Search in sources :

Example 6 with Storage

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

Example 7 with Storage

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

Example 8 with Storage

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

Example 9 with Storage

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));
}
Also used : Blob(com.google.cloud.storage.Blob) Storage(com.google.cloud.storage.Storage) BlobInfo(com.google.cloud.storage.BlobInfo) BlobId(com.google.cloud.storage.BlobId) CopyWriter(com.google.cloud.storage.CopyWriter) Test(org.junit.Test)

Example 10 with Storage

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

Aggregations

Storage (com.google.cloud.storage.Storage)14 Test (org.junit.Test)6 Blob (com.google.cloud.storage.Blob)4 Policy (com.google.cloud.Policy)3 BlobId (com.google.cloud.storage.BlobId)3 BlobInfo (com.google.cloud.storage.BlobInfo)2 StorageOptions (com.google.cloud.storage.StorageOptions)2 Role (com.google.cloud.Role)1 Bucket (com.google.cloud.storage.Bucket)1 CopyWriter (com.google.cloud.storage.CopyWriter)1 IOException (java.io.IOException)1 WritableByteChannel (java.nio.channels.WritableByteChannel)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 Map (java.util.Map)1 Set (java.util.Set)1 Before (org.junit.Before)1