Search in sources :

Example 6 with CopyRequest

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());
}
Also used : StorageRpc(com.google.cloud.storage.spi.v1.StorageRpc) CopyRequest(com.google.cloud.storage.Storage.CopyRequest) Test(org.junit.Test)

Example 7 with CopyRequest

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());
}
Also used : StorageRpc(com.google.cloud.storage.spi.v1.StorageRpc) CopyRequest(com.google.cloud.storage.Storage.CopyRequest) Test(org.junit.Test)

Example 8 with CopyRequest

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());
}
Also used : StorageRpc(com.google.cloud.storage.spi.v1.StorageRpc) CopyRequest(com.google.cloud.storage.Storage.CopyRequest) Test(org.junit.Test)

Aggregations

CopyRequest (com.google.cloud.storage.Storage.CopyRequest)8 StorageRpc (com.google.cloud.storage.spi.v1.StorageRpc)5 Test (org.junit.Test)5 Blob (com.google.cloud.storage.Blob)3 BlobId (com.google.cloud.storage.BlobId)1 CopyWriter (com.google.cloud.storage.CopyWriter)1