use of com.github.ambry.quota.QuotaException in project ambry by linkedin.
the class OperationQuotaChargerTest method testCharge.
@Test
public void testCharge() throws Exception {
// charge should return true if quotaChargeCallback is null.
OperationQuotaCharger operationQuotaCharger = new OperationQuotaCharger(null, BLOBID, "GetOperation");
Assert.assertTrue("charge should return true if quotaChargeCallback is null.", operationQuotaCharger.charge());
QuotaChargeCallback quotaChargeCallback = Mockito.mock(QuotaChargeCallback.class);
operationQuotaCharger = new OperationQuotaCharger(quotaChargeCallback, BLOBID, "GetOperation");
// charge should return false if quotaChargeCallback throws exception and isCharged is false.
Mockito.doThrow(new QuotaException("too many requests", new RouterException("", RouterErrorCode.TooManyRequests), true)).when(quotaChargeCallback).charge();
Assert.assertFalse("charge should return true if quotaChargeCallback throws exception and isCharged is false.", operationQuotaCharger.charge());
Mockito.verify(quotaChargeCallback, Mockito.times(1)).charge();
// charge should return true if quotaChargeCallback.charge goes through.
Mockito.doNothing().when(quotaChargeCallback).charge();
Assert.assertTrue("charge should return true if quotaChargeCallback.charge goes through.", operationQuotaCharger.charge());
Mockito.verify(quotaChargeCallback, Mockito.times(2)).charge();
// Once isCharged is true, charge should never call quotaChargeCallback.charge.
Mockito.doNothing().when(quotaChargeCallback).charge();
Assert.assertTrue("Once isCharged is true, charge should never call quotaChargeCallback.charge.", operationQuotaCharger.charge());
Mockito.verify(quotaChargeCallback, Mockito.times(2)).charge();
}
Aggregations