Skip to content

Commit cc4b6e2

Browse files
authored
test: add rapid bucket fixture (googleapis#3032)
Update ITAppendableUploadTest and ITObjectReadSessionTest to use the rapid bucket instead of testbench. Beacuse rapid buckets are not yet available in all zones, if we attempt to make the rapid bucket and it fails the test will be skipped instead of failing.
1 parent ac9d76c commit cc4b6e2

File tree

5 files changed

+83
-34
lines changed

5 files changed

+83
-34
lines changed

google-cloud-storage/src/test/java/com/google/cloud/storage/ITAppendableUploadTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import com.google.cloud.storage.Storage.BlobGetOption;
2323
import com.google.cloud.storage.it.runner.StorageITRunner;
2424
import com.google.cloud.storage.it.runner.annotations.Backend;
25+
import com.google.cloud.storage.it.runner.annotations.BucketFixture;
26+
import com.google.cloud.storage.it.runner.annotations.BucketType;
2527
import com.google.cloud.storage.it.runner.annotations.Inject;
2628
import com.google.cloud.storage.it.runner.annotations.SingleBackend;
2729
import com.google.cloud.storage.it.runner.annotations.StorageFixture;
@@ -37,12 +39,11 @@
3739
import java.util.concurrent.ExecutionException;
3840
import java.util.concurrent.TimeUnit;
3941
import java.util.concurrent.TimeoutException;
40-
import org.junit.Ignore;
4142
import org.junit.Test;
4243
import org.junit.runner.RunWith;
4344

4445
@RunWith(StorageITRunner.class)
45-
@SingleBackend(Backend.TEST_BENCH)
46+
@SingleBackend(Backend.PROD)
4647
public final class ITAppendableUploadTest {
4748

4849
@Inject public Generator generator;
@@ -51,7 +52,9 @@ public final class ITAppendableUploadTest {
5152
@StorageFixture(TransportCompatibility.Transport.GRPC)
5253
public Storage storage;
5354

54-
@Inject public BucketInfo bucket;
55+
@Inject
56+
@BucketFixture(BucketType.RAPID)
57+
public BucketInfo bucket;
5558

5659
@Test
5760
public void testAppendableBlobUpload()
@@ -92,7 +95,6 @@ public void appendableBlobUploadWithoutFinalizing() throws IOException {
9295
}
9396

9497
@Test
95-
@Ignore("Pending work in testbench, manually verified internally on 2025-03-03")
9698
public void appendableBlobUploadTakeover() throws Exception {
9799
BlobAppendableUploadConfig uploadConfig =
98100
BlobAppendableUploadConfig.of().withFlushPolicy(FlushPolicy.maxFlushSize(5));
@@ -137,7 +139,6 @@ public void testUploadFileUsingAppendable() throws Exception {
137139
}
138140

139141
@Test
140-
@Ignore("Pending work in testbench, manually verified internally on 2025-03-25")
141142
public void finalizeAfterCloseWorks() throws Exception {
142143
BlobAppendableUploadConfig uploadConfig =
143144
BlobAppendableUploadConfig.of().withFlushPolicy(FlushPolicy.maxFlushSize(1024));
@@ -153,7 +154,6 @@ public void finalizeAfterCloseWorks() throws Exception {
153154
}
154155

155156
@Test
156-
@Ignore("Pending work in testbench, manually verified internally on 2025-03-25")
157157
public void takeoverJustToFinalizeWorks() throws Exception {
158158
BlobAppendableUploadConfig uploadConfig =
159159
BlobAppendableUploadConfig.of().withFlushPolicy(FlushPolicy.maxFlushSize(5));

google-cloud-storage/src/test/java/com/google/cloud/storage/ITObjectReadSessionTest.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@
2727
import com.google.api.core.ApiFutures;
2828
import com.google.api.gax.rpc.OutOfRangeException;
2929
import com.google.cloud.storage.Crc32cValue.Crc32cLengthKnown;
30-
import com.google.cloud.storage.Storage.BlobTargetOption;
3130
import com.google.cloud.storage.Storage.BlobWriteOption;
3231
import com.google.cloud.storage.TransportCompatibility.Transport;
3332
import com.google.cloud.storage.ZeroCopySupport.DisposableByteString;
3433
import com.google.cloud.storage.it.ChecksummedTestContent;
3534
import com.google.cloud.storage.it.runner.StorageITRunner;
3635
import com.google.cloud.storage.it.runner.annotations.Backend;
36+
import com.google.cloud.storage.it.runner.annotations.BucketFixture;
37+
import com.google.cloud.storage.it.runner.annotations.BucketType;
3738
import com.google.cloud.storage.it.runner.annotations.Inject;
3839
import com.google.cloud.storage.it.runner.annotations.SingleBackend;
3940
import com.google.cloud.storage.it.runner.annotations.StorageFixture;
4041
import com.google.cloud.storage.it.runner.registry.Generator;
41-
import com.google.cloud.storage.it.runner.registry.ObjectsFixture;
42-
import com.google.cloud.storage.it.runner.registry.ObjectsFixture.ObjectAndContent;
4342
import com.google.common.base.Stopwatch;
4443
import com.google.common.hash.Hasher;
4544
import com.google.common.hash.Hashing;
@@ -63,7 +62,7 @@
6362
import org.junit.runner.RunWith;
6463

6564
@RunWith(StorageITRunner.class)
66-
@SingleBackend(Backend.TEST_BENCH)
65+
@SingleBackend(Backend.PROD)
6766
public final class ITObjectReadSessionTest {
6867

6968
private static final int _512KiB = 512 * 1024;
@@ -72,18 +71,20 @@ public final class ITObjectReadSessionTest {
7271
@StorageFixture(Transport.GRPC)
7372
public Storage storage;
7473

75-
@Inject public BucketInfo bucket;
74+
@Inject
75+
@BucketFixture(BucketType.RAPID)
76+
public BucketInfo bucket;
7677

7778
@Inject public Generator generator;
7879

79-
@Inject public ObjectsFixture objectsFixture;
80-
8180
@Test
8281
public void bytes()
8382
throws ExecutionException, InterruptedException, TimeoutException, IOException {
84-
ObjectAndContent obj512KiB = objectsFixture.getObj512KiB();
85-
byte[] expected = obj512KiB.getContent().getBytes(_512KiB - 13);
86-
BlobId blobId = obj512KiB.getInfo().getBlobId();
83+
ChecksummedTestContent testContent =
84+
ChecksummedTestContent.of(DataGenerator.base64Characters().genBytes(512 * 1024));
85+
BlobInfo obj512KiB = create(testContent);
86+
byte[] expected = testContent.getBytes(_512KiB - 13);
87+
BlobId blobId = obj512KiB.getBlobId();
8788

8889
try (BlobReadSession blobReadSession =
8990
storage.blobReadSession(blobId).get(30, TimeUnit.SECONDS)) {
@@ -105,8 +106,10 @@ public void bytes()
105106

106107
@Test
107108
public void attemptingToGetFutureOutSizeSessionFails() throws Throwable {
108-
ObjectAndContent obj512KiB = objectsFixture.getObj512KiB();
109-
BlobId blobId = obj512KiB.getInfo().getBlobId();
109+
ChecksummedTestContent testContent =
110+
ChecksummedTestContent.of(DataGenerator.base64Characters().genBytes(512 * 1024));
111+
BlobInfo obj512KiB = create(testContent);
112+
BlobId blobId = obj512KiB.getBlobId();
110113

111114
ApiFuture<byte[]> future;
112115
try (BlobReadSession session = storage.blobReadSession(blobId).get(30, TimeUnit.SECONDS)) {
@@ -322,15 +325,11 @@ public void seekable() throws Exception {
322325
@Test
323326
public void outOfRange()
324327
throws ExecutionException, InterruptedException, TimeoutException, IOException {
325-
BlobId blobId;
326-
BlobWriteSession session =
327-
storage.blobWriteSession(
328-
BlobInfo.newBuilder(bucket, generator.randomObjectName()).build(),
329-
BlobWriteOption.doesNotExist());
330-
try (WritableByteChannel upload = session.open()) {
331-
upload.write(DataGenerator.base64Characters().genByteBuffer(4));
332-
}
333-
blobId = session.getResult().get(5, TimeUnit.SECONDS).getBlobId();
328+
ChecksummedTestContent testContent =
329+
ChecksummedTestContent.of(DataGenerator.base64Characters().genBytes(4));
330+
BlobInfo obj512KiB = create(testContent);
331+
BlobId blobId = obj512KiB.getBlobId();
332+
334333
try (BlobReadSession blobReadSession =
335334
storage.blobReadSession(blobId).get(30, TimeUnit.SECONDS)) {
336335

@@ -350,10 +349,14 @@ public void outOfRange()
350349
}
351350
}
352351

353-
private BlobInfo create(ChecksummedTestContent content) {
354-
return storage.create(
355-
BlobInfo.newBuilder(bucket, generator.randomObjectName()).build(),
356-
content.getBytes(),
357-
BlobTargetOption.doesNotExist());
352+
private BlobInfo create(ChecksummedTestContent content)
353+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
354+
BlobInfo info = BlobInfo.newBuilder(bucket, generator.randomObjectName()).build();
355+
try (BlobAppendableUpload upload =
356+
storage.blobAppendableUpload(
357+
info, BlobAppendableUploadConfig.of(), BlobWriteOption.doesNotExist())) {
358+
upload.write(ByteBuffer.wrap(content.getBytes()));
359+
return upload.finalizeUpload().get(30, TimeUnit.SECONDS);
360+
}
358361
}
359362
}

google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/annotations/BucketType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ public enum BucketType {
2525
/** A bucket created with Hierarchical Namespace enabled */
2626
HNS,
2727
/** A bucket created using all GCS default except that object versioning is enabled */
28-
VERSIONED
28+
VERSIONED,
29+
/** A Rapid bucket */
30+
RAPID
2931
}

google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/BackendResources.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
import com.google.api.gax.core.NoCredentialsProvider;
2525
import com.google.cloud.NoCredentials;
2626
import com.google.cloud.storage.BucketInfo;
27+
import com.google.cloud.storage.BucketInfo.CustomPlacementConfig;
2728
import com.google.cloud.storage.BucketInfo.HierarchicalNamespace;
2829
import com.google.cloud.storage.BucketInfo.IamConfiguration;
2930
import com.google.cloud.storage.GrpcStorageOptions;
3031
import com.google.cloud.storage.HttpStorageOptions;
3132
import com.google.cloud.storage.Storage;
33+
import com.google.cloud.storage.StorageClass;
3234
import com.google.cloud.storage.StorageOptions;
3335
import com.google.cloud.storage.TransportCompatibility.Transport;
3436
import com.google.cloud.storage.it.GrpcPlainRequestLoggingInterceptor;
@@ -242,6 +244,31 @@ static BackendResources of(
242244
storageJson.get().getStorage(),
243245
ctrl.get().getCtrl());
244246
});
247+
TestRunScopedInstance<BucketInfoShim> bucketRapid =
248+
TestRunScopedInstance.of(
249+
"fixture/BUCKET/[" + backend.name() + "]/RAPID",
250+
() -> {
251+
String bucketName =
252+
String.format(Locale.US, "java-storage-grpc-rapid-%s", UUID.randomUUID());
253+
protectedBucketNames.add(bucketName);
254+
return new BucketInfoShim(
255+
BucketInfo.newBuilder(bucketName)
256+
.setLocation(zone.get().get().getRegion())
257+
.setCustomPlacementConfig(
258+
CustomPlacementConfig.newBuilder()
259+
.setDataLocations(ImmutableList.of(zone.get().get().getZone()))
260+
.build())
261+
.setStorageClass(StorageClass.valueOf("RAPID"))
262+
.setHierarchicalNamespace(
263+
HierarchicalNamespace.newBuilder().setEnabled(true).build())
264+
.setIamConfiguration(
265+
IamConfiguration.newBuilder()
266+
.setIsUniformBucketLevelAccessEnabled(true)
267+
.build())
268+
.build(),
269+
storageJson.get().getStorage(),
270+
ctrl.get().getCtrl());
271+
});
245272
TestRunScopedInstance<ObjectsFixture> objectsFixture =
246273
TestRunScopedInstance.of(
247274
"fixture/OBJECTS/[" + backend.name() + "]",
@@ -286,6 +313,11 @@ static BackendResources of(
286313
BucketInfo.class,
287314
bucketVersioned,
288315
backendIs(backend).and(bucketTypeIs(BucketType.VERSIONED))),
316+
RegistryEntry.of(
317+
63,
318+
BucketInfo.class,
319+
bucketRapid,
320+
backendIs(backend).and(bucketTypeIs(BucketType.RAPID))),
289321
RegistryEntry.of(
290322
70, BucketInfo.class, bucket, backendIs(backend).and(isDefaultBucket())),
291323
RegistryEntry.of(

google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/registry/BucketInfoShim.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package com.google.cloud.storage.it.runner.registry;
1818

19+
import static org.junit.Assume.assumeTrue;
20+
1921
import com.google.cloud.storage.BucketInfo;
2022
import com.google.cloud.storage.Storage;
23+
import com.google.cloud.storage.StorageException;
2124
import com.google.cloud.storage.it.BucketCleaner;
2225
import com.google.storage.control.v2.StorageControlClient;
2326

@@ -47,7 +50,16 @@ public Object get() {
4750

4851
@Override
4952
public void start() {
50-
createdBucket = s.create(bucketInfo).asBucketInfo();
53+
try {
54+
createdBucket = s.create(bucketInfo).asBucketInfo();
55+
} catch (StorageException se) {
56+
String msg = se.getMessage();
57+
if (se.getCode() == 400 && msg.contains("not a valid zone in location")) {
58+
assumeTrue(
59+
"Skipping test due to bucket setup unavailable in current zone. (" + msg + ")", false);
60+
}
61+
throw se;
62+
}
5163
}
5264

5365
@Override

0 commit comments

Comments
 (0)