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