Search in sources :

Example 21 with FakeClock

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);
}
Also used : FakeClock(com.twitter.common.util.testing.FakeClock) WindowedStatistics(com.twitter.common.stats.WindowedStatistics) Test(org.junit.Test)

Example 22 with FakeClock

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);
}
Also used : FakeClock(com.twitter.common.util.testing.FakeClock) WindowedStatistics(com.twitter.common.stats.WindowedStatistics) Test(org.junit.Test)

Example 23 with FakeClock

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));
}
Also used : FakeClock(com.twitter.common.util.testing.FakeClock) Time(com.twitter.common.quantity.Time) Test(org.junit.Test)

Example 24 with FakeClock

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);
}
Also used : FakeClock(com.twitter.common.util.testing.FakeClock) Before(org.junit.Before)

Aggregations

FakeClock (com.twitter.common.util.testing.FakeClock)24 Test (org.junit.Test)14 Before (org.junit.Before)9 Time (com.twitter.common.quantity.Time)7 WindowedStatistics (com.twitter.common.stats.WindowedStatistics)6 Function (com.google.common.base.Function)2 BackoffDecider (com.twitter.common.util.BackoffDecider)2 Random (com.twitter.common.util.Random)2 TruncatedBinaryBackoff (com.twitter.common.util.TruncatedBinaryBackoff)2 Collection (java.util.Collection)2 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 Singleton (com.google.inject.Singleton)1 GuiceServletContextListener (com.google.inject.servlet.GuiceServletContextListener)1 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)1 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)1 JerseyServletModule (com.sun.jersey.guice.JerseyServletModule)1 GuiceContainer (com.sun.jersey.guice.spi.container.servlet.GuiceContainer)1 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)1 ContainerResponse (com.sun.jersey.spi.container.ContainerResponse)1