Ejemplo n.º 1
0
  @Test
  public void shouldReturnParameters_onGet() {
    // Given
    final int capacity = 1 + Randoms.randomInt(50);
    final long tokenDelayMillis = 10 + Randoms.randomInt(5000);
    rateLimiter = new RateLimiter(capacity, tokenDelayMillis);

    // When
    final int returnedCapacity = rateLimiter.getBucketCapacity();
    final long returnedTokenDelayMillis = rateLimiter.getTokenReplacementDelayMillis();

    // Then
    assertEquals(capacity, returnedCapacity);
    assertEquals(tokenDelayMillis, returnedTokenDelayMillis);
  }
Ejemplo n.º 2
0
  @Test
  public void shouldNotCreateRateLimiter_withNegativeDelay() {
    // Given
    final int capacity = 1 + Randoms.randomInt(50);
    final long tokenDelayMillis = -1 - Randoms.randomInt(5000);

    // When
    IllegalArgumentException actualException = null;
    try {
      new RateLimiter(capacity, tokenDelayMillis);
    } catch (final IllegalArgumentException e) {
      actualException = e;
    }

    // Then
    assertNotNull(actualException);
  }
  @Test
  public void shouldNotApplyFlowControl_onStatusSubresourceRequest() throws Exception {
    // Given
    setUpRequestPath("http://www.example.com/status/" + Randoms.randomString());

    // When
    flowControlledRequestFilter.filter(mockContainerRequestContext);

    // Then
    verifyZeroInteractions(mockrestAdapterStartLatch, mockRateLimiter);
  }
Ejemplo n.º 4
0
  @Test
  public void shouldNotSetParameters_withZeroCapacity() {
    // Given
    rateLimiter = new RateLimiter(10, 1000);
    final int capacity = 0;
    final long tokenDelayMillis = 10 + Randoms.randomInt(5000);

    // When
    IllegalArgumentException actualException = null;
    try {
      rateLimiter.setParameters(capacity, tokenDelayMillis);
    } catch (final IllegalArgumentException e) {
      actualException = e;
    }

    // Then
    assertNotNull(actualException);
  }