Search in sources :

Example 1 with QuotaRequestContext

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);
}
Also used : QuotaRequestContext(com.google.gerrit.server.quota.QuotaRequestContext) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with QuotaRequestContext

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);
}
Also used : OptionalLong(java.util.OptionalLong) QuotaRequestContext(com.google.gerrit.server.quota.QuotaRequestContext) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with QuotaRequestContext

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);
}
Also used : QuotaRequestContext(com.google.gerrit.server.quota.QuotaRequestContext) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with QuotaRequestContext

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"));
}
Also used : QuotaRequestContext(com.google.gerrit.server.quota.QuotaRequestContext) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with QuotaRequestContext

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"));
}
Also used : QuotaRequestContext(com.google.gerrit.server.quota.QuotaRequestContext) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)19 QuotaRequestContext (com.google.gerrit.server.quota.QuotaRequestContext)19 Test (org.junit.Test)19 QuotaResponse (com.google.gerrit.server.quota.QuotaResponse)6 Change (com.google.gerrit.entities.Change)2 QuotaException (com.google.gerrit.server.quota.QuotaException)2 OptionalLong (java.util.OptionalLong)2