@@ -408,47 +408,47 @@ public void testListBlobsEmptySelectedFields() throws InterruptedException {
408408 }
409409 }
410410
411- @ Test (timeout = 5000 )
411+ @ Test (timeout = 7500 )
412412 public void testListBlobRequesterPays () throws InterruptedException {
413- String [] blobNames = {"test-list-blobs-empty-selected-fields-blob1" ,
414- "test-list-blobs-empty-selected-fields-blob2" };
415- BlobInfo blob1 = BlobInfo .newBuilder (BUCKET , blobNames [0 ])
416- .setContentType (CONTENT_TYPE )
417- .build ();
418- BlobInfo blob2 = BlobInfo .newBuilder (BUCKET , blobNames [1 ])
419- .setContentType (CONTENT_TYPE )
420- .build ();
421- Blob remoteBlob1 = storage .create (blob1 );
422- Blob remoteBlob2 = storage .create (blob2 );
423- assertNotNull (remoteBlob1 );
424- assertNotNull (remoteBlob2 );
425-
426- Page <Blob > page = storage .list (BUCKET ,
427- Storage .BlobListOption .prefix ("test-list-blobs-empty-selected-fields-blob" ),
428- Storage .BlobListOption .fields ());
413+ BlobInfo blob1 =
414+ BlobInfo .newBuilder (BUCKET , "test-list-blobs-empty-selected-fields-blob1" )
415+ .setContentType (CONTENT_TYPE )
416+ .build ();
417+ assertNotNull (storage .create (blob1 ));
429418
430419 // Test listing a Requester Pays bucket.
431420 Bucket remoteBucket = storage .get (BUCKET , Storage .BucketGetOption .fields (BucketField .ID ));
432421 assertNull (remoteBucket .requesterPays ());
433422 remoteBucket = remoteBucket .toBuilder ().setRequesterPays (true ).build ();
434423 Bucket updatedBucket = storage .update (remoteBucket );
435424 assertTrue (updatedBucket .requesterPays ());
436- String projectId = remoteStorageHelper .getOptions ().getProjectId ();
437425 try {
438- page = storage .list (BUCKET ,
426+ storage .list (
427+ BUCKET ,
439428 Storage .BlobListOption .prefix ("test-list-blobs-empty-selected-fields-blob" ),
440429 Storage .BlobListOption .fields (),
441430 Storage .BlobListOption .userProject ("fakeBillingProjectId" ));
442431 fail ("Expected bad user project error." );
443432 } catch (StorageException e ) {
444433 assertTrue (e .getMessage ().contains ("User project specified in the request is invalid" ));
445434 }
446- while (Iterators .size (page .iterateAll ().iterator ()) != 2 ) {
435+
436+ String projectId = remoteStorageHelper .getOptions ().getProjectId ();
437+ while (true ) {
438+ Page <Blob > page =
439+ storage .list (
440+ BUCKET ,
441+ Storage .BlobListOption .prefix ("test-list-blobs-empty-selected-fields-blob" ),
442+ Storage .BlobListOption .fields (),
443+ Storage .BlobListOption .userProject (projectId ));
444+ List <Blob > blobs = Lists .newArrayList (page .iterateAll ());
445+ // If the list is empty, maybe the blob isn't visible yet; wait and try again.
446+ // Otherwise, expect one blob, since we only put in one above.
447+ if (!blobs .isEmpty ()) {
448+ assertThat (blobs ).hasSize (1 );
449+ break ;
450+ }
447451 Thread .sleep (500 );
448- page = storage .list (BUCKET ,
449- Storage .BlobListOption .prefix ("test-list-blobs-empty-selected-fields-blob" ),
450- Storage .BlobListOption .fields (),
451- Storage .BlobListOption .userProject (projectId ));
452452 }
453453 }
454454
0 commit comments