Search in sources :

Example 21 with Document

use of com.microsoft.azure.cosmosdb.Document in project ambry by linkedin.

the class AzureCloudDestinationTest method testQueryMetadata.

/**
 * Test metadata query for different input count.
 * @param numBlobs the number of blobs to query.
 * @param expectedQueries the number of internal queries made after batching.
 * @throws Exception
 */
private void testQueryMetadata(int numBlobs, int expectedQueries) throws Exception {
    // Reset metrics
    azureMetrics = new AzureMetrics(new MetricRegistry());
    try {
        azureDest = new AzureCloudDestination(mockServiceClient, mockBlobBatchClient, mockumentClient, "foo", "bar", clusterName, azureMetrics, defaultAzureReplicationFeedType, clusterMap, false, configProps);
        List<BlobId> blobIdList = new ArrayList<>();
        List<Document> docList = new ArrayList<>();
        for (int j = 0; j < numBlobs; j++) {
            BlobId blobId = generateBlobId();
            blobIdList.add(blobId);
            CloudBlobMetadata inputMetadata = new CloudBlobMetadata(blobId, creationTime, Utils.Infinite_Time, blobSize, CloudBlobMetadata.EncryptionOrigin.NONE);
            docList.add(AzureTestUtils.createDocumentFromCloudBlobMetadata(inputMetadata));
        }
        Observable<FeedResponse<Document>> mockResponse = mock(Observable.class);
        mockObservableForQuery(docList, mockResponse);
        when(mockumentClient.queryDocuments(anyString(), any(SqlQuerySpec.class), any(FeedOptions.class))).thenReturn(mockResponse);
        Set<BlobId> blobIdSet = new HashSet<>(blobIdList);
        assertEquals(blobIdList.size(), blobIdSet.size());
        Map<String, CloudBlobMetadata> metadataMap = azureDest.getBlobMetadata(blobIdList);
        for (BlobId blobId : blobIdList) {
            assertEquals("Unexpected id in metadata", blobId.getID(), metadataMap.get(blobId.getID()).getId());
        }
        assertEquals(expectedQueries, azureMetrics.documentQueryCount.getCount());
        assertEquals(expectedQueries, azureMetrics.missingKeysQueryTime.getCount());
    } finally {
        azureDest.close();
    }
}
Also used : CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) MetricRegistry(com.codahale.metrics.MetricRegistry) ArrayList(java.util.ArrayList) FeedResponse(com.microsoft.azure.cosmosdb.FeedResponse) Document(com.microsoft.azure.cosmosdb.Document) SqlQuerySpec(com.microsoft.azure.cosmosdb.SqlQuerySpec) FeedOptions(com.microsoft.azure.cosmosdb.FeedOptions) BlobId(com.github.ambry.commons.BlobId) HashSet(java.util.HashSet)

Example 22 with Document

use of com.microsoft.azure.cosmosdb.Document in project ambry by linkedin.

the class AzureStorageCompactorTest method testCompactionCheckpoints.

/**
 * Test compaction checkpoint behavior
 */
@Test
public void testCompactionCheckpoints() throws Exception {
    AzureStorageCompactor compactorSpy = spy(azureStorageCompactor);
    doReturn(true).when(compactorSpy).updateCompactionProgress(anyString(), anyString(), anyLong());
    String fieldName = CloudBlobMetadata.FIELD_DELETION_TIME;
    long startTime = testTime - TimeUnit.DAYS.toMillis(numBlobsPerQuery);
    long endTime = testTime;
    // When dead blobs query returns results, progress gets updated to last record's dead time
    List<Document> docList = new ArrayList<>();
    long lastDeadTime = 0;
    for (int j = 0; j < numBlobsPerQuery; j++) {
        BlobId blobId = generateBlobId();
        CloudBlobMetadata inputMetadata = new CloudBlobMetadata(blobId, testTime, Utils.Infinite_Time, blobSize, CloudBlobMetadata.EncryptionOrigin.NONE);
        lastDeadTime = startTime + TimeUnit.HOURS.toMillis(j);
        inputMetadata.setDeletionTime(lastDeadTime);
        blobMetadataList.add(inputMetadata);
        docList.add(AzureTestUtils.createDocumentFromCloudBlobMetadata(inputMetadata));
    }
    Observable<FeedResponse<Document>> mockResponse = mock(Observable.class);
    mockObservableForQuery(docList, mockResponse);
    when(mockumentClient.queryDocuments(anyString(), any(SqlQuerySpec.class), any(FeedOptions.class))).thenReturn(mockResponse);
    compactorSpy.compactPartition(partitionPath, fieldName, startTime, endTime);
    verify(compactorSpy, atLeastOnce()).updateCompactionProgress(eq(partitionPath), eq(fieldName), eq(lastDeadTime));
    verify(compactorSpy, never()).updateCompactionProgress(eq(partitionPath), eq(fieldName), eq(endTime));
    // When dead blobs query returns no results, progress gets updated to queryEndtime
    mockResponse = getMockedObservableForQueryWithNoResults();
    when(mockumentClient.queryDocuments(anyString(), any(SqlQuerySpec.class), any(FeedOptions.class))).thenReturn(mockResponse);
    compactorSpy.compactPartition(partitionPath, fieldName, startTime, endTime);
    verify(compactorSpy).updateCompactionProgress(eq(partitionPath), eq(fieldName), eq(endTime));
}
Also used : CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) ArrayList(java.util.ArrayList) FeedResponse(com.microsoft.azure.cosmosdb.FeedResponse) Document(com.microsoft.azure.cosmosdb.Document) SqlQuerySpec(com.microsoft.azure.cosmosdb.SqlQuerySpec) FeedOptions(com.microsoft.azure.cosmosdb.FeedOptions) BlobId(com.github.ambry.commons.BlobId) Test(org.junit.Test)

