Search in sources :

Example 11 with CloudStorageException

use of com.github.ambry.cloud.CloudStorageException in project ambry by linkedin.

the class AzureStorageCompactorTest method testPurgeWithStorageError.

/**
 * Test purgeBlobs with ABS error
 */
@Test
public void testPurgeWithStorageError() throws Exception {
    // Unsuccessful case
    BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_ARCHIVED);
    BlobBatch mockBatch = mock(BlobBatch.class);
    Response<Void> mockResponse = mock(Response.class);
    when(mockResponse.getStatusCode()).thenThrow(ex);
    when(mockBlobBatchClient.getBlobBatch()).thenReturn(mockBatch);
    when(mockBatch.deleteBlob(anyString(), anyString())).thenReturn(mockResponse);
    try {
        AzureCompactionUtil.purgeBlobs(blobMetadataList, azureBlobDataAccessor, azureMetrics, cosmosDataAccessor);
        fail("Expected CloudStorageException");
    } catch (CloudStorageException bex) {
    }
    assertEquals(0, azureMetrics.blobDeletedCount.getCount());
    assertEquals(numBlobsPerQuery, azureMetrics.blobDeleteErrorCount.getCount());
}
Also used : CloudStorageException(com.github.ambry.cloud.CloudStorageException) BlobStorageException(com.azure.storage.blob.models.BlobStorageException) BlobBatch(com.azure.storage.blob.batch.BlobBatch) Test(org.junit.Test)

Example 12 with CloudStorageException

use of com.github.ambry.cloud.CloudStorageException in project ambry by linkedin.

the class AzureStorageCompactorTest method testPurgeWithCosmosBulkDeleteError.

/**
 * Test purgeBlobs with Cosmos bulk delete error
 */
@Test
public void testPurgeWithCosmosBulkDeleteError() throws Exception {
    Exception mockException = new RuntimeException(new DocumentClientException(HttpConstants.StatusCodes.TOO_MANY_REQUESTS));
    doThrow(mockException).when(mockumentClient).executeStoredProcedure(anyString(), any(RequestOptions.class), any());
    try {
        AzureCompactionUtil.purgeBlobs(blobMetadataList, azureBlobDataAccessor, azureMetrics, cosmosDataAccessor);
        fail("Expected CloudStorageException");
    } catch (CloudStorageException bex) {
    }
    assertEquals(0, azureMetrics.blobDeletedCount.getCount());
    assertEquals(numBlobsPerQuery, azureMetrics.blobDeleteErrorCount.getCount());
}
Also used : RequestOptions(com.microsoft.azure.cosmosdb.RequestOptions) CloudStorageException(com.github.ambry.cloud.CloudStorageException) DocumentClientException(com.microsoft.azure.cosmosdb.DocumentClientException) BlobStorageException(com.azure.storage.blob.models.BlobStorageException) CloudStorageException(com.github.ambry.cloud.CloudStorageException) IOException(java.io.IOException) DocumentClientException(com.microsoft.azure.cosmosdb.DocumentClientException) Test(org.junit.Test)

Example 13 with CloudStorageException

use of com.github.ambry.cloud.CloudStorageException in project ambry by linkedin.

the class AzureStorageCompactorTest method testCompactionFailsOnCheckpointReadError.

/**
 * Test compaction on error reading checkpoint.
 */
@Test
public void testCompactionFailsOnCheckpointReadError() throws Exception {
    BlobStorageException ex = mockStorageException(BlobErrorCode.INTERNAL_ERROR);
    when(mockBlockBlobClient.downloadWithResponse(any(), any(), any(), any(), anyBoolean(), any(), any())).thenThrow(ex);
    try {
        azureStorageCompactor.compactPartition(partitionPath);
        fail("Expected compaction to fail");
    } catch (CloudStorageException cse) {
    // expected
    }
}
Also used : CloudStorageException(com.github.ambry.cloud.CloudStorageException) BlobStorageException(com.azure.storage.blob.models.BlobStorageException) Test(org.junit.Test)

Aggregations

CloudStorageException (com.github.ambry.cloud.CloudStorageException)13 IOException (java.io.IOException)7 Test (org.junit.Test)7 BlobStorageException (com.azure.storage.blob.models.BlobStorageException)6 CloudBlobMetadata (com.github.ambry.cloud.CloudBlobMetadata)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 PartitionId (com.github.ambry.clustermap.PartitionId)4 BlobId (com.github.ambry.commons.BlobId)4 DocumentClientException (com.microsoft.azure.cosmosdb.DocumentClientException)4 InputStream (java.io.InputStream)4 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)3 FindResult (com.github.ambry.cloud.FindResult)2 VcrMetrics (com.github.ambry.cloud.VcrMetrics)2 CloudConfig (com.github.ambry.config.CloudConfig)2 RequestOptions (com.microsoft.azure.cosmosdb.RequestOptions)2 AsyncDocumentClient (com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2