Search in sources :

Example 26 with RateWindow

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

the class RateWindowTest method shouldGetMinRateWhenTimeHasPassedCurrentIndex.

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

Example 27 with RateWindow

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

the class ConnectionsMonitorTest method setUp.

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

Example 28 with RateWindow

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

the class ConnectionsMonitorTest method recalculatingRateShouldNotBlockGetRateIfNotModifying.

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

        public void run() {
            monitor.add();
        }
    }).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)

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