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);
}
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);
}
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);
}
Aggregations