Skip to content

Commit

Permalink
More style fixes to Storage module
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Dec 21, 2015
1 parent b504340 commit 604b1c4
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ public Tuple<String, byte[]> read(StorageObject from, Map<Option, ?> options, lo
}

@Override
public void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest,
long destOffset, int length, boolean last) throws StorageException {
public void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length,
boolean last) throws StorageException {
try {
GenericUrl url = new GenericUrl(uploadId);
HttpRequest httpRequest = storage.getRequestFactory().buildPutRequest(url,
Expand Down Expand Up @@ -571,7 +571,7 @@ private RewriteResponse rewrite(RewriteRequest req, String token) throws Storage
try {
Long maxBytesRewrittenPerCall = req.megabytesRewrittenPerCall != null
? req.megabytesRewrittenPerCall * MEGABYTE : null;
com.google.api.services.storage.model.RewriteResponse rewriteReponse = storage.objects()
com.google.api.services.storage.model.RewriteResponse rewriteResponse = storage.objects()
.rewrite(req.source.getBucket(), req.source.getName(), req.target.getBucket(),
req.target.getName(), req.target.getContentType() != null ? req.target : null)
.setSourceGeneration(req.source.getGeneration())
Expand All @@ -590,11 +590,11 @@ private RewriteResponse rewrite(RewriteRequest req, String token) throws Storage
.execute();
return new RewriteResponse(
req,
rewriteReponse.getResource(),
rewriteReponse.getObjectSize().longValue(),
rewriteReponse.getDone(),
rewriteReponse.getRewriteToken(),
rewriteReponse.getTotalBytesRewritten().longValue());
rewriteResponse.getResource(),
rewriteResponse.getObjectSize().longValue(),
rewriteResponse.getDone(),
rewriteResponse.getRewriteToken(),
rewriteResponse.getTotalBytesRewritten().longValue());
} catch (IOException ex) {
throw translate(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ Tuple<String, byte[]> read(StorageObject from, Map<Option, ?> options, long posi

String open(StorageObject object, Map<Option, ?> options) throws StorageException;

void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest,
long destOffset, int length, boolean last) throws StorageException;
void write(String uploadId, byte[] toWrite, int toWriteOffset, long destOffset, int length,
boolean last) throws StorageException;

RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws StorageException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ String toPb() {
}

/**
* Creats an ACL object.
* Creates an ACL object.
*
* @param entity the entity for this ACL object
* @param role the role to associate to the {@code entity} object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Builder mediaLink(String mediaLink) {
*/
public Builder metadata(Map<String, String> metadata) {
this.metadata = metadata != null
? new HashMap(metadata) : Data.<Map>nullOf(ImmutableEmptyMap.class);
? new HashMap<>(metadata) : Data.<Map<String, String>>nullOf(ImmutableEmptyMap.class);
return this;
}

Expand Down Expand Up @@ -576,8 +576,9 @@ public ObjectAccessControl apply(Acl acl) {
Map<String, String> pbMetadata = metadata;
if (metadata != null && !Data.isNull(metadata)) {
pbMetadata = Maps.newHashMapWithExpectedSize(metadata.size());
for (String key : metadata.keySet()) {
pbMetadata.put(key, firstNonNull(metadata.get(key), Data.<String>nullOf(String.class)));
for (Map.Entry<String, String> entry : metadata.entrySet()) {
pbMetadata.put(entry.getKey(),
firstNonNull(entry.getValue(), Data.<String>nullOf(String.class)));
}
}
storageObject.setMetadata(pbMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void flush() {
runWithRetries(callable(new Runnable() {
@Override
public void run() {
storageRpc.write(uploadId, buffer, 0, storageObject, position, length, false);
storageRpc.write(uploadId, buffer, 0, position, length, false);
}
}), options.retryParams(), StorageImpl.EXCEPTION_HANDLER);
} catch (RetryHelper.RetryHelperException e) {
Expand Down Expand Up @@ -139,7 +139,7 @@ public void close() throws IOException {
runWithRetries(callable(new Runnable() {
@Override
public void run() {
storageRpc.write(uploadId, buffer, 0, storageObject, position, limit, true);
storageRpc.write(uploadId, buffer, 0, position, limit, true);
}
}), options.retryParams(), StorageImpl.EXCEPTION_HANDLER);
} catch (RetryHelper.RetryHelperException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static class BlobPageFetcher implements PageImpl.NextPageFetcher<Blob> {
@Override
public Page<Blob> nextPage() {
Page<BlobInfo> nextInfoPage = infoPage.nextPage();
return new PageImpl<Blob>(new BlobPageFetcher(options, nextInfoPage),
return new PageImpl<>(new BlobPageFetcher(options, nextInfoPage),
nextInfoPage.nextPageCursor(), new LazyBlobIterable(options, nextInfoPage.values()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
*/
public interface Storage extends Service<StorageOptions> {

public static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
String DEFAULT_CONTENT_TYPE = "application/octet-stream";

enum PredefinedAcl {
AUTHENTICATED_READ("authenticatedRead"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -272,13 +273,13 @@ public void testDeleteNone() throws Exception {

@Test
public void testDeleteSome() throws Exception {
List<Boolean> deleleResultList = Arrays.asList(true, true, true);
expect(storage.delete(BLOB_ID_ARRAY)).andReturn(deleleResultList);
List<Boolean> deleteResult = Arrays.asList(true, true, true);
expect(storage.delete(BLOB_ID_ARRAY)).andReturn(deleteResult);
replay(storage);
List<Boolean> result = Blob.delete(storage, BLOB_ID_ARRAY);
assertEquals(deleleResultList.size(), result.size());
for (int i = 0; i < deleleResultList.size(); i++) {
assertEquals(deleleResultList.get(i), result.get(i));
assertEquals(deleteResult.size(), result.size());
for (int i = 0; i < deleteResult.size(); i++) {
assertEquals(deleteResult.get(i), result.get(i));
}
}

Expand All @@ -295,6 +296,7 @@ public void testLoadFromId() throws Exception {
expect(storage.get(BLOB_INFO.blobId())).andReturn(BLOB_INFO);
replay(storage);
Blob loadedBlob = Blob.load(storage, BLOB_INFO.blobId());
assertNotNull(loadedBlob);
assertEquals(BLOB_INFO, loadedBlob.info());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public void testWriteWithoutFlush() throws IOException {
public void testWriteWithFlush() throws IOException {
expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture<byte[]> capturedBuffer = Capture.newInstance();
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
eq(BLOB_INFO.toPb()), eq(0L), eq(CUSTOM_CHUNK_SIZE), eq(false));
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L),
eq(CUSTOM_CHUNK_SIZE), eq(false));
replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
writer.chunkSize(CUSTOM_CHUNK_SIZE);
Expand All @@ -116,9 +116,8 @@ public void testWriteWithFlush() throws IOException {
public void testWritesAndFlush() throws IOException {
expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture<byte[]> capturedBuffer = Capture.newInstance();
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
eq(BLOB_INFO.toPb()), eq(0L), eq(DEFAULT_CHUNK_SIZE),
eq(false));
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L),
eq(DEFAULT_CHUNK_SIZE), eq(false));
replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
ByteBuffer[] buffers = new ByteBuffer[DEFAULT_CHUNK_SIZE / MIN_CHUNK_SIZE];
Expand All @@ -138,8 +137,7 @@ public void testWritesAndFlush() throws IOException {
public void testCloseWithoutFlush() throws IOException {
expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture<byte[]> capturedBuffer = Capture.newInstance();
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
eq(BLOB_INFO.toPb()), eq(0L), eq(0), eq(true));
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(0), eq(true));
replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
assertTrue(writer.isOpen());
Expand All @@ -153,8 +151,7 @@ public void testCloseWithFlush() throws IOException {
expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture<byte[]> capturedBuffer = Capture.newInstance();
ByteBuffer buffer = randomBuffer(MIN_CHUNK_SIZE);
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
eq(BLOB_INFO.toPb()), eq(0L), eq(MIN_CHUNK_SIZE),
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(MIN_CHUNK_SIZE),
eq(true));
replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
Expand All @@ -170,8 +167,7 @@ public void testCloseWithFlush() throws IOException {
public void testWriteClosed() throws IOException {
expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture<byte[]> capturedBuffer = Capture.newInstance();
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
eq(BLOB_INFO.toPb()), eq(0L), eq(0), eq(true));
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(0), eq(true));
replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
writer.close();
Expand All @@ -189,8 +185,7 @@ public void testSaveAndRestore() throws IOException {
Capture<byte[]> capturedBuffer = Capture.newInstance(CaptureType.ALL);
Capture<Long> capturedPosition = Capture.newInstance(CaptureType.ALL);
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
eq(BLOB_INFO.toPb()), captureLong(capturedPosition),
eq(DEFAULT_CHUNK_SIZE), eq(false));
captureLong(capturedPosition), eq(DEFAULT_CHUNK_SIZE), eq(false));
expectLastCall().times(2);
replay(storageRpcMock);
ByteBuffer buffer1 = randomBuffer(DEFAULT_CHUNK_SIZE);
Expand All @@ -210,8 +205,7 @@ public void testSaveAndRestore() throws IOException {
public void testSaveAndRestoreClosed() throws IOException {
expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture<byte[]> capturedBuffer = Capture.newInstance();
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
eq(BLOB_INFO.toPb()), eq(0L), eq(0), eq(true));
storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0), eq(0L), eq(0), eq(true));
replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
writer.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -219,6 +220,7 @@ public void testLoad() throws Exception {
expect(storage.get(BUCKET_INFO.name())).andReturn(BUCKET_INFO);
replay(storage);
Bucket loadedBucket = Bucket.load(storage, BUCKET_INFO.name());
assertNotNull(loadedBucket);
assertEquals(BUCKET_INFO, loadedBucket.info());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void testGetBlobFailNonExistingGeneration() {
public void testListBlobsSelectedFields() {
String[] blobNames = {"test-list-blobs-selected-fields-blob1",
"test-list-blobs-selected-fields-blob2"};
ImmutableMap metadata = ImmutableMap.of("k", "v");
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo blob1 = BlobInfo.builder(BUCKET, blobNames[0])
.contentType(CONTENT_TYPE)
.metadata(metadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,7 @@ public void testGetBucketWithOptions() {

@Test
public void testGetBucketWithSelectedFields() {
Capture<Map<StorageRpc.Option, Object>> capturedOptions =
Capture.<Map<StorageRpc.Option, Object>>newInstance();
Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance();
EasyMock.expect(storageRpcMock.get(EasyMock.eq(BucketInfo.of(BUCKET_NAME1).toPb()),
EasyMock.capture(capturedOptions))).andReturn(BUCKET_INFO1.toPb());
EasyMock.replay(storageRpcMock);
Expand All @@ -417,8 +416,7 @@ public void testGetBucketWithSelectedFields() {

@Test
public void testGetBucketWithEmptyFields() {
Capture<Map<StorageRpc.Option, Object>> capturedOptions =
Capture.<Map<StorageRpc.Option, Object>>newInstance();
Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance();
EasyMock.expect(storageRpcMock.get(EasyMock.eq(BucketInfo.of(BUCKET_NAME1).toPb()),
EasyMock.capture(capturedOptions))).andReturn(BUCKET_INFO1.toPb());
EasyMock.replay(storageRpcMock);
Expand Down Expand Up @@ -470,8 +468,7 @@ public void testGetBlobWithOptionsFromBlobId() {

@Test
public void testGetBlobWithSelectedFields() {
Capture<Map<StorageRpc.Option, Object>> capturedOptions =
Capture.<Map<StorageRpc.Option, Object>>newInstance();
Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance();
EasyMock.expect(storageRpcMock.get(EasyMock.eq(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb()),
EasyMock.capture(capturedOptions))).andReturn(BLOB_INFO1.toPb());
EasyMock.replay(storageRpcMock);
Expand All @@ -493,8 +490,7 @@ public void testGetBlobWithSelectedFields() {

@Test
public void testGetBlobWithEmptyFields() {
Capture<Map<StorageRpc.Option, Object>> capturedOptions =
Capture.<Map<StorageRpc.Option, Object>>newInstance();
Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance();
EasyMock.expect(storageRpcMock.get(EasyMock.eq(BlobId.of(BUCKET_NAME1, BLOB_NAME1).toPb()),
EasyMock.capture(capturedOptions))).andReturn(BLOB_INFO1.toPb());
EasyMock.replay(storageRpcMock);
Expand Down Expand Up @@ -555,8 +551,7 @@ public void testListBucketsWithOptions() {
@Test
public void testListBucketsWithSelectedFields() {
String cursor = "cursor";
Capture<Map<StorageRpc.Option, Object>> capturedOptions =
Capture.<Map<StorageRpc.Option, Object>>newInstance();
Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance();
ImmutableList<BucketInfo> bucketList = ImmutableList.of(BUCKET_INFO1, BUCKET_INFO2);
Tuple<String, Iterable<com.google.api.services.storage.model.Bucket>> result =
Tuple.of(cursor, Iterables.transform(bucketList, BucketInfo.TO_PB_FUNCTION));
Expand All @@ -577,8 +572,7 @@ public void testListBucketsWithSelectedFields() {
@Test
public void testListBucketsWithEmptyFields() {
String cursor = "cursor";
Capture<Map<StorageRpc.Option, Object>> capturedOptions =
Capture.<Map<StorageRpc.Option, Object>>newInstance();
Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance();
ImmutableList<BucketInfo> bucketList = ImmutableList.of(BUCKET_INFO1, BUCKET_INFO2);
Tuple<String, Iterable<com.google.api.services.storage.model.Bucket>> result =
Tuple.of(cursor, Iterables.transform(bucketList, BucketInfo.TO_PB_FUNCTION));
Expand Down Expand Up @@ -638,8 +632,7 @@ public void testListBlobsWithOptions() {
@Test
public void testListBlobsWithSelectedFields() {
String cursor = "cursor";
Capture<Map<StorageRpc.Option, Object>> capturedOptions =
Capture.<Map<StorageRpc.Option, Object>>newInstance();
Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance();
ImmutableList<BlobInfo> blobList = ImmutableList.of(BLOB_INFO1, BLOB_INFO2);
Tuple<String, Iterable<com.google.api.services.storage.model.StorageObject>> result =
Tuple.of(cursor, Iterables.transform(blobList, BlobInfo.TO_PB_FUNCTION));
Expand Down Expand Up @@ -668,8 +661,7 @@ public void testListBlobsWithSelectedFields() {
@Test
public void testListBlobsWithEmptyFields() {
String cursor = "cursor";
Capture<Map<StorageRpc.Option, Object>> capturedOptions =
Capture.<Map<StorageRpc.Option, Object>>newInstance();
Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance();
ImmutableList<BlobInfo> blobList = ImmutableList.of(BLOB_INFO1, BLOB_INFO2);
Tuple<String, Iterable<com.google.api.services.storage.model.StorageObject>> result =
Tuple.of(cursor, Iterables.transform(blobList, BlobInfo.TO_PB_FUNCTION));
Expand Down

0 comments on commit 604b1c4

Please sign in to comment.