Skip to content

Commit d3fe98c

Browse files
frankynpongad
authored andcommitted
storage: fix integration (#3297)
Do not pollute main test bucket with default kms key
1 parent 754b1fc commit d3fe98c

File tree

1 file changed

+22
-17
lines changed
  • google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it

1 file changed

+22
-17
lines changed

google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java

+22-17
Original file line numberDiff line numberDiff line change
@@ -1860,25 +1860,30 @@ public void testListBucketRequesterPaysFails() throws InterruptedException {
18601860
}
18611861

18621862
@Test
1863-
public void testListBucketDefaultKmsKeyName() throws InterruptedException {
1864-
Bucket remoteBucket = storage.get(BUCKET, Storage.BucketGetOption.fields(BucketField.ENCRYPTION));
1865-
assertNull(remoteBucket.getDefaultKmsKeyName());
1866-
remoteBucket = remoteBucket.toBuilder().setDefaultKmsKeyName(KMS_KEY_NAME_1).build().update();
1863+
public void testListBucketDefaultKmsKeyName() throws ExecutionException, InterruptedException {
1864+
String bucketName = RemoteStorageHelper.generateBucketName();
1865+
Bucket remoteBucket = storage.create(BucketInfo.newBuilder(bucketName)
1866+
.setDefaultKmsKeyName(KMS_KEY_NAME_1).setLocation("US").build());
1867+
assertNotNull(remoteBucket);
18671868
assertTrue(remoteBucket.getDefaultKmsKeyName().startsWith(KMS_KEY_NAME_1));
1868-
Iterator<Bucket> bucketIterator = storage.list(Storage.BucketListOption.prefix(BUCKET),
1869-
Storage.BucketListOption.fields(BucketField.ENCRYPTION)).iterateAll().iterator();
1870-
while (!bucketIterator.hasNext()) {
1871-
Thread.sleep(500);
1872-
bucketIterator = storage.list(Storage.BucketListOption.prefix(BUCKET),
1869+
try {
1870+
Iterator<Bucket> bucketIterator = storage.list(Storage.BucketListOption.prefix(bucketName),
18731871
Storage.BucketListOption.fields(BucketField.ENCRYPTION)).iterateAll().iterator();
1874-
}
1875-
while (bucketIterator.hasNext()) {
1876-
Bucket bucket = bucketIterator.next();
1877-
assertTrue(bucket.getName().startsWith(BUCKET));
1878-
assertNotNull(bucket.getDefaultKmsKeyName());
1879-
assertTrue(bucket.getDefaultKmsKeyName().startsWith(KMS_KEY_NAME_1));
1880-
assertNull(bucket.getCreateTime());
1881-
assertNull(bucket.getSelfLink());
1872+
while (!bucketIterator.hasNext()) {
1873+
Thread.sleep(500);
1874+
bucketIterator = storage.list(Storage.BucketListOption.prefix(bucketName),
1875+
Storage.BucketListOption.fields(BucketField.ENCRYPTION)).iterateAll().iterator();
1876+
}
1877+
while (bucketIterator.hasNext()) {
1878+
Bucket bucket = bucketIterator.next();
1879+
assertTrue(bucket.getName().startsWith(bucketName));
1880+
assertNotNull(bucket.getDefaultKmsKeyName());
1881+
assertTrue(bucket.getDefaultKmsKeyName().startsWith(KMS_KEY_NAME_1));
1882+
assertNull(bucket.getCreateTime());
1883+
assertNull(bucket.getSelfLink());
1884+
}
1885+
} finally {
1886+
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
18821887
}
18831888
}
18841889

0 commit comments

Comments
 (0)