Skip to content
Permalink
Browse files
JCLOUDS-1546: Support GCS Archive storage class
Also change portable abstraction mapping for Tier.ARCHIVE.
  • Loading branch information
gaul committed May 9, 2020
1 parent d220b24 commit 08a16c95fbd115f5afed52898e91bacd013e9cde
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
@@ -86,6 +86,7 @@ public static Location fromValue(String location) {
}

public enum StorageClass {
ARCHIVE(Tier.ARCHIVE),
COLDLINE(Tier.ARCHIVE),
DURABLE_REDUCED_AVAILABILITY(Tier.STANDARD),
MULTI_REGIONAL(Tier.STANDARD),
@@ -103,7 +104,7 @@ public static StorageClass fromTier(Tier tier) {
switch (tier) {
case STANDARD: return StorageClass.STANDARD;
case INFREQUENT: return StorageClass.NEARLINE;
case ARCHIVE: return StorageClass.COLDLINE;
case ARCHIVE: return StorageClass.ARCHIVE;
}
throw new IllegalArgumentException("invalid tier: " + tier);
}
@@ -60,6 +60,8 @@ public class BucketApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {

private static final String BUCKET_NAME_COLDLINE = "jcloudstestbucketcoldline" + (int) (Math.random() * 10000);

private static final String BUCKET_NAME_ARCHIVE = "jcloudstestbucketarchive" + (int) (Math.random() * 10000);

private static final String BUCKET_NAME_MULTI_REGIONAL = "jcloudstestbucketmultiregional" + (int) (Math.random() * 10000);

private static final String BUCKET_NAME_NEARLINE = "jcloudstestbucketnearline" + (int) (Math.random() * 10000);
@@ -141,6 +143,23 @@ public void testCreateBucketColdline() {
api().deleteBucket(BUCKET_NAME_COLDLINE);
}

@Test(groups = "live")
public void testCreateBucketArchive() {
BucketTemplate template = new BucketTemplate()
.name(BUCKET_NAME_ARCHIVE)
.location(Location.US)
.storageClass(StorageClass.ARCHIVE);

Bucket response = api().createBucket(PROJECT_NUMBER, template);

assertNotNull(response);
assertEquals(response.name(), BUCKET_NAME_ARCHIVE);
assertEquals(response.location(), Location.US);
assertThat(response.storageClass()).isEqualTo(StorageClass.ARCHIVE);

api().deleteBucket(BUCKET_NAME_ARCHIVE);
}

@Test(groups = "live")
public void testCreateBucketMultiregional() {
BucketTemplate template = new BucketTemplate()
@@ -449,6 +449,48 @@ public void testMultipartJpegUpload() throws IOException {
ByteStreams2.toByteArrayAndClose(payloadImpl.getPayload().openStream()));
}

@Test(groups = "live", dependsOnMethods = "testPatchObjectsWithOptions")
public void testMultipartJpegUploadArchive() throws IOException {
long contentLength = 32 * 1024L;
ByteSource byteSource = TestUtils.randomByteSource().slice(0, contentLength);
ByteSourcePayload payload = Payloads.newByteSourcePayload(byteSource);
PayloadEnclosing payloadImpl = new PayloadEnclosingImpl(payload);

ObjectTemplate template = new ObjectTemplate();

ObjectAccessControls oacl = ObjectAccessControls.builder().bucket(BUCKET_NAME).entity("allUsers")
.role(ObjectRole.OWNER).build();

// This would trigger server side validation of md5
md5Hash = base64().encode(byteSource.hash(Hashing.md5()).asBytes());
// TODO: crc32c = without making a compile dep on guava 18

template.contentType("image/jpeg").addAcl(oacl).size(contentLength).name(MULTIPART_UPLOAD_OBJECT)
.contentLanguage("en").contentDisposition("attachment").md5Hash(md5Hash)
.storageClass(StorageClass.ARCHIVE)
.customMetadata("custommetakey1", "custommetavalue1").crc32c(crc32c)
.customMetadata(ImmutableMap.of("Adrian", "powderpuff"));

GoogleCloudStorageObject gcsObject = api().multipartUpload(BUCKET_NAME, template, payloadImpl.getPayload());

assertThat(gcsObject.bucket()).isEqualTo(BUCKET_NAME);
assertThat(gcsObject.name()).isEqualTo(MULTIPART_UPLOAD_OBJECT);
checkHashCodes(gcsObject);

assertThat(gcsObject.metadata()).contains(entry("custommetakey1", "custommetavalue1"),
entry("Adrian", "powderpuff")).doesNotContainKey("adrian");

gcsObject = api().getObject(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT, null);

assertThat(gcsObject).isNotNull();
assertThat(gcsObject.storageClass()).isEqualTo(StorageClass.ARCHIVE);

PayloadEnclosing impl = api().download(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT);

assertThat(ByteStreams2.toByteArrayAndClose(impl.getPayload().openStream())).isEqualTo(
ByteStreams2.toByteArrayAndClose(payloadImpl.getPayload().openStream()));
}

private void checkHashCodes(GoogleCloudStorageObject gcsObject) {
assertEquals(gcsObject.md5Hash(), md5Hash);
if (crc32c != null) {

0 comments on commit 08a16c9

Please sign in to comment.