use of org.forgerock.openam.shared.monitoring.RateWindow in project OpenAM by OpenRock.
the class RateWindowTest method shouldGetAverageRateWhenTimeIsJustInLatestIndex.
@Test
public void shouldGetAverageRateWhenTimeIsJustInLatestIndex() {
//Given
RateWindow rateWindow = createRateWindow(2);
long timestamp1 = getNowTimestamp(SAMPLE_RATE);
long timestamp2 = timestamp1 + SAMPLE_RATE;
given(timer.now()).willReturn(timestamp2 + SAMPLE_RATE - 1);
rateWindow.incrementForTimestamp(timestamp1);
rateWindow.incrementForTimestamp(timestamp2);
//When
double rate = rateWindow.getAverageRate();
//Then
assertEquals(rate, 0.5D);
}
use of org.forgerock.openam.shared.monitoring.RateWindow in project OpenAM by OpenRock.
the class RateWindowTest method shouldAddRateToFirstWindowSlot.
@Test
public void shouldAddRateToFirstWindowSlot() {
//Given
RateWindow rateWindow = createRateWindow(1);
long timestamp = getNowTimestamp(SAMPLE_RATE);
//When
rateWindow.incrementForTimestamp(timestamp);
//Then
assertEquals(rateWindow.getAverageRate(), 1D);
}
use of org.forgerock.openam.shared.monitoring.RateWindow in project OpenAM by OpenRock.
the class RateWindowTest method shouldGetMinRateWhenNoRateSet.
@Test
public void shouldGetMinRateWhenNoRateSet() {
//Given
RateWindow rateWindow = createRateWindow(2);
//When
long rate = rateWindow.getMinRate();
//Then
assertEquals(rate, 0L);
}
use of org.forgerock.openam.shared.monitoring.RateWindow in project OpenAM by OpenRock.
the class RateWindowTest method shouldAddRatesToSameWindowSlotWithTimestampsAtEitherEndOfSampleRate.
@Test
public void shouldAddRatesToSameWindowSlotWithTimestampsAtEitherEndOfSampleRate() {
//Given
RateWindow rateWindow = createRateWindow(1);
long timestamp1 = getNowTimestamp(SAMPLE_RATE);
long timestamp2 = timestamp1 + SAMPLE_RATE - 1;
rateWindow.incrementForTimestamp(timestamp1);
//When
rateWindow.incrementForTimestamp(timestamp2);
//Then
assertEquals(rateWindow.getAverageRate(), 2D);
}
use of org.forgerock.openam.shared.monitoring.RateWindow in project OpenAM by OpenRock.
the class RateWindowTest method shouldGetMaxRateWhenWindowMoves.
@Test
public void shouldGetMaxRateWhenWindowMoves() {
//Given
RateWindow rateWindow = createRateWindow(2);
long timestamp1 = getNowTimestamp(SAMPLE_RATE);
long timestamp2 = timestamp1 + SAMPLE_RATE;
long timestamp3 = timestamp2 + 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);
//When
long rate = rateWindow.getMaxRate();
//Then
assertEquals(rate, 3L);
}
Aggregations