1818
1919import static org .junit .jupiter .api .Assertions .assertEquals ;
2020import static org .junit .jupiter .api .Assertions .assertFalse ;
21+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
2122import static org .junit .jupiter .api .Assertions .assertThrows ;
2223import static org .junit .jupiter .api .Assertions .assertTrue ;
2324import static org .junit .jupiter .api .Assertions .fail ;
4445import org .apache .commons .lang3 .function .Consumers ;
4546import org .junit .jupiter .api .BeforeEach ;
4647import org .junit .jupiter .api .Test ;
47- import org .junit .jupiter .api .condition .EnabledOnOs ;
48- import org .junit .jupiter .api .condition .OS ;
4948import org .junit .jupiter .api .io .TempDir ;
5049
5150/**
@@ -204,12 +203,12 @@ public void testListFilesByExtension() {
204203
205204 files = FileUtils .listFiles (temporaryFolder , extensions , true );
206205 fileNames = filesToFilenames (files );
207- assertEquals (4 , fileNames .size ());
206+ assertEquals (4 , fileNames .size (), fileNames :: toString );
208207 assertTrue (fileNames .contains ("dummy-file.txt" ));
209208 assertFalse (fileNames .contains ("dummy-index.html" ));
210209
211210 files = FileUtils .listFiles (temporaryFolder , null , false );
212- assertEquals (2 , files .size ());
211+ assertEquals (2 , files .size (), files :: toString );
213212 fileNames = filesToFilenames (files );
214213 assertTrue (fileNames .contains ("dummy-build.xml" ));
215214 assertTrue (fileNames .contains ("README" ));
@@ -238,7 +237,6 @@ public void testListFilesWithDeletion() throws IOException {
238237 * Tests <a href="https://issues.apache.org/jira/browse/IO-856">IO-856</a> ListFiles should not fail on vanishing files.
239238 */
240239 @ Test
241- @ EnabledOnOs (value = OS .WINDOWS )
242240 public void testListFilesWithDeletionThreaded () throws ExecutionException , InterruptedException {
243241 // test for IO-856
244242 // create random directory in tmp, create the directory if it does not exist
@@ -248,33 +246,42 @@ public void testListFilesWithDeletionThreaded() throws ExecutionException, Inter
248246 fail ("Could not create file path: " + tempDir .getAbsolutePath ());
249247 }
250248 final int waitTime = 10_000 ;
249+ final int maxFiles = 500 ;
251250 final byte [] bytes = "TEST" .getBytes (StandardCharsets .UTF_8 );
252251 final CompletableFuture <Void > c1 = CompletableFuture .runAsync (() -> {
253252 final long endTime = System .currentTimeMillis () + waitTime ;
254- while (System .currentTimeMillis () < endTime ) {
253+ int count = 0 ;
254+ while (System .currentTimeMillis () < endTime && count < maxFiles ) {
255255 final File file = new File (tempDir .getAbsolutePath (), UUID .randomUUID () + ".deletetester" );
256256 file .deleteOnExit ();
257257 try {
258258 Files .write (file .toPath (), bytes );
259+ count ++;
259260 } catch (final Exception e ) {
260261 fail ("Could not create test file: '" + file .getAbsolutePath () + "': " + e , e );
261262 }
262263 if (!file .delete ()) {
263264 fail ("Could not delete test file: '" + file .getAbsolutePath () + "'" );
264265 }
265266 }
267+ // System.out.printf("Created %,d%n", count);
266268 });
267269 final CompletableFuture <Void > c2 = CompletableFuture .runAsync (() -> {
268270 final long endTime = System .currentTimeMillis () + waitTime ;
271+ int max = 0 ;
269272 try {
270273 while (System .currentTimeMillis () < endTime ) {
271- FileUtils .listFiles (tempDir , new String [] { "\\ .deletetester" }, false );
274+ final Collection <File > files = FileUtils .listFiles (tempDir , new String [] { "\\ .deletetester" }, false );
275+ assertNotNull (files );
276+ max = Math .max (max , files .size ());
272277 }
273278 } catch (final Exception e ) {
279+ System .out .printf ("List size max %,d%n" , max );
274280 fail ("IO-856 test failure: " + e , e );
275281 // The exception can be hidden.
276282 e .printStackTrace ();
277283 }
284+ // System.out.printf("List size max %,d%n", max);
278285 });
279286 // wait for the threads to finish
280287 c1 .get ();
0 commit comments