Search in sources :

Example 1 with RateWindow

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

the class OperationMonitorTest method setUp.

@BeforeMethod
public void setUp() {
    RateTimer timer = mock(RateTimer.class);
    rateWindow = mock(RateWindow.class);
    operationMonitor = new OperationMonitor(timer, rateWindow);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) RateTimer(org.forgerock.openam.shared.monitoring.RateTimer) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with RateWindow

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

the class OperationMonitorTest method recalculatingRateShouldNotBlockGetRateIfNotModifying.

@Test
public void recalculatingRateShouldNotBlockGetRateIfNotModifying() {
    //Given
    RateTimer timer = new TestCurrentMillis();
    RateWindow rateWindow = new RateWindow(timer, 10, 1000L);
    final OperationMonitor monitor = new OperationMonitor(timer, rateWindow);
    //When
    new Thread(new Runnable() {

        public void run() {
            monitor.increment();
        }
    }).start();
    double rate = monitor.getAverageRate();
    //Then
    assertEquals(rate, 0D);
}
Also used : RateWindow(org.forgerock.openam.shared.monitoring.RateWindow) TestCurrentMillis(org.forgerock.openam.cts.monitoring.TestCurrentMillis) RateTimer(org.forgerock.openam.shared.monitoring.RateTimer) Test(org.testng.annotations.Test)

Example 3 with RateWindow

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

the class RateWindowTest method shouldAddRatesToDifferentWindowSlots.

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

Example 4 with RateWindow

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

the class RateWindowTest method shouldNotUpdatePastRateIfBeforeWindowStart.

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

Example 5 with RateWindow

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

the class RateWindowTest method shouldGetMinRate.

@Test
public void shouldGetMinRate() {
    //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);
    //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