Search in sources :

Example 16 with RateWindow

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

the class RateWindowTest method shouldGetMinRateWhenWindowMoves.

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

Example 17 with RateWindow

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

the class RateWindowTest method shouldGetMinRateEvenWhenWindowHasMovedTwiceUnderIt.

@Test
public void shouldGetMinRateEvenWhenWindowHasMovedTwiceUnderIt() {
    //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.getMinRate();
    rateWindow.incrementForTimestamp(timestamp4);
    //When
    long rate = rateWindow.getMinRate();
    //Then
    assertEquals(rate, 0L);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) Test(org.testng.annotations.Test)

Example 18 with RateWindow

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

the class RateWindowTest method shouldAddRatesToSameWindowSlotWithSameTimestamp.

@Test
public void shouldAddRatesToSameWindowSlotWithSameTimestamp() {
    //Given
    RateWindow rateWindow = createRateWindow(1);
    long timestamp1 = getNowTimestamp(SAMPLE_RATE);
    rateWindow.incrementForTimestamp(timestamp1);
    //When
    rateWindow.incrementForTimestamp(timestamp1);
    //Then
    assertEquals(rateWindow.getAverageRate(), 2D);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) Test(org.testng.annotations.Test)

Example 19 with RateWindow

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

the class RateWindowTest method shouldGetMaxRate.

@Test
public void shouldGetMaxRate() {
    //Given
    RateWindow rateWindow = createRateWindow(3);
    long timestamp1 = getNowTimestamp(SAMPLE_RATE);
    long timestamp2 = timestamp1 + SAMPLE_RATE;
    long timestamp3 = timestamp2 + SAMPLE_RATE;
    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.incrementForTimestamp(timestamp3);
    rateWindow.incrementForTimestamp(timestamp3);
    rateWindow.incrementForTimestamp(timestamp3);
    //When
    long rate = rateWindow.getMaxRate();
    //Then
    assertEquals(rate, 6L);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) Test(org.testng.annotations.Test)

Example 20 with RateWindow

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

the class RateWindowTest method shouldUpdatePreviousRate.

@Test
public void shouldUpdatePreviousRate() {
    //Given
    RateWindow rateWindow = createRateWindow(4);
    long timestamp1 = getNowTimestamp(SAMPLE_RATE);
    long timestamp2 = timestamp1 + SAMPLE_RATE;
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp2);
    //When
    rateWindow.incrementForTimestamp(timestamp1);
    //Then
    assertEquals(rateWindow.getMaxRate(), 2L);
}
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