/** * Request is replayable on a different origin IFF * A) we have not started to send response back to the client AND * B) we have not lost any of its body chunks */ protected boolean isRequestReplayable() { if (startedSendingResponseToClient) { NO_RETRY_RESP_STARTED.increment(); return false; } if (proxiedRequestWithoutBuffering) { NO_RETRY_INCOMPLETE_BODY.increment(); return false; } return true; }
@Test public void testDynamicCounterIncrement() { DynamicCounter.increment(CONFIG); assertEquals(1, registry.counter(ID).count()); }
@Override public Id id() { return get().id(); }
@Test public void testDynamicTimerRecordSeconds() { DynamicTimer.record(CONFIG, 42); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42 * 42, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void testAddNaN() { Counter c = new DefaultCounter(clock, NoopId.INSTANCE); c.add(1.0); c.add(Double.NaN); Assertions.assertEquals(c.actualCount(), 1.0, 1e-12); }
@Override public double actualCount() { return get().actualCount(); }
@Override public void add(double amount) { get().add(amount); }
private void doMeasurementTest(Counter c, int expectedValue, long expectedTime) { c.increment(expectedValue); clock.setWallTime(expectedTime); List<Measurement> measurements = Utils.toList(c.measure()); Assertions.assertEquals(1, measurements.size()); Measurement m = measurements.get(0); Assertions.assertEquals(c.id(), m.id()); Assertions.assertEquals(expectedTime, m.timestamp()); Assertions.assertEquals(expectedValue, m.value(), 0.1e-12); }
@Test public void testBasicTimerRecordSeconds() { BasicTimer d = new BasicTimer(CONFIG, TimeUnit.SECONDS); register(d); d.record(42, TimeUnit.NANOSECONDS); Id id = ID.withTag("unit", "SECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42e-9, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42e-9 * 42e-9, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42e-9, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }
@Test public void counterAdd() { Counter c = registry.counter("foo"); Assertions.assertEquals(0.0, c.actualCount(), 1e-12); c.add(1.5); Assertions.assertEquals(1.5, c.actualCount(), 1e-12); }
@Test public void testDoubleCounterAdd() { DoubleCounter c = new DoubleCounter(CONFIG, Clock.WALL); register(c); c.increment(0.2); assertEquals(0.2, registry.counter(ID).actualCount()); }
/** * Update the counter by {@code amount}. * * @param amount * Amount to add to the counter. */ default void increment(long amount) { add(amount); }
protected static void incrementExceptionCounter(Throwable throwable, String handler) { registry.counter("server.connection.exception", "handler", handler, "id", throwable.getClass().getSimpleName()) .increment(); }
@Test public void testMeasure() { Counter c = new DefaultCounter(clock, NoopId.INSTANCE); c.increment(42); clock.setWallTime(3712345L); for (Measurement m : c.measure()) { Assertions.assertEquals(m.id(), c.id()); Assertions.assertEquals(m.timestamp(), 3712345L); Assertions.assertEquals(m.value(), 42.0, 0.1e-12); } }
@Test public void testUnregisteredBasicCounterIncrement() { BasicCounter c = new BasicCounter(CONFIG); c.increment(); assertEquals(1, registry.counters().count()); assertEquals(1, registry.counter("test").count()); }
@Test public void testBasicTimerRecordMillis() { BasicTimer d = new BasicTimer(CONFIG); register(d); d.record(42, TimeUnit.NANOSECONDS); Id id = ID.withTag("unit", "MILLISECONDS"); assertEquals(1, registry.counter(id.withTag(Statistic.count)).count()); assertEquals(42e-6, registry.counter(id.withTag(Statistic.totalTime)).actualCount(), 1e-12); assertEquals(42e-6 * 42e-6, registry.counter(id.withTag(Statistic.totalOfSquares)).actualCount(), 1e-12); assertEquals(42e-6, registry.maxGauge(id.withTag(Statistic.max)).value(), 1e-12); }