Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle eventally consistent blob lists in storage ITs #704

Merged
merged 2 commits into from
Mar 3, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.gcloud.Page;
import com.google.gcloud.ReadChannel;
Expand Down Expand Up @@ -287,8 +288,8 @@ public void testGetBlobFailNonExistingGeneration() {
assertTrue(remoteBlob.delete());
}

@Test
public void testListBlobsSelectedFields() {
@Test(timeout = 5000)
public void testListBlobsSelectedFields() throws InterruptedException {
String[] blobNames = {"test-list-blobs-selected-fields-blob1",
"test-list-blobs-selected-fields-blob2"};
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
Expand All @@ -307,19 +308,27 @@ public void testListBlobsSelectedFields() {
Page<Blob> page = storage.list(BUCKET,
Storage.BlobListOption.prefix("test-list-blobs-selected-fields-blob"),
Storage.BlobListOption.fields(BlobField.METADATA));
int index = 0;
// Listing blobs is eventually consistent, we loop until the list is of the expected size. The
// test fails if timeout is reached.
while (Iterators.size(page.values().iterator()) != 2) {

This comment was marked as spam.

This comment was marked as spam.

Thread.sleep(500);
page = storage.list(BUCKET,
Storage.BlobListOption.prefix("test-list-blobs-selected-fields-blob"),
Storage.BlobListOption.fields(BlobField.METADATA));
}
Set<String> blobSet = ImmutableSet.of(blobNames[0], blobNames[1]);
for (Blob remoteBlob : page.values()) {
assertEquals(BUCKET, remoteBlob.bucket());
assertEquals(blobNames[index++], remoteBlob.name());
assertTrue(blobSet.contains(remoteBlob.name()));
assertEquals(metadata, remoteBlob.metadata());
assertNull(remoteBlob.contentType());
}
assertTrue(remoteBlob1.delete());
assertTrue(remoteBlob2.delete());
}

@Test
public void testListBlobsEmptySelectedFields() {
@Test(timeout = 5000)
public void testListBlobsEmptySelectedFields() throws InterruptedException {
String[] blobNames = {"test-list-blobs-empty-selected-fields-blob1",
"test-list-blobs-empty-selected-fields-blob2"};
BlobInfo blob1 = BlobInfo.builder(BUCKET, blobNames[0])
Expand All @@ -335,17 +344,25 @@ public void testListBlobsEmptySelectedFields() {
Page<Blob> page = storage.list(BUCKET,
Storage.BlobListOption.prefix("test-list-blobs-empty-selected-fields-blob"),
Storage.BlobListOption.fields());
int index = 0;
// Listing blobs is eventually consistent, we loop until the list is of the expected size. The
// test fails if timeout is reached.
while (Iterators.size(page.values().iterator()) != 2) {
Thread.sleep(500);
page = storage.list(BUCKET,
Storage.BlobListOption.prefix("test-list-blobs-empty-selected-fields-blob"),
Storage.BlobListOption.fields());
}
Set<String> blobSet = ImmutableSet.of(blobNames[0], blobNames[1]);
for (Blob remoteBlob : page.values()) {
assertEquals(BUCKET, remoteBlob.bucket());
assertEquals(blobNames[index++], remoteBlob.name());
assertTrue(blobSet.contains(remoteBlob.name()));
assertNull(remoteBlob.contentType());
}
assertTrue(remoteBlob1.delete());
assertTrue(remoteBlob2.delete());
}

@Test
@Test(timeout = 10000)
public void testListBlobsVersioned() throws ExecutionException, InterruptedException {
String bucketName = RemoteGcsHelper.generateBucketName();
Bucket bucket = storage.create(BucketInfo.builder(bucketName).versioningEnabled(true).build());
Expand All @@ -366,6 +383,14 @@ public void testListBlobsVersioned() throws ExecutionException, InterruptedExcep
Page<Blob> page = storage.list(bucketName,
Storage.BlobListOption.prefix("test-list-blobs-versioned-blob"),
Storage.BlobListOption.versions(true));
// Listing blobs is eventually consistent, we loop until the list is of the expected size. The
// test fails if timeout is reached.
while (Iterators.size(page.values().iterator()) != 3) {
Thread.sleep(500);
page = storage.list(bucketName,
Storage.BlobListOption.prefix("test-list-blobs-versioned-blob"),
Storage.BlobListOption.versions(true));
}
Set<String> blobSet = ImmutableSet.of(blobNames[0], blobNames[1]);
for (Blob remoteBlob : page.values()) {
assertEquals(bucketName, remoteBlob.bucket());
Expand Down