Search in sources :

Example 11 with RateWindow

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

the class RateWindowTest method shouldGetMaxRateWhenTimeHasPassedCurrentIndex.

@Test
public void shouldGetMaxRateWhenTimeHasPassedCurrentIndex() {
    //Given
    RateWindow rateWindow = createRateWindow(3);
    long timestamp1 = getNowTimestamp(SAMPLE_RATE);
    long timestamp2 = timestamp1 + SAMPLE_RATE;
    long timestamp3 = timestamp2 + SAMPLE_RATE;
    given(timer.now()).willReturn(timestamp3 + SAMPLE_RATE - 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.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 12 with RateWindow

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

the class RateWindowTest method shouldGetAverageRateWhenTimeIsInLatestIndex.

@Test
public void shouldGetAverageRateWhenTimeIsInLatestIndex() {
    //Given
    RateWindow rateWindow = createRateWindow(2);
    long timestamp1 = getNowTimestamp(SAMPLE_RATE);
    long timestamp2 = timestamp1 + SAMPLE_RATE;
    given(timer.now()).willReturn(timestamp2);
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp2);
    //When
    double rate = rateWindow.getAverageRate();
    //Then
    assertEquals(rate, 0.5D);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) Test(org.testng.annotations.Test)

Example 13 with RateWindow

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

the class RateWindowTest method shouldGetMaxRateEvenWhenWindowHasMovedUnderIt.

@Test
public void shouldGetMaxRateEvenWhenWindowHasMovedUnderIt() {
    //Given
    RateWindow rateWindow = createRateWindow(2);
    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.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 14 with RateWindow

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

the class RateWindowTest method shouldAddRatesToDifferentWindowSlotsWithAnEmptySlotBetween.

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

Example 15 with RateWindow

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

the class RateWindowTest method shouldGetAverageRateWhenTimeHasPassedLatestIndex.

@Test
public void shouldGetAverageRateWhenTimeHasPassedLatestIndex() {
    //Given
    RateWindow rateWindow = createRateWindow(2);
    long timestamp1 = getNowTimestamp(SAMPLE_RATE);
    long timestamp2 = timestamp1 + SAMPLE_RATE;
    given(timer.now()).willReturn(timestamp1 + (SAMPLE_RATE * 2));
    rateWindow.incrementForTimestamp(timestamp1);
    rateWindow.incrementForTimestamp(timestamp2);
    //When
    double rate = rateWindow.getAverageRate();
    //Then
    assertEquals(rate, 0.5D);
}
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