1111import java .io .IOException ;
1212import java .net .URL ;
1313import java .util .concurrent .ExecutorService ;
14+ import java .util .concurrent .Future ;
1415import java .util .concurrent .atomic .AtomicBoolean ;
1516import 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