use of com.google.cloud.storage.Storage in project google-cloud-java by GoogleCloudPlatform.
the class RemoteStorageHelperTest method testForceDeleteFail.
@Test
public void testForceDeleteFail() throws InterruptedException, ExecutionException {
Storage storageMock = EasyMock.createMock(Storage.class);
EasyMock.expect(blob1.getBlobId()).andReturn(BLOB_ID1);
EasyMock.expect(storageMock.delete(BLOB_ID1)).andReturn(true);
EasyMock.expect(blob2.getBlobId()).andReturn(BLOB_ID2);
EasyMock.expect(storageMock.delete(BLOB_ID2)).andReturn(true);
EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true))).andReturn(blobPage);
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION);
EasyMock.replay(storageMock, blob1, blob2);
thrown.expect(ExecutionException.class);
try {
RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 5, TimeUnit.SECONDS);
} finally {
EasyMock.verify(storageMock);
}
}
use of com.google.cloud.storage.Storage in project google-cloud-java by GoogleCloudPlatform.
the class RemoteStorageHelperTest method testForceDeleteTimeout.
@Test
public void testForceDeleteTimeout() throws InterruptedException, ExecutionException {
Storage storageMock = EasyMock.createMock(Storage.class);
EasyMock.expect(blob1.getBlobId()).andReturn(BLOB_ID1).anyTimes();
EasyMock.expect(storageMock.delete(BLOB_ID1)).andReturn(true).anyTimes();
EasyMock.expect(blob2.getBlobId()).andReturn(BLOB_ID2).anyTimes();
EasyMock.expect(storageMock.delete(BLOB_ID2)).andReturn(true).anyTimes();
EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true))).andReturn(blobPage).anyTimes();
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(RETRYABLE_EXCEPTION).anyTimes();
EasyMock.replay(storageMock, blob1, blob2);
assertFalse(RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 50, TimeUnit.MICROSECONDS));
EasyMock.verify(storageMock);
}
use of com.google.cloud.storage.Storage in project google-cloud-java by GoogleCloudPlatform.
the class RemoteStorageHelperTest method testForceDelete.
@Test
public void testForceDelete() throws InterruptedException, ExecutionException {
Storage storageMock = EasyMock.createMock(Storage.class);
EasyMock.expect(blob1.getBlobId()).andReturn(BLOB_ID1);
EasyMock.expect(storageMock.delete(BLOB_ID1)).andReturn(true);
EasyMock.expect(blob2.getBlobId()).andReturn(BLOB_ID2);
EasyMock.expect(storageMock.delete(BLOB_ID2)).andReturn(true);
EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true))).andReturn(blobPage);
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andReturn(true);
EasyMock.replay(storageMock, blob1, blob2);
assertTrue(RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME, 5, TimeUnit.SECONDS));
EasyMock.verify(storageMock, blob1, blob2);
}
use of com.google.cloud.storage.Storage in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testCopyBlobUpdateStorageClass.
@Test
public void testCopyBlobUpdateStorageClass() {
String sourceBlobName = "test-copy-blob-update-storage-class-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
BlobInfo sourceInfo = BlobInfo.newBuilder(source).setStorageClass(StorageClass.STANDARD).build();
Blob remoteSourceBlob = storage.create(sourceInfo, BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob);
assertEquals(StorageClass.STANDARD, remoteSourceBlob.getStorageClass());
String targetBlobName = "test-copy-blob-update-storage-class-target";
BlobInfo targetInfo = BlobInfo.newBuilder(BUCKET, targetBlobName).setStorageClass(StorageClass.COLDLINE).build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, targetInfo);
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(StorageClass.COLDLINE, copyWriter.getResult().getStorageClass());
assertTrue(copyWriter.isDone());
assertTrue(remoteSourceBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
use of com.google.cloud.storage.Storage in project google-cloud-java by GoogleCloudPlatform.
the class RemoteStorageHelperTest method testForceDeleteNoTimeout.
@Test
public void testForceDeleteNoTimeout() {
Storage storageMock = EasyMock.createMock(Storage.class);
EasyMock.expect(blob1.getBlobId()).andReturn(BLOB_ID1);
EasyMock.expect(storageMock.delete(BLOB_ID1)).andReturn(true);
EasyMock.expect(blob2.getBlobId()).andReturn(BLOB_ID2);
EasyMock.expect(storageMock.delete(BLOB_ID2)).andReturn(true);
EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true))).andReturn(blobPage);
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andReturn(true);
EasyMock.replay(storageMock, blob1, blob2);
RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME);
EasyMock.verify(storageMock);
}
Aggregations