2222import java .util .ArrayList ;
2323import java .util .List ;
2424import java .util .Random ;
25+ import java .util .concurrent .CompletionService ;
2526import java .util .concurrent .ExecutionException ;
27+ import java .util .concurrent .ExecutorCompletionService ;
2628import java .util .concurrent .ExecutorService ;
2729import java .util .concurrent .Executors ;
2830import java .util .concurrent .Future ;
@@ -47,8 +49,8 @@ public class TestGetContentSummary extends AbstractAbfsIntegrationTest {
4749 private static final int TEST_BUFFER_SIZE = 20 ;
4850 private static final int FILES_PER_DIRECTORY = 2 ;
4951 private static final int MAX_THREADS = 16 ;
50- private static final int NUM_FILES_FOR_LIST_MAX_TEST = 10 ;
51- // DEFAULT_AZURE_LIST_MAX_RESULTS + 10;
52+ private static final int NUM_FILES_FOR_LIST_MAX_TEST =
53+ DEFAULT_AZURE_LIST_MAX_RESULTS + 10 ;
5254private static final int NUM_CONCURRENT_CALLS = 8 ;
5355
5456 private final String [] directories = {"/testFolder" ,
@@ -156,17 +158,18 @@ public void testInvalidPath() throws Exception {
156158 @ Test
157159 public void testConcurrentGetContentSummaryCalls ()
158160 throws InterruptedException , ExecutionException , IOException {
161+ AzureBlobFileSystem fs = getFileSystem ();
159162 ExecutorService executorService = new ThreadPoolExecutor (1 , MAX_THREADS , 5 ,
160163 TimeUnit .SECONDS , new SynchronousQueue <>());
161- ArrayList <Future <ContentSummary >> futures = new ArrayList <>();
164+ CompletionService <ContentSummary > completionService =
165+ new ExecutorCompletionService <>(executorService );
162166 createDirectoryStructure ();
163167 for (int i = 0 ; i < NUM_CONCURRENT_CALLS ; i ++) {
164- Future <ContentSummary > future = executorService .submit (
165- () -> getFileSystem ().getContentSummary (new Path ("/testFolder" )));
166- futures .add (future );
168+ completionService .submit (() -> fs .getContentSummary (new Path (
169+ "/testFolder" )));
167170 }
168171 for (int i = 0 ; i < NUM_CONCURRENT_CALLS ; i ++) {
169- ContentSummary contentSummary = futures . get ( i ).get ();
172+ ContentSummary contentSummary = completionService . take ( ).get ();
170173 verifyContentSummary (contentSummary , 7 , 8 * FILES_PER_DIRECTORY ,
171174 8 * TEST_BUFFER_SIZE );
172175 }
0 commit comments