Example 23 with Document

use of com.microsoft.azure.cosmosdb.Document in project ambry by linkedin.

the class CosmosDataAccessorTest method testQueryNormal.

/**
 * Test query metadata.
 */
@Test
public void testQueryNormal() throws Exception {
    Observable<FeedResponse<Document>> mockResponse = mock(Observable.class);
    List<Document> docList = Collections.singletonList(AzureTestUtils.createDocumentFromCloudBlobMetadata(blobMetadata));
    mockObservableForQuery(docList, mockResponse);
    when(mockumentClient.queryDocuments(anyString(), any(SqlQuerySpec.class), any(FeedOptions.class))).thenReturn(mockResponse);
    List<CloudBlobMetadata> metadataList = doQueryMetadata();
    assertEquals("Expected single entry", 1, metadataList.size());
    CloudBlobMetadata outputMetadata = metadataList.get(0);
    assertEquals("Returned metadata does not match original", blobMetadata, outputMetadata);
    assertEquals(1, azureMetrics.documentQueryCount.getCount());
    assertEquals(1, azureMetrics.missingKeysQueryTime.getCount());
}
Also used : SqlQuerySpec(com.microsoft.azure.cosmosdb.SqlQuerySpec) ChangeFeedOptions(com.microsoft.azure.cosmosdb.ChangeFeedOptions) FeedOptions(com.microsoft.azure.cosmosdb.FeedOptions) CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) FeedResponse(com.microsoft.azure.cosmosdb.FeedResponse) Document(com.microsoft.azure.cosmosdb.Document) Test(org.junit.Test)

Aggregations

Document (com.microsoft.azure.cosmosdb.Document)23 FeedResponse (com.microsoft.azure.cosmosdb.FeedResponse)15 CloudBlobMetadata (com.github.ambry.cloud.CloudBlobMetadata)14 FeedOptions (com.microsoft.azure.cosmosdb.FeedOptions)14 SqlQuerySpec (com.microsoft.azure.cosmosdb.SqlQuerySpec)13 DocumentClientException (com.microsoft.azure.cosmosdb.DocumentClientException)10 ArrayList (java.util.ArrayList)10 BlobId (com.github.ambry.commons.BlobId)9 ChangeFeedOptions (com.microsoft.azure.cosmosdb.ChangeFeedOptions)9 PartitionKey (com.microsoft.azure.cosmosdb.PartitionKey)7 RequestOptions (com.microsoft.azure.cosmosdb.RequestOptions)7 SqlParameter (com.microsoft.azure.cosmosdb.SqlParameter)5 SqlParameterCollection (com.microsoft.azure.cosmosdb.SqlParameterCollection)5 CloudStorageException (com.github.ambry.cloud.CloudStorageException)4 VcrMetrics (com.github.ambry.cloud.VcrMetrics)4 ResourceResponse (com.microsoft.azure.cosmosdb.ResourceResponse)4 StoredProcedureResponse (com.microsoft.azure.cosmosdb.StoredProcedureResponse)4 AsyncDocumentClient (com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4