Skip to content

Commit 2808d95

Browse files
committed
Minor fixes to Storage
- Remove RemoteGcsHelper.create(String, String) - Fix storage example in testing/package-info.java - Fix functional classes tests
1 parent e86259d commit 2808d95

5 files changed

Lines changed: 11 additions & 45 deletions

File tree

gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@
3939
import java.util.logging.Logger;
4040

4141
/**
42-
* Utility to create a remote storage configuration for testing
42+
* Utility to create a remote storage configuration for testing. Storage options can be obtained via
43+
* the {@link #options()} method. Returned options have custom {@link StorageOptions#retryParams()}:
44+
* {@link RetryParams#retryMaxAttempts()} is {@code 10}, {@link RetryParams#retryMinAttempts()} is
45+
* {@code 6}, {@link RetryParams#maxRetryDelayMillis()} is {@code 30000},
46+
* {@link RetryParams#totalRetryPeriodMillis()} is {@code 120000} and
47+
* {@link RetryParams#initialRetryDelayMillis()} is {@code 250}.
48+
* {@link StorageOptions#connectTimeout()} and {@link StorageOptions#readTimeout()} are both set
49+
* to {@code 60000}.
4350
*/
4451
public class RemoteGcsHelper {
4552

@@ -118,28 +125,6 @@ public static RemoteGcsHelper create(String projectId, InputStream keyStream)
118125
}
119126
}
120127

121-
/**
122-
* Creates a {@code RemoteGcsHelper} object for the given project id and JSON key path.
123-
*
124-
* @param projectId id of the project to be used for running the tests
125-
* @param keyPath path to the JSON key to be used for running the tests
126-
* @return A {@code RemoteGcsHelper} object for the provided options.
127-
* @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if the file
128-
* pointed by {@code keyPath} does not exist
129-
*/
130-
public static RemoteGcsHelper create(String projectId, String keyPath)
131-
throws GcsHelperException {
132-
try {
133-
InputStream keyFileStream = new FileInputStream(keyPath);
134-
return create(projectId, keyFileStream);
135-
} catch (FileNotFoundException ex) {
136-
if (log.isLoggable(Level.WARNING)) {
137-
log.log(Level.WARNING, ex.getMessage());
138-
}
139-
throw GcsHelperException.translate(ex);
140-
}
141-
}
142-
143128
/**
144129
* Creates a {@code RemoteGcsHelper} object using default project id and authentication
145130
* credentials.

gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/JSON/key.json");
2424
* Storage storage = gcsHelper.options().service();
2525
* String bucket = RemoteGcsHelper.generateBucketName();
26-
* storage.create(BucketInfo.of(bucket));
26+
* storage.create(BucketInfo.builder(bucket).build());
2727
* } </pre>
2828
*
2929
* <p>After the test:

gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void testReload() throws Exception {
100100
expect(storage.get(BLOB_INFO.blobId(), new Storage.BlobGetOption[0])).andReturn(updatedInfo);
101101
replay(storage);
102102
Blob updatedBlob = blob.reload();
103-
assertSame(storage, blob.storage());
103+
assertSame(storage, updatedBlob.storage());
104104
assertEquals(updatedInfo, updatedBlob.info());
105105
}
106106

gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void testReload() throws Exception {
9595
expect(storage.get(updatedInfo.name())).andReturn(updatedInfo);
9696
replay(storage);
9797
Bucket updatedBucket = bucket.reload();
98-
assertSame(storage, bucket.storage());
98+
assertSame(storage, updatedBucket.storage());
9999
assertEquals(updatedInfo, updatedBucket.info());
100100
}
101101

gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@
2424
import com.google.gcloud.storage.testing.RemoteGcsHelper;
2525

2626
import org.easymock.EasyMock;
27-
import org.junit.BeforeClass;
2827
import org.junit.Rule;
2928
import org.junit.Test;
3029
import org.junit.rules.ExpectedException;
3130

3231
import java.io.ByteArrayInputStream;
3332
import java.io.InputStream;
34-
import java.nio.file.Files;
35-
import java.nio.file.Paths;
3633
import java.util.Iterator;
3734
import java.util.List;
38-
import java.util.UUID;
3935
import java.util.concurrent.ExecutionException;
4036
import java.util.concurrent.TimeUnit;
4137

@@ -97,18 +93,10 @@ public Iterator<BlobInfo> iterateAll() {
9793
return BLOB_LIST.iterator();
9894
}
9995
};
100-
private static String keyPath = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json";
10196

10297
@Rule
10398
public ExpectedException thrown = ExpectedException.none();
10499

105-
@BeforeClass
106-
public static void beforeClass() {
107-
while (Files.exists(Paths.get(JSON_KEY))) {
108-
keyPath = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json";
109-
}
110-
}
111-
112100
@Test
113101
public void testForceDelete() throws InterruptedException, ExecutionException {
114102
Storage storageMock = EasyMock.createMock(Storage.class);
@@ -165,11 +153,4 @@ public void testCreateFromStream() {
165153
assertEquals(120000, options.retryParams().totalRetryPeriodMillis());
166154
assertEquals(250, options.retryParams().initialRetryDelayMillis());
167155
}
168-
169-
@Test
170-
public void testCreateNoKey() {
171-
thrown.expect(RemoteGcsHelper.GcsHelperException.class);
172-
thrown.expectMessage(keyPath + " (No such file or directory)");
173-
RemoteGcsHelper.create(PROJECT_ID, keyPath);
174-
}
175156
}

0 commit comments

Comments
 (0)