use of io.pravega.segmentstore.storage.QueueStats in project pravega by pravega.
the class ThrottlerCalculatorTests method testBatching.
/**
* Tests the ability to properly calculate batching-related delays.
*/
@Test
public void testBatching() {
val increment = 0.1;
val queueStats = new AtomicReference<QueueStats>(null);
val tc = ThrottlerCalculator.builder().batchingThrottler(queueStats::get).build();
// Test variance based on Fill Ratio (uncapped).
// Set the initial lastValue to the max, so we verify that we won't exceed this value.
AtomicInteger lastValue = new AtomicInteger(ThrottlerCalculator.MAX_BATCHING_DELAY_MILLIS);
for (double fillRatio = 0.0; fillRatio <= 1.0; fillRatio += increment) {
queueStats.set(new QueueStats(100, fillRatio, ThrottlerCalculator.MAX_BATCHING_DELAY_MILLIS));
val value = tc.getThrottlingDelay().getDurationMillis();
if (fillRatio < increment / 2) {
// This is essentially 0.0, but it's hard to compare precisely against double.
Assert.assertEquals("Expected maximum batching when fill ratio is 0.", lastValue.get(), value);
} else {
if (fillRatio > 1.0 - increment / 2) {
Assert.assertEquals("Expected maximum batching when fill ratio is 1.0.", 0, value);
}
AssertExtensions.assertLessThan("Expecting batching delay to decrease as fill ratio increases: " + fillRatio, lastValue.get(), value);
}
lastValue.set(value);
}
// Test capping at max.
Arrays.stream(new QueueStats[] { new QueueStats(100, 0.0, ThrottlerCalculator.MAX_BATCHING_DELAY_MILLIS + 1), new QueueStats(100, 0.5, ThrottlerCalculator.MAX_BATCHING_DELAY_MILLIS * 10), new QueueStats(100, 0.9, ThrottlerCalculator.MAX_BATCHING_DELAY_MILLIS * 100) }).forEach(qs -> {
queueStats.set(qs);
Assert.assertEquals("Expected batching to be capped.", ThrottlerCalculator.MAX_BATCHING_DELAY_MILLIS, tc.getThrottlingDelay().getDurationMillis());
});
}
Aggregations