Search in sources :

Example 1 with QueueStats

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());
    });
}
Also used : lombok.val(lombok.val) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) QueueStats(io.pravega.segmentstore.storage.QueueStats) Test(org.junit.Test)

Aggregations

QueueStats (io.pravega.segmentstore.storage.QueueStats)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 lombok.val (lombok.val)1 Test (org.junit.Test)1