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