use of com.google.gerrit.server.quota.QuotaRequestContext in project gerrit by GerritCodeReview.
the class MultipleQuotaPluginsIT method refillsOnError.
@Test
public void refillsOnError() {
QuotaRequestContext ctx = QuotaRequestContext.builder().user(identifiedAdmin).build();
when(quotaEnforcerA.requestTokens("testGroup", ctx, 1)).thenReturn(QuotaResponse.ok());
when(quotaEnforcerB.requestTokens("testGroup", ctx, 1)).thenReturn(QuotaResponse.error("fail"));
assertThat(quotaBackend.user(identifiedAdmin).requestToken("testGroup")).isEqualTo(QuotaResponse.Aggregated.create(ImmutableList.of(QuotaResponse.ok(), QuotaResponse.error("fail"))));
verify(quotaEnforcerA).requestTokens("testGroup", ctx, 1);
verify(quotaEnforcerB).requestTokens("testGroup", ctx, 1);
verify(quotaEnforcerA).refill("testGroup", ctx, 1);
}
use of com.google.gerrit.server.quota.QuotaRequestContext in project gerrit by GerritCodeReview.
the class MultipleQuotaPluginsIT method minimumAvailableTokens.
@Test
public void minimumAvailableTokens() {
QuotaRequestContext ctx = QuotaRequestContext.builder().user(identifiedAdmin).build();
when(quotaEnforcerA.availableTokens("testGroup", ctx)).thenReturn(QuotaResponse.ok(20L));
when(quotaEnforcerB.availableTokens("testGroup", ctx)).thenReturn(QuotaResponse.ok(10L));
OptionalLong tokens = quotaBackend.user(identifiedAdmin).availableTokens("testGroup").availableTokens();
assertThat(tokens).isPresent();
assertThat(tokens.getAsLong()).isEqualTo(10L);
verify(quotaEnforcerA).availableTokens("testGroup", ctx);
verify(quotaEnforcerB).availableTokens("testGroup", ctx);
}
use of com.google.gerrit.server.quota.QuotaRequestContext in project gerrit by GerritCodeReview.
the class MultipleQuotaPluginsIT method refillsOnException.
@Test
public void refillsOnException() {
NullPointerException exception = new NullPointerException();
QuotaRequestContext ctx = QuotaRequestContext.builder().user(identifiedAdmin).build();
when(quotaEnforcerA.requestTokens("testGroup", ctx, 1)).thenReturn(QuotaResponse.ok());
when(quotaEnforcerB.requestTokens("testGroup", ctx, 1)).thenThrow(exception);
NullPointerException thrown = assertThrows(NullPointerException.class, () -> quotaBackend.user(identifiedAdmin).requestToken("testGroup"));
assertThat(thrown).isEqualTo(exception);
verify(quotaEnforcerA).requestTokens("testGroup", ctx, 1);
verify(quotaEnforcerB).requestTokens("testGroup", ctx, 1);
verify(quotaEnforcerA).refill("testGroup", ctx, 1);
}
use of com.google.gerrit.server.quota.QuotaRequestContext in project gerrit by GerritCodeReview.
the class DefaultQuotaBackendIT method requestTokenPluginThrowsAndRethrows.
@Test
public void requestTokenPluginThrowsAndRethrows() {
QuotaRequestContext ctx = QuotaRequestContext.builder().user(identifiedAdmin).build();
when(quotaEnforcer.requestTokens("testGroup", ctx, 1)).thenThrow(new NullPointerException());
assertThrows(NullPointerException.class, () -> quotaBackend.user(identifiedAdmin).requestToken("testGroup"));
}
use of com.google.gerrit.server.quota.QuotaRequestContext in project gerrit by GerritCodeReview.
the class DefaultQuotaBackendIT method availableTokensPluginThrowsAndRethrows.
@Test
public void availableTokensPluginThrowsAndRethrows() {
QuotaRequestContext ctx = QuotaRequestContext.builder().user(identifiedAdmin).build();
when(quotaEnforcer.availableTokens("testGroup", ctx)).thenThrow(new NullPointerException());
assertThrows(NullPointerException.class, () -> quotaBackend.user(identifiedAdmin).availableTokens("testGroup"));
}
Aggregations