use of com.twitter.common.util.testing.FakeClock 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);
}
use of com.twitter.common.util.testing.FakeClock 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);
}
use of com.twitter.common.util.testing.FakeClock in project commons by twitter.
the class WindowedHistogramTest method testClearedWinHistogram.
@Test
public void testClearedWinHistogram() {
FakeClock clock = new FakeClock();
Amount<Long, Time> window = Amount.of(100L, Time.MILLISECONDS);
int slices = 10;
Amount<Long, Time> sliceDuration = Amount.of(window.as(Time.NANOSECONDS) / slices, Time.NANOSECONDS);
WindowedHistogram<?> h = createFullHistogram(window, slices, clock);
long p0 = h.getQuantile(0.1);
long p50 = h.getQuantile(0.5);
long p90 = h.getQuantile(0.9);
assertFalse(0 == p0);
assertFalse(0 == p50);
assertFalse(0 == p90);
h.clear();
assertEquals(0, h.getQuantile(0.1));
assertEquals(0, h.getQuantile(0.5));
assertEquals(0, h.getQuantile(0.9));
// reload the histogram with the exact same values than before
fillHistogram(h, sliceDuration, slices, clock);
assertEquals(p0, h.getQuantile(0.1));
assertEquals(p50, h.getQuantile(0.5));
assertEquals(p90, h.getQuantile(0.9));
}
use of com.twitter.common.util.testing.FakeClock in project commons by twitter.
the class CachingSupplierTest method setUp.
@Before
public void setUp() {
supplier = createMock(new Clazz<Supplier<String>>() {
});
clock = new FakeClock();
cache = new CachingSupplier<String>(supplier, ONE_SECOND, clock);
}
Aggregations