Skip to content

Commit

Permalink
Minor fixes to Storage
Browse files Browse the repository at this point in the history
- Remove RemoteGcsHelper.create(String, String)
- Fix storage example in testing/package-info.java
- Fix functional classes tests
  • Loading branch information
mziccard committed Dec 21, 2015
1 parent e86259d commit 2808d95
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
* } </pre>
*
* <p>After the test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -97,18 +93,10 @@ public Iterator<BlobInfo> 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);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2808d95

Please sign in to comment.