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

test: update ObjectsFixture to allow discrimination by @BucketFixture #1876

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -47,6 +47,7 @@ private BackendResources(
TestRunScopedInstance<BucketInfoShim> bucket,
TestRunScopedInstance<BucketInfoShim> bucketRequesterPays,
TestRunScopedInstance<ObjectsFixture> objectsFixture,
TestRunScopedInstance<ObjectsFixture> objectsFixtureRequesterPays,
TestRunScopedInstance<KmsFixture> kmsFixture) {
this.backend = backend;
this.protectedBucketNames = protectedBucketNames;
Expand All @@ -63,8 +64,14 @@ private BackendResources(
backendIs(backend).and(isRequesterPaysBucket())),
RegistryEntry.of(
7, BucketInfo.class, bucket, backendIs(backend).and(isDefaultBucket())),
RegistryEntry.of(8, ObjectsFixture.class, objectsFixture, backendIs(backend)),
RegistryEntry.of(9, KmsFixture.class, kmsFixture, backendIs(backend)));
RegistryEntry.of(
8, ObjectsFixture.class, objectsFixture, backendIs(backend).and(isDefaultBucket())),
RegistryEntry.of(
9,
ObjectsFixture.class,
objectsFixtureRequesterPays,
backendIs(backend).and(isRequesterPaysBucket())),
RegistryEntry.of(10, KmsFixture.class, kmsFixture, backendIs(backend)));
}

public ImmutableList<RegistryEntry<?>> getRegistryEntries() {
Expand Down Expand Up @@ -141,6 +148,11 @@ static BackendResources of(Backend backend) {
TestRunScopedInstance.of(
"OBJECTS_FIXTURE_" + backend.name(),
() -> new ObjectsFixture(storageJson.get().getStorage(), bucket.get().getBucketInfo()));
TestRunScopedInstance<ObjectsFixture> objectsFixtureRequesterPays =
TestRunScopedInstance.of(
"OBJECTS_FIXTURE_REQUESTER_PAYS_" + backend.name(),
() ->
new ObjectsFixture(storageJson.get().getStorage(), bucketRp.get().getBucketInfo()));
TestRunScopedInstance<KmsFixture> kmsFixture =
TestRunScopedInstance.of(
"KMS_FIXTURE_" + backend.name(), () -> KmsFixture.of(storageJson.get().getStorage()));
Expand All @@ -153,6 +165,7 @@ static BackendResources of(Backend backend) {
bucket,
bucketRp,
objectsFixture,
objectsFixtureRequesterPays,
kmsFixture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.DataGenerator;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.Storage.BlobGetOption;
import com.google.cloud.storage.Storage.BlobTargetOption;
import com.google.cloud.storage.Storage.ComposeRequest;
import com.google.cloud.storage.it.ChecksummedTestContent;
Expand All @@ -34,6 +35,9 @@ public final class ObjectsFixture implements ManagedLifecycle {
private final Storage s;
private final BucketInfo bucket;

private final BlobTargetOption[] blobTargetOptions;
private final BlobGetOption[] blobGetOptions;

private BlobInfo info1;
private BlobInfo info2;
private BlobInfo info3;
Expand All @@ -43,6 +47,21 @@ public final class ObjectsFixture implements ManagedLifecycle {
ObjectsFixture(Storage s, BucketInfo bucket) {
this.s = s;
this.bucket = bucket;
boolean isRequesterPays = Boolean.TRUE.equals(bucket.requesterPays());
String projectId = s.getOptions().getProjectId();
if (isRequesterPays) {
blobTargetOptions =
new BlobTargetOption[] {
BlobTargetOption.doesNotExist(), BlobTargetOption.userProject(projectId)
};
} else {
blobTargetOptions = new BlobTargetOption[] {BlobTargetOption.doesNotExist()};
}
if (isRequesterPays) {
blobGetOptions = new BlobGetOption[] {BlobGetOption.userProject(projectId)};
} else {
blobGetOptions = new BlobGetOption[] {};
}
}

@Override
Expand Down Expand Up @@ -83,41 +102,38 @@ public void start() {
BlobInfo info2 = BlobInfo.newBuilder(blobId2).setMetadata(ImmutableMap.of("pow", "2")).build();
BlobInfo info3 = BlobInfo.newBuilder(blobId3).setMetadata(ImmutableMap.of("pow", "3")).build();
BlobInfo info4 = BlobInfo.newBuilder(blobId4).setMetadata(ImmutableMap.of("pow", "4")).build();
s.create(info1, "A".getBytes(StandardCharsets.UTF_8), BlobTargetOption.doesNotExist());
s.create(info1, "A".getBytes(StandardCharsets.UTF_8), blobTargetOptions);

ComposeRequest c2 =
ComposeRequest.newBuilder()
.addSource(blobId1.getName(), blobId1.getName())
.setTarget(info2)
.setTargetOptions(BlobTargetOption.doesNotExist())
.setTargetOptions(blobTargetOptions)
.build();
ComposeRequest c3 =
ComposeRequest.newBuilder()
.addSource(blobId2.getName(), blobId2.getName())
.setTarget(info3)
.setTargetOptions(BlobTargetOption.doesNotExist())
.setTargetOptions(blobTargetOptions)
.build();
ComposeRequest c4 =
ComposeRequest.newBuilder()
.addSource(blobId3.getName(), blobId3.getName())
.setTarget(info4)
.setTargetOptions(BlobTargetOption.doesNotExist())
.setTargetOptions(blobTargetOptions)
.build();
s.compose(c2);
s.compose(c3);
s.compose(c4);

this.info1 = s.get(blobId1).asBlobInfo();
this.info2 = s.get(blobId2).asBlobInfo();
this.info3 = s.get(blobId3).asBlobInfo();
this.info4 = s.get(blobId4).asBlobInfo();
this.info1 = s.get(blobId1, blobGetOptions).asBlobInfo();
this.info2 = s.get(blobId2, blobGetOptions).asBlobInfo();
this.info3 = s.get(blobId3, blobGetOptions).asBlobInfo();
this.info4 = s.get(blobId4, blobGetOptions).asBlobInfo();

byte[] bytes = DataGenerator.base64Characters().genBytes(512 * 1024);
Blob obj512KiB =
s.create(
BlobInfo.newBuilder(bucket, "obj512KiB").build(),
bytes,
BlobTargetOption.doesNotExist());
s.create(BlobInfo.newBuilder(bucket, "obj512KiB").build(), bytes, blobTargetOptions);
this.obj512KiB = new ObjectAndContent(obj512KiB.asBlobInfo(), ChecksummedTestContent.of(bytes));
}

Expand Down