use of com.microsoft.azure.cosmosdb.FeedResponse 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();
}
}
use of com.microsoft.azure.cosmosdb.FeedResponse 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));
}
use of com.microsoft.azure.cosmosdb.FeedResponse 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());
}
Aggregations