From 2808d953a47e2e072510edbcf93fe996f3f85dd1 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 21 Dec 2015 09:29:37 +0100 Subject: [PATCH] Minor fixes to Storage - Remove RemoteGcsHelper.create(String, String) - Fix storage example in testing/package-info.java - Fix functional classes tests --- .../storage/testing/RemoteGcsHelper.java | 31 +++++-------------- .../gcloud/storage/testing/package-info.java | 2 +- .../com/google/gcloud/storage/BlobTest.java | 2 +- .../com/google/gcloud/storage/BucketTest.java | 2 +- .../gcloud/storage/RemoteGcsHelperTest.java | 19 ------------ 5 files changed, 11 insertions(+), 45 deletions(-) diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java index f5cdae83f999..cfdbf7ac2a77 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java @@ -39,7 +39,14 @@ import java.util.logging.Logger; /** - * Utility to create a remote storage configuration for testing + * Utility to create a remote storage configuration for testing. Storage options can be obtained via + * the {@link #options()} method. Returned options have custom {@link StorageOptions#retryParams()}: + * {@link RetryParams#retryMaxAttempts()} is {@code 10}, {@link RetryParams#retryMinAttempts()} is + * {@code 6}, {@link RetryParams#maxRetryDelayMillis()} is {@code 30000}, + * {@link RetryParams#totalRetryPeriodMillis()} is {@code 120000} and + * {@link RetryParams#initialRetryDelayMillis()} is {@code 250}. + * {@link StorageOptions#connectTimeout()} and {@link StorageOptions#readTimeout()} are both set + * to {@code 60000}. */ public class RemoteGcsHelper { @@ -118,28 +125,6 @@ public static RemoteGcsHelper create(String projectId, InputStream keyStream) } } - /** - * Creates a {@code RemoteGcsHelper} object for the given project id and JSON key path. - * - * @param projectId id of the project to be used for running the tests - * @param keyPath path to the JSON key to be used for running the tests - * @return A {@code RemoteGcsHelper} object for the provided options. - * @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if the file - * pointed by {@code keyPath} does not exist - */ - public static RemoteGcsHelper create(String projectId, String keyPath) - throws GcsHelperException { - try { - InputStream keyFileStream = new FileInputStream(keyPath); - return create(projectId, keyFileStream); - } catch (FileNotFoundException ex) { - if (log.isLoggable(Level.WARNING)) { - log.log(Level.WARNING, ex.getMessage()); - } - throw GcsHelperException.translate(ex); - } - } - /** * Creates a {@code RemoteGcsHelper} object using default project id and authentication * credentials. diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java index 82b3578284dc..ced582ad21bd 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java @@ -23,7 +23,7 @@ * RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/JSON/key.json"); * Storage storage = gcsHelper.options().service(); * String bucket = RemoteGcsHelper.generateBucketName(); - * storage.create(BucketInfo.of(bucket)); + * storage.create(BucketInfo.builder(bucket).build()); * } * *

After the test: diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java index 3998ae554327..85cc0dec98ae 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java @@ -100,7 +100,7 @@ public void testReload() throws Exception { expect(storage.get(BLOB_INFO.blobId(), new Storage.BlobGetOption[0])).andReturn(updatedInfo); replay(storage); Blob updatedBlob = blob.reload(); - assertSame(storage, blob.storage()); + assertSame(storage, updatedBlob.storage()); assertEquals(updatedInfo, updatedBlob.info()); } diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java index 596f43a3c87a..392dc232cc2f 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java @@ -95,7 +95,7 @@ public void testReload() throws Exception { expect(storage.get(updatedInfo.name())).andReturn(updatedInfo); replay(storage); Bucket updatedBucket = bucket.reload(); - assertSame(storage, bucket.storage()); + assertSame(storage, updatedBucket.storage()); assertEquals(updatedInfo, updatedBucket.info()); } diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java index 3c3d1aebb3df..6b67a9576dc6 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java @@ -24,18 +24,14 @@ import com.google.gcloud.storage.testing.RemoteGcsHelper; import org.easymock.EasyMock; -import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.Iterator; import java.util.List; -import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -97,18 +93,10 @@ public Iterator iterateAll() { return BLOB_LIST.iterator(); } }; - private static String keyPath = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json"; @Rule public ExpectedException thrown = ExpectedException.none(); - @BeforeClass - public static void beforeClass() { - while (Files.exists(Paths.get(JSON_KEY))) { - keyPath = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json"; - } - } - @Test public void testForceDelete() throws InterruptedException, ExecutionException { Storage storageMock = EasyMock.createMock(Storage.class); @@ -165,11 +153,4 @@ public void testCreateFromStream() { assertEquals(120000, options.retryParams().totalRetryPeriodMillis()); assertEquals(250, options.retryParams().initialRetryDelayMillis()); } - - @Test - public void testCreateNoKey() { - thrown.expect(RemoteGcsHelper.GcsHelperException.class); - thrown.expectMessage(keyPath + " (No such file or directory)"); - RemoteGcsHelper.create(PROJECT_ID, keyPath); - } }