use of com.github.ambry.quota.QuotaMetrics in project ambry by linkedin.
the class NonBlockingRouterQuotaCallbackTest method testRouterWithDefaultQuotaCallback.
/**
* Test default {@link QuotaChargeCallback} doesn't charge anything and doesn't error out when throttling is disabled.
*/
@Test
public void testRouterWithDefaultQuotaCallback() throws Exception {
try {
setRouter();
assertExpectedThreadCounts(2, 1);
AtomicInteger listenerCalledCount = new AtomicInteger(0);
QuotaConfig quotaConfig = new QuotaConfig(new VerifiableProperties(new Properties()));
QuotaManager quotaManager = new ChargeTesterQuotaManager(quotaConfig, new SimpleQuotaRecommendationMergePolicy(quotaConfig), accountService, null, new QuotaMetrics(new MetricRegistry()), listenerCalledCount);
QuotaChargeCallback quotaChargeCallback = QuotaUtils.buildQuotaChargeCallback(null, quotaManager, true);
int blobSize = 3000;
setOperationParams(blobSize, TTL_SECS);
String compositeBlobId = router.putBlob(putBlobProperties, putUserMetadata, putChannel, PutBlobOptions.DEFAULT, null, quotaChargeCallback).get();
assertEquals(0, listenerCalledCount.get());
RetainingAsyncWritableChannel retainingAsyncWritableChannel = new RetainingAsyncWritableChannel();
router.getBlob(compositeBlobId, new GetBlobOptionsBuilder().build(), null, quotaChargeCallback).get().getBlobDataChannel().readInto(retainingAsyncWritableChannel, null).get();
// read out all the chunks.
retainingAsyncWritableChannel.consumeContentAsInputStream().close();
assertEquals(0, listenerCalledCount.get());
} finally {
router.close();
assertExpectedThreadCounts(0, 0);
// submission after closing should return a future that is already done.
assertClosed();
}
}
Aggregations