use of com.twitter.common.util.testing.FakeClock in project commons by twitter.
the class HttpStatsFilterIntegrationTest method setUp.
@Before
public void setUp() {
Stats.flush();
server = new JettyHttpServerDispatch();
server.listen(0);
server.registerFilter(GuiceFilter.class, "/*");
clock = new FakeClock();
final Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(TestServlet.class).in(Singleton.class);
bind(Clock.class).toInstance(clock);
bind(HttpStatsFilter.class).in(Singleton.class);
}
}, new JerseyServletModule() {
@Override
protected void configureServlets() {
filter("/*").through(HttpStatsFilter.class);
serve("/*").with(GuiceContainer.class, ImmutableMap.of(PROPERTY_CONTAINER_RESPONSE_FILTERS, HttpStatsFilter.class.getName()));
}
});
server.getRootContext().addEventListener(new GuiceServletContextListener() {
@Override
protected Injector getInjector() {
return injector;
}
});
ClientConfig config = new DefaultClientConfig();
client = Client.create(config);
}
use of com.twitter.common.util.testing.FakeClock in project commons by twitter.
the class MarkDeadStrategyWithHostCheckTest method setUp.
@Before
public void setUp() {
wrappedStrategy = createMock(new Clazz<LoadBalancingStrategy<String>>() {
});
onBackendsChosen = createMock(new Clazz<Closure<Collection<String>>>() {
});
random = createMock(Random.class);
clock = new FakeClock();
Function<String, BackoffDecider> backoffFactory = new Function<String, BackoffDecider>() {
@Override
public BackoffDecider apply(String s) {
return BackoffDecider.builder(s).withSeedSize(1).withClock(clock).withRandom(random).withTolerateFailureRate(0.5).withStrategy(new TruncatedBinaryBackoff(INITIAL_BACKOFF, MAX_BACKOFF)).withRecoveryType(BackoffDecider.RecoveryType.FULL_CAPACITY).withRequestWindow(MAX_BACKOFF).build();
}
};
markDead = new MarkDeadStrategyWithHostCheck<String>(wrappedStrategy, backoffFactory);
}
use of com.twitter.common.util.testing.FakeClock in project commons by twitter.
the class RequestLoggerTest method setUp.
@Before
public void setUp() throws Exception {
clock = new FakeClock();
sink = createMock(LogSink.class);
request = createMock(Request.class);
response = createMock(Response.class);
log = new RequestLogger(clock, sink);
}
use of com.twitter.common.util.testing.FakeClock in project commons by twitter.
the class HttpStatsFilterTest method setUp.
@Before
public void setUp() throws Exception {
clock = new FakeClock();
request = createMock(HttpServletRequest.class);
response = createMock(HttpServletResponse.class);
filterChain = createMock(FilterChain.class);
filter = new HttpStatsFilter(clock);
containerRequest = createMock(ContainerRequest.class);
containerResponse = createMock(ContainerResponse.class);
injectContextVars();
}
use of com.twitter.common.util.testing.FakeClock in project commons by twitter.
the class HistogramTest method testHistogramWithMemoryConstraints.
@Test
public void testHistogramWithMemoryConstraints() {
int n = 10000;
FakeClock clock = new FakeClock();
int slices = 2;
double error = DEFAULT_PRECISION.getEpsilon() * n * slices;
// We suppose here that 32KB is enough for the default precision of (slices + 1) histograms
HistogramInterface hist = new Histogram(name, Amount.of(1L, Time.MINUTES), slices, Amount.of(32L, Data.KB), null, DEFAULT_QUANTILES, clock);
for (int i = 1; i <= n; ++i) {
hist.add(i);
}
clock.advance(Amount.of(31L, Time.SECONDS));
Snapshot sample = hist.snapshot();
assertEquals(1L, sample.min());
assertEquals((long) n, sample.max());
assertEquals((long) n, sample.count());
assertEquals((long) (n * (n + 1) / 2), sample.sum());
assertEquals(n * (n + 1) / (2.0 * n), sample.avg(), 0.1);
long[] expected = new long[DEFAULT_QUANTILES.length];
for (int i = 0; i < DEFAULT_QUANTILES.length; i++) {
expected[i] = (long) (DEFAULT_QUANTILES[i] * n);
}
checkQuantiles(expected, sample, error);
}
Aggregations