Skip to content

Commit 5b9e041

Browse files
committed
synchronized filenames list
1 parent f8e9551 commit 5b9e041

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAbfsListStatusRemoteIterator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
import java.io.FileNotFoundException;
2222
import java.io.IOException;
2323
import java.util.ArrayList;
24+
import java.util.Collections;
2425
import java.util.List;
2526
import java.util.NoSuchElementException;
2627
import java.util.concurrent.ExecutionException;
2728
import java.util.concurrent.ExecutorService;
2829
import java.util.concurrent.Executors;
2930
import java.util.concurrent.Future;
3031

31-
import org.apache.hadoop.test.LambdaTestUtils;
3232
import org.assertj.core.api.Assertions;
3333
import org.junit.Assert;
3434
import org.junit.Test;
@@ -42,6 +42,7 @@
4242
import org.apache.hadoop.fs.azurebfs.services.AbfsListStatusRemoteIterator;
4343
import org.apache.hadoop.fs.azurebfs.services.ListingSupport;
4444
import org.apache.hadoop.fs.azurebfs.utils.TracingContext;
45+
import org.apache.hadoop.test.LambdaTestUtils;
4546

4647
import static org.mockito.ArgumentMatchers.any;
4748
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -285,14 +286,16 @@ private void setPageSize(int pageSize) throws IOException {
285286
private List<String> createFilesUnderDirectory(Path rootPath)
286287
throws ExecutionException, InterruptedException, IOException {
287288
final List<Future<Void>> tasks = new ArrayList<>();
288-
final List<String> fileNames = new ArrayList<>();
289+
final List<String> fileNames = Collections.synchronizedList(new ArrayList<>());
289290
ExecutorService es = Executors.newFixedThreadPool(10);
290291
try {
291292
for (int i = 0; i < ITestAbfsListStatusRemoteIterator.TEST_FILES_NUMBER; i++) {
292293
Path filePath = makeQualified(new Path(rootPath, "testListPath" + i));
293294
tasks.add(es.submit(() -> {
294295
touch(filePath);
295-
Assert.assertTrue(fileNames.add(filePath.toString()));
296+
synchronized (fileNames) {
297+
Assert.assertTrue(fileNames.add(filePath.toString()));
298+
}
296299
return null;
297300
}));
298301
}
@@ -303,7 +306,6 @@ private List<String> createFilesUnderDirectory(Path rootPath)
303306
es.shutdownNow();
304307
}
305308
LOG.debug(fileNames.toString());
306-
Assertions.assertThat(fileNames).doesNotContainNull();
307309
Assertions.assertThat(fileNames)
308310
.describedAs("File creation incorrect or fileNames not added to list")
309311
.hasSize(ITestAbfsListStatusRemoteIterator.TEST_FILES_NUMBER);

0 commit comments

Comments
 (0)