From d2a2177419ba11e9ddcf412cdfea7ddf2b901e6e Mon Sep 17 00:00:00 2001 From: andrey-qlogic Date: Mon, 3 Dec 2018 20:34:17 +0000 Subject: [PATCH 1/6] 3822: Added BlobTargetOption for user to set disabledGzipContent true --- .../src/main/java/com/google/cloud/storage/Storage.java | 8 ++++++++ .../com/google/cloud/storage/spi/v1/HttpStorageRpc.java | 4 ++++ .../java/com/google/cloud/storage/spi/v1/StorageRpc.java | 1 + 3 files changed, 13 insertions(+) diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java index 1702c2616a0e..bd78bbd3e334 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java @@ -346,6 +346,14 @@ public static BlobTargetOption metagenerationNotMatch() { return new BlobTargetOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH); } + /** + * Returns an option for blob's data diabledGzipContent. If this option is used the request will + * create an with disabled Gzip Content. + */ + public static BlobTargetOption disableGzipContent() { + return new BlobTargetOption(StorageRpc.Option.IF_DISABLE_GZIP_CONTENT, true); + } + /** * Returns an option to set a customer-supplied AES256 key for server-side encryption of the * blob. diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java index 709e01a25064..087f4a207d35 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java @@ -16,6 +16,7 @@ package com.google.cloud.storage.spi.v1; +import static com.google.cloud.storage.spi.v1.StorageRpc.Option.IF_DISABLE_GZIP_CONTENT; import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; import static java.net.HttpURLConnection.HTTP_NOT_FOUND; @@ -287,6 +288,9 @@ public StorageObject create( storageObject, new InputStreamContent(storageObject.getContentType(), content)); insert.getMediaHttpUploader().setDirectUploadEnabled(true); + Boolean disableGzipContent = Option.IF_DISABLE_GZIP_CONTENT.getBoolean(options); + if (disableGzipContent != null) + insert.getMediaHttpUploader().setDisableGZipContent(disableGzipContent); setEncryptionHeaders(insert.getRequestHeaders(), ENCRYPTION_KEY_PREFIX, options); return insert .setProjection(DEFAULT_PROJECTION) diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/StorageRpc.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/StorageRpc.java index 117cd20faa85..447643283d94 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/StorageRpc.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/StorageRpc.java @@ -48,6 +48,7 @@ enum Option { IF_SOURCE_METAGENERATION_NOT_MATCH("ifSourceMetagenerationNotMatch"), IF_SOURCE_GENERATION_MATCH("ifSourceGenerationMatch"), IF_SOURCE_GENERATION_NOT_MATCH("ifSourceGenerationNotMatch"), + IF_DISABLE_GZIP_CONTENT("disableGzipContent"), PREFIX("prefix"), MAX_RESULTS("maxResults"), PAGE_TOKEN("pageToken"), From 75b8a552aad2b43e5995513adb79c30197306311 Mon Sep 17 00:00:00 2001 From: andrey-qlogic Date: Mon, 3 Dec 2018 21:05:02 +0000 Subject: [PATCH 2/6] 3822: Changed method comment --- .../src/main/java/com/google/cloud/storage/Storage.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java index bd78bbd3e334..a01cef4df71e 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java @@ -347,8 +347,7 @@ public static BlobTargetOption metagenerationNotMatch() { } /** - * Returns an option for blob's data diabledGzipContent. If this option is used the request will - * create an with disabled Gzip Content. + * Returns an option for blob's upload with the parameter disabledGzipContent. */ public static BlobTargetOption disableGzipContent() { return new BlobTargetOption(StorageRpc.Option.IF_DISABLE_GZIP_CONTENT, true); From 1026169f8360810692927f3033f3d696c769fa4d Mon Sep 17 00:00:00 2001 From: andrey-qlogic Date: Mon, 3 Dec 2018 21:41:52 +0000 Subject: [PATCH 3/6] 3822: Changed method comment with more explanation --- .../src/main/java/com/google/cloud/storage/Storage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java index a01cef4df71e..4afe0c2c1e83 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java @@ -347,7 +347,8 @@ public static BlobTargetOption metagenerationNotMatch() { } /** - * Returns an option for blob's upload with the parameter disabledGzipContent. + * Returns an option for blob's data disabledGzipContent. If this option is used, + * the request will create a blob with disableGzipContent; at present, this is only for upload. */ public static BlobTargetOption disableGzipContent() { return new BlobTargetOption(StorageRpc.Option.IF_DISABLE_GZIP_CONTENT, true); From bae0e48dd0500b2d7b9794623dea34e022ab3231 Mon Sep 17 00:00:00 2001 From: andrey-qlogic Date: Tue, 4 Dec 2018 19:19:47 +0000 Subject: [PATCH 4/6] 3822: Fixed comments after review. Added unit test --- .../cloud/storage/spi/v1/HttpStorageRpc.java | 1 - .../google/cloud/storage/StorageImplTest.java | 35 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java index 087f4a207d35..881dd213cabd 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java @@ -16,7 +16,6 @@ package com.google.cloud.storage.spi.v1; -import static com.google.cloud.storage.spi.v1.StorageRpc.Option.IF_DISABLE_GZIP_CONTENT; import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; import static java.net.HttpURLConnection.HTTP_NOT_FOUND; diff --git a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java index cad54d597d78..dbf4d6b2fba8 100644 --- a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java +++ b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java @@ -154,6 +154,8 @@ public class StorageImplTest { private static final BlobTargetOption BLOB_TARGET_GENERATION = BlobTargetOption.generationMatch(); private static final BlobTargetOption BLOB_TARGET_METAGENERATION = BlobTargetOption.metagenerationMatch(); + private static final BlobTargetOption BLOB_TARGET_DISABLE_GZIP_CONTENT = + BlobTargetOption.disableGzipContent(); private static final BlobTargetOption BLOB_TARGET_NOT_EXIST = BlobTargetOption.doesNotExist(); private static final BlobTargetOption BLOB_TARGET_PREDEFINED_ACL = BlobTargetOption.predefinedAcl(Storage.PredefinedAcl.PRIVATE); @@ -162,6 +164,9 @@ public class StorageImplTest { StorageRpc.Option.IF_METAGENERATION_MATCH, BLOB_INFO1.getMetageneration(), StorageRpc.Option.IF_GENERATION_MATCH, 0L, StorageRpc.Option.PREDEFINED_ACL, BUCKET_TARGET_PREDEFINED_ACL.getValue()); + private static final Map BLOB_TARGET_OPTIONS_CREATE_DISABLE_GZIP_CONTENT = + ImmutableMap.of( + StorageRpc.Option.IF_DISABLE_GZIP_CONTENT, true); private static final Map BLOB_TARGET_OPTIONS_UPDATE = ImmutableMap.of( StorageRpc.Option.IF_METAGENERATION_MATCH, BLOB_INFO1.getMetageneration(), @@ -545,6 +550,36 @@ public void testCreateBlobWithOptions() throws IOException { assertEquals(-1, byteStream.read(streamBytes)); } + @Test + public void testCreateBlobWithDisabledGzipContent() throws IOException { + Capture capturedStream = Capture.newInstance(); + EasyMock.expect( + storageRpcMock.create( + EasyMock.eq( + BLOB_INFO1 + .toBuilder() + .setMd5(CONTENT_MD5) + .setCrc32c(CONTENT_CRC32C) + .build() + .toPb()), + EasyMock.capture(capturedStream), + EasyMock.eq(BLOB_TARGET_OPTIONS_CREATE_DISABLE_GZIP_CONTENT))) + .andReturn(BLOB_INFO1.toPb()); + EasyMock.replay(storageRpcMock); + initializeService(); + Blob blob = + storage.create( + BLOB_INFO1, + BLOB_CONTENT, + BLOB_TARGET_DISABLE_GZIP_CONTENT); + assertEquals(expectedBlob1, blob); + ByteArrayInputStream byteStream = capturedStream.getValue(); + byte[] streamBytes = new byte[BLOB_CONTENT.length]; + assertEquals(BLOB_CONTENT.length, byteStream.read(streamBytes)); + assertArrayEquals(BLOB_CONTENT, streamBytes); + assertEquals(-1, byteStream.read(streamBytes)); + } + @Test public void testCreateBlobWithEncryptionKey() throws IOException { Capture capturedStream = Capture.newInstance(); From f03e539f51c5d852bcf14721ac63553693ebb724 Mon Sep 17 00:00:00 2001 From: andrey-qlogic Date: Wed, 5 Dec 2018 10:18:20 +0000 Subject: [PATCH 5/6] 3822: Fixed formatting errors in Storage class --- .../src/main/java/com/google/cloud/storage/Storage.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java index 4afe0c2c1e83..6ce9ca8c6e2a 100644 --- a/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java +++ b/google-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java @@ -347,8 +347,8 @@ public static BlobTargetOption metagenerationNotMatch() { } /** - * Returns an option for blob's data disabledGzipContent. If this option is used, - * the request will create a blob with disableGzipContent; at present, this is only for upload. + * Returns an option for blob's data disabledGzipContent. If this option is used, the request + * will create a blob with disableGzipContent; at present, this is only for upload. */ public static BlobTargetOption disableGzipContent() { return new BlobTargetOption(StorageRpc.Option.IF_DISABLE_GZIP_CONTENT, true); From 5f53615d50de2485b8edbe5363ec0f54ace00282 Mon Sep 17 00:00:00 2001 From: andrey-qlogic Date: Wed, 5 Dec 2018 10:44:15 +0000 Subject: [PATCH 6/6] 3822: Fixed formatting errors in StorageImplTest class --- .../google/cloud/storage/StorageImplTest.java | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java index dbf4d6b2fba8..393c7ff3bfcf 100644 --- a/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java +++ b/google-cloud-clients/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageImplTest.java @@ -165,8 +165,7 @@ public class StorageImplTest { StorageRpc.Option.IF_GENERATION_MATCH, 0L, StorageRpc.Option.PREDEFINED_ACL, BUCKET_TARGET_PREDEFINED_ACL.getValue()); private static final Map BLOB_TARGET_OPTIONS_CREATE_DISABLE_GZIP_CONTENT = - ImmutableMap.of( - StorageRpc.Option.IF_DISABLE_GZIP_CONTENT, true); + ImmutableMap.of(StorageRpc.Option.IF_DISABLE_GZIP_CONTENT, true); private static final Map BLOB_TARGET_OPTIONS_UPDATE = ImmutableMap.of( StorageRpc.Option.IF_METAGENERATION_MATCH, BLOB_INFO1.getMetageneration(), @@ -554,24 +553,20 @@ public void testCreateBlobWithOptions() throws IOException { public void testCreateBlobWithDisabledGzipContent() throws IOException { Capture capturedStream = Capture.newInstance(); EasyMock.expect( - storageRpcMock.create( - EasyMock.eq( - BLOB_INFO1 - .toBuilder() - .setMd5(CONTENT_MD5) - .setCrc32c(CONTENT_CRC32C) - .build() - .toPb()), - EasyMock.capture(capturedStream), - EasyMock.eq(BLOB_TARGET_OPTIONS_CREATE_DISABLE_GZIP_CONTENT))) + storageRpcMock.create( + EasyMock.eq( + BLOB_INFO1 + .toBuilder() + .setMd5(CONTENT_MD5) + .setCrc32c(CONTENT_CRC32C) + .build() + .toPb()), + EasyMock.capture(capturedStream), + EasyMock.eq(BLOB_TARGET_OPTIONS_CREATE_DISABLE_GZIP_CONTENT))) .andReturn(BLOB_INFO1.toPb()); EasyMock.replay(storageRpcMock); initializeService(); - Blob blob = - storage.create( - BLOB_INFO1, - BLOB_CONTENT, - BLOB_TARGET_DISABLE_GZIP_CONTENT); + Blob blob = storage.create(BLOB_INFO1, BLOB_CONTENT, BLOB_TARGET_DISABLE_GZIP_CONTENT); assertEquals(expectedBlob1, blob); ByteArrayInputStream byteStream = capturedStream.getValue(); byte[] streamBytes = new byte[BLOB_CONTENT.length];