Search in sources :

Example 11 with TestingTicker

use of io.airlift.testing.TestingTicker in project airlift by airlift.

the class TestDecayCounter method testAddAfterRescale.

@Test
public void testAddAfterRescale() {
    TestingTicker ticker = new TestingTicker();
    DecayCounter counter = new DecayCounter(ExponentialDecay.oneMinute(), ticker);
    counter.add(1);
    ticker.increment(1, TimeUnit.MINUTES);
    counter.add(2);
    double expected = 2 + 1 / Math.E;
    assertTrue(Math.abs(counter.getCount() - expected) < 1e-9);
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Test(org.testng.annotations.Test)

Example 12 with TestingTicker

use of io.airlift.testing.TestingTicker in project airlift by airlift.

the class TestDecayTDigest method testDecayBelowThreshold.

@Test
public void testDecayBelowThreshold() {
    TestingTicker ticker = new TestingTicker();
    double decayFactor = 0.1;
    DecayTDigest digest = new DecayTDigest(100, decayFactor, ticker);
    digest.add(1);
    // incrementing time by this amount should cause the weight of the existing value to become "zero"
    ticker.increment((long) Math.ceil(Math.log(1 / ZERO_WEIGHT_THRESHOLD) / decayFactor), TimeUnit.SECONDS);
    assertEquals(digest.getCount(), 0.0);
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Test(org.testng.annotations.Test)

Example 13 with TestingTicker

use of io.airlift.testing.TestingTicker in project airlift by airlift.

the class TestDecayTDigest method testRescaleMinMax.

@Test
public void testRescaleMinMax() {
    TestingTicker ticker = new TestingTicker();
    DecayTDigest digest = new DecayTDigest(100, 0.001, ticker);
    digest.add(5);
    digest.add(1);
    assertEquals(digest.getMin(), 1.0);
    assertEquals(digest.getMax(), 5.0);
    ticker.increment(51, TimeUnit.SECONDS);
    assertEquals(digest.getMin(), 1.0);
    assertEquals(digest.getMax(), 5.0);
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Test(org.testng.annotations.Test)

Example 14 with TestingTicker

use of io.airlift.testing.TestingTicker in project airlift by airlift.

the class TestQuantileDigest method testMinMaxWithDecay.

@Test
public void testMinMaxWithDecay() throws Exception {
    TestingTicker ticker = new TestingTicker();
    QuantileDigest digest = new QuantileDigest(0.01, ExponentialDecay.computeAlpha(QuantileDigest.ZERO_WEIGHT_THRESHOLD, 60), ticker);
    addRange(digest, 1, 10);
    // TODO: tighter bounds?
    ticker.increment(1000, TimeUnit.SECONDS);
    int from = 4;
    int to = 7;
    addRange(digest, from, to + 1);
    digest.validate();
    assertEquals(digest.getMin(), from);
    assertEquals(digest.getMax(), to);
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Test(org.testng.annotations.Test)

Example 15 with TestingTicker

use of io.airlift.testing.TestingTicker in project airlift by airlift.

the class TestQuantileDigest method testRescaleWithDecayKeepsCompactTree.

@Test
public void testRescaleWithDecayKeepsCompactTree() throws Exception {
    TestingTicker ticker = new TestingTicker();
    int targetAgeInSeconds = (int) (QuantileDigest.RESCALE_THRESHOLD_SECONDS);
    QuantileDigest digest = new QuantileDigest(0.01, ExponentialDecay.computeAlpha(QuantileDigest.ZERO_WEIGHT_THRESHOLD / 2, targetAgeInSeconds), ticker);
    for (int i = 0; i < 10; ++i) {
        digest.add(i);
        digest.validate();
        // bump the clock to make all previous values decay to ~0
        ticker.increment(targetAgeInSeconds, TimeUnit.SECONDS);
    }
    assertEquals(digest.getNodeCount(), 1);
}
Also used : TestingTicker(io.airlift.testing.TestingTicker) Test(org.testng.annotations.Test)

Aggregations

TestingTicker (io.airlift.testing.TestingTicker)17 Test (org.testng.annotations.Test)17 Duration (io.airlift.units.Duration)3 PRESTO_PAGES (com.facebook.presto.PrestoMediaTypes.PRESTO_PAGES)1 TaskHandle (com.facebook.presto.execution.TaskExecutor.TaskHandle)1 PagesSerde (com.facebook.presto.execution.buffer.PagesSerde)1 SerializedPage (com.facebook.presto.execution.buffer.SerializedPage)1 TestingPagesSerdeFactory.testingPagesSerde (com.facebook.presto.execution.buffer.TestingPagesSerdeFactory.testingPagesSerde)1 ClientCallback (com.facebook.presto.operator.HttpPageBufferClient.ClientCallback)1 Page (com.facebook.presto.spi.Page)1 PAGE_TOO_LARGE (com.facebook.presto.spi.StandardErrorCode.PAGE_TOO_LARGE)1 PAGE_TRANSPORT_ERROR (com.facebook.presto.spi.StandardErrorCode.PAGE_TRANSPORT_ERROR)1 PAGE_TRANSPORT_TIMEOUT (com.facebook.presto.spi.StandardErrorCode.PAGE_TRANSPORT_TIMEOUT)1 WORKER_NODE_ERROR (com.facebook.presto.util.Failures.WORKER_NODE_ERROR)1 Throwables (com.google.common.base.Throwables)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 CONTENT_TYPE (com.google.common.net.HttpHeaders.CONTENT_TYPE)1 Threads.daemonThreadsNamed (io.airlift.concurrent.Threads.daemonThreadsNamed)1 HttpStatus (io.airlift.http.client.HttpStatus)1 Request (io.airlift.http.client.Request)1