Search in sources :

Example 6 with WindowedStatistics

use of com.twitter.common.stats.WindowedStatistics in project commons by twitter.

the class WindowedStatsTest method testCleaningOfExpiredWindows.

@Test
public void testCleaningOfExpiredWindows() {
    FakeClock clock = new FakeClock();
    WindowedStatistics ws = new WindowedStatistics(window, slices, clock);
    long n = 1000L;
    for (int i = 0; i < n; i++) {
        ws.accumulate(i);
    }
    assertEmpty(ws);
    clock.advance(Amount.of(1 + sliceDuration, Time.NANOSECONDS));
    ws.refresh();
    // this window is not empty
    assertEquals(n, ws.populationSize());
    clock.advance(Amount.of(100 * sliceDuration, Time.NANOSECONDS));
    ws.refresh();
    // this window has been cleaned
    assertEmpty(ws);
}
Also used : FakeClock(com.twitter.common.util.testing.FakeClock) WindowedStatistics(com.twitter.common.stats.WindowedStatistics) Test(org.junit.Test)

Example 7 with WindowedStatistics

use of com.twitter.common.stats.WindowedStatistics in project commons by twitter.

the class WindowedStatsTest method testEmptyStats.

@Test
public void testEmptyStats() {
    FakeClock clock = new FakeClock();
    WindowedStatistics ws = new WindowedStatistics(window, slices, clock);
    assertEmpty(ws);
}
Also used : FakeClock(com.twitter.common.util.testing.FakeClock) WindowedStatistics(com.twitter.common.stats.WindowedStatistics) Test(org.junit.Test)

Aggregations

WindowedStatistics (com.twitter.common.stats.WindowedStatistics)7 FakeClock (com.twitter.common.util.testing.FakeClock)6 Test (org.junit.Test)5 WindowedApproxHistogram (com.twitter.common.stats.WindowedApproxHistogram)2 Histogram (com.twitter.common.metrics.Histogram)1 HistogramInterface (com.twitter.common.metrics.HistogramInterface)1 Data (com.twitter.common.quantity.Data)1 Time (com.twitter.common.quantity.Time)1