2828import java .util .ArrayList ;
2929import java .util .List ;
3030import java .util .Optional ;
31+ import java .util .concurrent .CompletableFuture ;
3132import java .util .concurrent .CountDownLatch ;
3233import java .util .concurrent .ExecutorService ;
3334import java .util .concurrent .Executors ;
@@ -313,14 +314,14 @@ public void testAsyncFetchesToDifferentBlobsDoNotBlockOnEachOther() throws Excep
313314 executor .shutdownNow ();
314315 }
315316
316- public void testRefCount () throws IOException , InterruptedException {
317+ public void testRefCount () throws Exception {
317318 List <BlobFetchRequest .BlobPart > blobParts = new ArrayList <>();
318319 String blobname = "test-blob" ;
319320 blobParts .add (new BlobFetchRequest .BlobPart ("blob" , 0 , EIGHT_MB ));
320321 BlobFetchRequest blobFetchRequest = BlobFetchRequest .builder ().fileName (blobname ).directory (directory ).blobParts (blobParts ).build ();
321322 // It will trigger async load
322- transferManager .fetchBlobAsync (blobFetchRequest );
323- Thread . sleep ( 2000 );
323+ CompletableFuture < IndexInput > future = transferManager .fetchBlobAsync (blobFetchRequest );
324+ future . get ( );
324325 assertEquals (Optional .of (0 ), Optional .of (fileCache .getRef (blobFetchRequest .getFilePath ())));
325326 assertNotNull (fileCache .get (blobFetchRequest .getFilePath ()));
326327 fileCache .decRef (blobFetchRequest .getFilePath ());
@@ -347,8 +348,6 @@ private IndexInput asyncFetchBlobWithName(String blobname) throws IOException {
347348 BlobFetchRequest blobFetchRequest = BlobFetchRequest .builder ().fileName (blobname ).directory (directory ).blobParts (blobParts ).build ();
348349 // It will trigger async load
349350 transferManager .fetchBlobAsync (blobFetchRequest );
350- assertNotNull (fileCache .get (blobFetchRequest .getFilePath ()));
351- fileCache .decRef (blobFetchRequest .getFilePath ());
352351 // Making the read call to fetch from file cache
353352 return transferManager .fetchBlob (blobFetchRequest );
354353 }
0 commit comments