use of org.apache.calcite.avatica.metrics.Counter in project calcite-avatica by apache.
the class DropwizardMetricsSystemTest method testCounter.
@Test
public void testCounter() {
final String name = "counter";
final com.codahale.metrics.Counter mockCounter = mock(com.codahale.metrics.Counter.class);
when(mockRegistry.counter(name)).thenReturn(mockCounter);
Counter counter = metrics.getCounter(name);
long[] updates = new long[] { 1L, 5L, -2L, 4L, -8L, 0 };
for (long update : updates) {
if (update < 0) {
counter.decrement(Math.abs(update));
} else {
counter.increment(update);
}
}
for (long update : updates) {
if (update < 0) {
verify(mockCounter).dec(Math.abs(update));
} else {
verify(mockCounter).inc(update);
}
}
int numSingleUpdates = 3;
for (int i = 0; i < numSingleUpdates; i++) {
counter.increment();
counter.decrement();
}
verify(mockCounter, times(numSingleUpdates)).inc();
verify(mockCounter, times(numSingleUpdates)).dec();
}
use of org.apache.calcite.avatica.metrics.Counter in project calcite-avatica by apache.
the class NoopMetricsSystemTest method testNoNulls.
@Test
public void testNoNulls() {
// The NOOP implementation should act as a real implementation, no "nulls" allowed.
MetricsSystem metrics = NoopMetricsSystem.getInstance();
Counter counter = metrics.getCounter("counter");
counter.decrement();
counter.increment();
counter.decrement(1L);
counter.increment(1L);
Histogram histogram = metrics.getHistogram("histogram");
histogram.update(1);
histogram.update(1L);
Timer timer = metrics.getTimer("timer");
Context context = timer.start();
context.close();
Context contextTwo = timer.start();
assertTrue("Timer's context should be a singleton", context == contextTwo);
Meter meter = metrics.getMeter("meter");
meter.mark();
meter.mark(5L);
metrics.register("gauge", new Gauge<Long>() {
@Override
public Long getValue() {
return 42L;
}
});
}
Aggregations