Skip to content

Commit f8716d2

Browse files
committed
Update FileUtilsTest.java
1 parent 6a24a88 commit f8716d2

1 file changed

Lines changed: 15 additions & 33 deletions

File tree

microsphere-java-core/src/test/java/io/microsphere/io/FileUtilsTest.java

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.IOException;
1212
import java.net.URL;
1313
import java.util.concurrent.ExecutorService;
14+
import java.util.concurrent.Future;
1415
import java.util.concurrent.atomic.AtomicBoolean;
1516
import java.util.concurrent.atomic.AtomicInteger;
1617

@@ -232,8 +233,6 @@ public void testForceDeleteOnFileNotExists() {
232233
public void testForceDeleteOnIOException() throws Exception {
233234
File testFile = createRandomTempFile();
234235

235-
ExecutorService executor = newFixedThreadPool(3);
236-
237236
// status : 0 -> init
238237
// status : 1 -> writing
239238
// status : 2 -> deleting
@@ -242,43 +241,26 @@ public void testForceDeleteOnIOException() throws Exception {
242241
long timeoutInMs = 1000;
243242

244243
Thread thread = new Thread(() -> {
245-
executor.submit(() -> {
246-
synchronized (testFile) {
247-
try (FileOutputStream outputStream = new FileOutputStream(testFile)) {
248-
outputStream.write('a');
249-
status.set(1);
250-
// wait for notification
251-
testFile.wait();
252-
}
253-
}
254-
return null;
255-
});
256-
257-
executor.submit(() -> {
258-
while (status.get() != 1) {
259-
}
260-
try {
261-
assertThrows(IOException.class, () -> forceDelete(testFile));
262-
} finally {
263-
status.set(2);
244+
synchronized (testFile) {
245+
try (FileOutputStream outputStream = new FileOutputStream(testFile)) {
246+
outputStream.write('a');
247+
// wait for notification
248+
testFile.wait(timeoutInMs);
249+
} catch (Throwable e) {
264250
}
265-
return null;
266-
});
267-
268-
executor.submit(() -> {
269-
while (status.get() != 2) {
270-
}
271-
synchronized (testFile) {
272-
testFile.notifyAll();
273-
}
274-
return null;
275-
});
251+
}
276252
});
277253

278254
thread.start();
255+
256+
assertThrows(IOException.class, () -> forceDelete(testFile));
257+
258+
synchronized (testFile) {
259+
testFile.notifyAll();
260+
}
261+
279262
thread.join(timeoutInMs);
280263

281-
executor.shutdown();
282264
}
283265

284266
@Test

0 commit comments

Comments
 (0)