use of com.google.cloud.storage.Storage.CopyRequest in project google-cloud-java by GoogleCloudPlatform.
the class StorageImplTest method testCopyWithOptions.
@Test
public void testCopyWithOptions() {
CopyRequest request = Storage.CopyRequest.newBuilder().setSource(BLOB_INFO2.getBlobId()).setSourceOptions(BLOB_SOURCE_GENERATION, BLOB_SOURCE_METAGENERATION).setTarget(BLOB_INFO1, BLOB_TARGET_GENERATION, BLOB_TARGET_METAGENERATION).build();
StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.getSource().toPb(), BLOB_SOURCE_OPTIONS_COPY, true, request.getTarget().toPb(), BLOB_TARGET_OPTIONS_COMPOSE, null);
StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L, false, "token", 21L);
EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse);
EasyMock.replay(storageRpcMock);
initializeService();
CopyWriter writer = storage.copy(request);
assertEquals(42L, writer.getBlobSize());
assertEquals(21L, writer.getTotalBytesCopied());
assertTrue(!writer.isDone());
}
use of com.google.cloud.storage.Storage.CopyRequest in project google-cloud-java by GoogleCloudPlatform.
the class StorageImplTest method testCopy.
@Test
public void testCopy() {
CopyRequest request = Storage.CopyRequest.of(BLOB_INFO1.getBlobId(), BLOB_INFO2.getBlobId());
StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.getSource().toPb(), EMPTY_RPC_OPTIONS, false, BLOB_INFO2.toPb(), EMPTY_RPC_OPTIONS, null);
StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L, false, "token", 21L);
EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse);
EasyMock.replay(storageRpcMock);
initializeService();
CopyWriter writer = storage.copy(request);
assertEquals(42L, writer.getBlobSize());
assertEquals(21L, writer.getTotalBytesCopied());
assertTrue(!writer.isDone());
}
use of com.google.cloud.storage.Storage.CopyRequest in project google-cloud-java by GoogleCloudPlatform.
the class StorageImplTest method testCopyMultipleRequests.
@Test
public void testCopyMultipleRequests() {
CopyRequest request = Storage.CopyRequest.of(BLOB_INFO1.getBlobId(), BLOB_INFO2.getBlobId());
StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.getSource().toPb(), EMPTY_RPC_OPTIONS, false, BLOB_INFO2.toPb(), EMPTY_RPC_OPTIONS, null);
StorageRpc.RewriteResponse rpcResponse1 = new StorageRpc.RewriteResponse(rpcRequest, null, 42L, false, "token", 21L);
StorageRpc.RewriteResponse rpcResponse2 = new StorageRpc.RewriteResponse(rpcRequest, BLOB_INFO1.toPb(), 42L, true, "token", 42L);
EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse1);
EasyMock.expect(storageRpcMock.continueRewrite(rpcResponse1)).andReturn(rpcResponse2);
EasyMock.replay(storageRpcMock);
initializeService();
CopyWriter writer = storage.copy(request);
assertEquals(42L, writer.getBlobSize());
assertEquals(21L, writer.getTotalBytesCopied());
assertTrue(!writer.isDone());
assertEquals(expectedBlob1, writer.getResult());
assertTrue(writer.isDone());
assertEquals(42L, writer.getTotalBytesCopied());
assertEquals(42L, writer.getBlobSize());
}
Aggregations