garydgregory commented on code in PR #697:
URL: https://github.com/apache/commons-io/pull/697#discussion_r1829373182
##########
src/test/java/org/apache/commons/io/FileUtilsListFilesTest.java:
##########
@@ -222,4 +219,48 @@ public void testListFilesWithDeletion() throws IOException
{
assertEquals(4, list.size());
}
+ @Test
+ public void testListFilesWithDeletionThreaded() throws
java.util.concurrent.ExecutionException, InterruptedException {
+ // test for IO-856
+ // create random directory in tmp, create the directory if it does not
exist
+ final File dir = FileUtils.getTempDirectory();
+ if (!dir.exists()) {
+ if (!dir.mkdirs()) {
+ throw new RuntimeException("could not create image file path:
" + dir.getAbsolutePath());
+ }
+ }
+ final int waitTime = 10000;
+ final java.util.concurrent.CompletableFuture<Void> c1 =
java.util.concurrent.CompletableFuture.runAsync(() -> {
+ long endTime = System.currentTimeMillis() + waitTime;
+ while (System.currentTimeMillis() < endTime) {
+ final File file = new File(dir.getAbsolutePath(),
java.util.UUID.randomUUID() + ".deletetester");
+ file.deleteOnExit();
+ try {
+ new
java.io.BufferedOutputStream(java.nio.file.Files.newOutputStream(file.toPath())).write("TEST".getBytes(java.nio.charset.StandardCharsets.UTF_8));
+ } catch (Exception e) {
+ throw new RuntimeException("could not create test file: "
+ file.getAbsolutePath(), e);
Review Comment:
Don't throw `RuntimeException`, use JUnit's `fail()` method.
##########
src/test/java/org/apache/commons/io/FileUtilsListFilesTest.java:
##########
@@ -222,4 +219,48 @@ public void testListFilesWithDeletion() throws IOException
{
assertEquals(4, list.size());
}
+ @Test
+ public void testListFilesWithDeletionThreaded() throws
java.util.concurrent.ExecutionException, InterruptedException {
+ // test for IO-856
+ // create random directory in tmp, create the directory if it does not
exist
+ final File dir = FileUtils.getTempDirectory();
+ if (!dir.exists()) {
+ if (!dir.mkdirs()) {
+ throw new RuntimeException("could not create image file path:
" + dir.getAbsolutePath());
+ }
+ }
+ final int waitTime = 10000;
+ final java.util.concurrent.CompletableFuture<Void> c1 =
java.util.concurrent.CompletableFuture.runAsync(() -> {
+ long endTime = System.currentTimeMillis() + waitTime;
+ while (System.currentTimeMillis() < endTime) {
+ final File file = new File(dir.getAbsolutePath(),
java.util.UUID.randomUUID() + ".deletetester");
+ file.deleteOnExit();
+ try {
+ new
java.io.BufferedOutputStream(java.nio.file.Files.newOutputStream(file.toPath())).write("TEST".getBytes(java.nio.charset.StandardCharsets.UTF_8));
+ } catch (Exception e) {
+ throw new RuntimeException("could not create test file: "
+ file.getAbsolutePath(), e);
+ }
+ if (!file.delete()) {
+ throw new RuntimeException("could not delete test file: "
+ file.getAbsolutePath());
+ }
+ }
+ });
+
+ final java.util.concurrent.CompletableFuture<Void> c2 =
java.util.concurrent.CompletableFuture.runAsync(() -> {
Review Comment:
Use an import for `java.util.concurrent.CompletableFuture`, don't use FQCNs.
##########
src/test/java/org/apache/commons/io/FileUtilsListFilesTest.java:
##########
@@ -222,4 +219,48 @@ public void testListFilesWithDeletion() throws IOException
{
assertEquals(4, list.size());
}
+ @Test
+ public void testListFilesWithDeletionThreaded() throws
java.util.concurrent.ExecutionException, InterruptedException {
+ // test for IO-856
+ // create random directory in tmp, create the directory if it does not
exist
+ final File dir = FileUtils.getTempDirectory();
+ if (!dir.exists()) {
+ if (!dir.mkdirs()) {
+ throw new RuntimeException("could not create image file path:
" + dir.getAbsolutePath());
+ }
+ }
+ final int waitTime = 10000;
+ final java.util.concurrent.CompletableFuture<Void> c1 =
java.util.concurrent.CompletableFuture.runAsync(() -> {
+ long endTime = System.currentTimeMillis() + waitTime;
+ while (System.currentTimeMillis() < endTime) {
+ final File file = new File(dir.getAbsolutePath(),
java.util.UUID.randomUUID() + ".deletetester");
+ file.deleteOnExit();
+ try {
+ new
java.io.BufferedOutputStream(java.nio.file.Files.newOutputStream(file.toPath())).write("TEST".getBytes(java.nio.charset.StandardCharsets.UTF_8));
Review Comment:
Use imports.
##########
src/test/java/org/apache/commons/io/FileUtilsListFilesTest.java:
##########
@@ -222,4 +219,48 @@ public void testListFilesWithDeletion() throws IOException
{
assertEquals(4, list.size());
}
+ @Test
+ public void testListFilesWithDeletionThreaded() throws
java.util.concurrent.ExecutionException, InterruptedException {
+ // test for IO-856
+ // create random directory in tmp, create the directory if it does not
exist
+ final File dir = FileUtils.getTempDirectory();
+ if (!dir.exists()) {
+ if (!dir.mkdirs()) {
+ throw new RuntimeException("could not create image file path:
" + dir.getAbsolutePath());
+ }
+ }
+ final int waitTime = 10000;
+ final java.util.concurrent.CompletableFuture<Void> c1 =
java.util.concurrent.CompletableFuture.runAsync(() -> {
+ long endTime = System.currentTimeMillis() + waitTime;
+ while (System.currentTimeMillis() < endTime) {
+ final File file = new File(dir.getAbsolutePath(),
java.util.UUID.randomUUID() + ".deletetester");
+ file.deleteOnExit();
+ try {
+ new
java.io.BufferedOutputStream(java.nio.file.Files.newOutputStream(file.toPath())).write("TEST".getBytes(java.nio.charset.StandardCharsets.UTF_8));
+ } catch (Exception e) {
+ throw new RuntimeException("could not create test file: "
+ file.getAbsolutePath(), e);
+ }
+ if (!file.delete()) {
+ throw new RuntimeException("could not delete test file: "
+ file.getAbsolutePath());
+ }
+ }
+ });
+
+ final java.util.concurrent.CompletableFuture<Void> c2 =
java.util.concurrent.CompletableFuture.runAsync(() -> {
+ long endTime = System.currentTimeMillis() + waitTime;
+ try {
+ while (System.currentTimeMillis() < endTime) {
+ final Collection<File> files = FileUtils.listFiles(dir,
new String[]{"\\.deletetester"}, false);
+ files.size();
Review Comment:
What does calling `size()` do here? Should there be an assert for the
result? is the call needed at all?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]