Skip to content

Commit bab9949

Browse files
committed
Update FileUtilsTest.java
1 parent 50e5ff2 commit bab9949

1 file changed

Lines changed: 30 additions & 24 deletions

File tree

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

Lines changed: 30 additions & 24 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

@@ -240,39 +241,44 @@ public void testForceDeleteOnIOException() throws Exception {
240241
// status : 2 -> deleting
241242
AtomicInteger status = new AtomicInteger(0);
242243

243-
executor.submit(() -> {
244+
long timeoutInMs = 1000;
245+
246+
Future future = executor.submit(() -> {
244247
synchronized (testFile) {
245248
FileOutputStream outputStream = new FileOutputStream(testFile);
246249
outputStream.write('a');
247250
status.set(1);
248-
// wait for notification
249-
testFile.wait();
250-
outputStream.close();
251-
}
252-
return null;
253-
});
254251

255-
executor.submit(() -> {
256-
while (status.get() != 1) {
257-
}
258-
try {
259-
forceDelete(testFile);
260-
} finally {
261-
status.set(2);
262-
}
263-
return null;
264-
});
252+
executor.submit(() -> {
253+
while (status.get() != 1) {
254+
}
255+
try {
256+
assertThrows(IOException.class, () -> forceDelete(testFile));
257+
} finally {
258+
status.set(2);
259+
}
260+
return null;
261+
});
265262

266-
executor.submit(() -> {
267-
while (status.get() != 2) {
268-
}
269-
synchronized (testFile) {
270-
testFile.notifyAll();
263+
// wait for notification
264+
testFile.wait(timeoutInMs / 2);
265+
outputStream.close();
271266
}
272267
return null;
273268
});
274-
275-
executor.awaitTermination(100, MILLISECONDS);
269+
270+
future.get(timeoutInMs, MILLISECONDS);
271+
272+
// executor.submit(() -> {
273+
// while (status.get() != 2) {
274+
// }
275+
// synchronized (testFile) {
276+
// testFile.notifyAll();
277+
// }
278+
// return null;
279+
// });
280+
281+
executor.awaitTermination(timeoutInMs, MILLISECONDS);
276282

277283
executor.shutdown();
278284

0 commit comments

Comments
 (0)