Search in sources :

Example 6 with RateWindow

use of org.forgerock.openam.shared.monitoring.RateWindow in project OpenAM by OpenRock.

the class RateWindowTest method shouldUpdatePreviousPreviousRate.

@Test
public void shouldUpdatePreviousPreviousRate() {
    //Given
    RateWindow rateWindow = createRateWindow(4);
    long timestamp1 = getNowTimestamp(SAMPLE_RATE);
    long timestamp2 = timestamp1 + SAMPLE_RATE;
    long timestamp3 = timestamp2 + SAMPLE_RATE;
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp2);
    rateWindow.incrementForTimestamp(timestamp3);
    //When
    rateWindow.incrementForTimestamp(timestamp1);
    //Then
    assertEquals(rateWindow.getMaxRate(), 2L);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) Test(org.testng.annotations.Test)

Example 7 with RateWindow

use of org.forgerock.openam.shared.monitoring.RateWindow in project OpenAM by OpenRock.

the class RateWindowTest method shouldGetMaxRateWhenNoRateSet.

@Test
public void shouldGetMaxRateWhenNoRateSet() {
    //Given
    RateWindow rateWindow = createRateWindow(2);
    //When
    long rate = rateWindow.getMaxRate();
    //Then
    assertEquals(rate, 0L);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) Test(org.testng.annotations.Test)

Example 8 with RateWindow

use of org.forgerock.openam.shared.monitoring.RateWindow in project OpenAM by OpenRock.

the class RateWindowTest method shouldGetMaxRateEvenWhenWindowHasMovedTwiceUnderIt.

@Test
public void shouldGetMaxRateEvenWhenWindowHasMovedTwiceUnderIt() {
    //Given
    RateWindow rateWindow = createRateWindow(4);
    long timestamp1 = getNowTimestamp(SAMPLE_RATE);
    long timestamp2 = timestamp1 + SAMPLE_RATE;
    long timestamp3 = timestamp2 + SAMPLE_RATE;
    long timestamp4 = timestamp3 + (SAMPLE_RATE * 2);
    given(timer.now()).willReturn(timestamp3 + 1);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp2);
    rateWindow.incrementForTimestamp(timestamp3);
    rateWindow.incrementForTimestamp(timestamp3);
    rateWindow.incrementForTimestamp(timestamp3);
    rateWindow.getMaxRate();
    rateWindow.incrementForTimestamp(timestamp4);
    //When
    long rate = rateWindow.getMaxRate();
    //Then
    assertEquals(rate, 3L);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) Test(org.testng.annotations.Test)

Example 9 with RateWindow

use of org.forgerock.openam.shared.monitoring.RateWindow in project OpenAM by OpenRock.

the class RateWindowTest method windowShouldBeExtendedWhenCalculatingMaxRate.

@Test
public void windowShouldBeExtendedWhenCalculatingMaxRate() {
    RateWindow rateWindow = createRateWindow(2);
    long timestamp1 = getNowTimestamp(SAMPLE_RATE);
    long timestamp2 = timestamp1 + SAMPLE_RATE;
    long timestamp3 = timestamp2 + SAMPLE_RATE;
    long timestamp4 = timestamp3 + (SAMPLE_RATE * 2);
    given(timer.now()).willReturn(timestamp1);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp1);
    given(timer.now()).willReturn(timestamp2);
    rateWindow.incrementForTimestamp(timestamp2);
    assertThat(rateWindow.getMaxRate()).isEqualTo(3);
    given(timer.now()).willReturn(timestamp3);
    assertThat(rateWindow.getMaxRate()).isEqualTo(1);
    given(timer.now()).willReturn(timestamp4);
    assertThat(rateWindow.getMaxRate()).isEqualTo(0);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) Test(org.testng.annotations.Test)

Example 10 with RateWindow

use of org.forgerock.openam.shared.monitoring.RateWindow in project OpenAM by OpenRock.

the class RateWindowTest method shouldGetMinRateEvenWhenWindowHasMovedUnderIt.

@Test
public void shouldGetMinRateEvenWhenWindowHasMovedUnderIt() {
    //Given
    RateWindow rateWindow = createRateWindow(4);
    long timestamp1 = getNowTimestamp(SAMPLE_RATE);
    long timestamp2 = timestamp1 + SAMPLE_RATE;
    long timestamp3 = timestamp2 + SAMPLE_RATE;
    long timestamp4 = timestamp3 + SAMPLE_RATE;
    given(timer.now()).willReturn(timestamp3 + 1);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp2);
    rateWindow.incrementForTimestamp(timestamp3);
    rateWindow.incrementForTimestamp(timestamp3);
    rateWindow.incrementForTimestamp(timestamp3);
    rateWindow.getMinRate();
    rateWindow.incrementForTimestamp(timestamp4);
    //When
    long rate = rateWindow.getMinRate();
    //Then
    assertEquals(rate, 1L);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) Test(org.testng.annotations.Test)

Aggregations

RateWindow (org.forgerock.openam.shared.monitoring.RateWindow)28 Test (org.testng.annotations.Test)26 RateTimer (org.forgerock.openam.shared.monitoring.RateTimer)4 TestCurrentMillis (org.forgerock.openam.cts.monitoring.TestCurrentMillis)2 BeforeMethod (org.testng.annotations.BeforeMethod)2