Search in sources :

Example 1 with Timer

use of org.apache.calcite.avatica.metrics.Timer in project druid by druid-io.

the class AvaticaMonitor method getTimer.

@Override
public Timer getTimer(final String name) {
    final AtomicLong counter = makeCounter(name);
    return new Timer() {

        @Override
        public Context start() {
            final long start = System.currentTimeMillis();
            final AtomicBoolean closed = new AtomicBoolean();
            return new Context() {

                @Override
                public void close() {
                    if (closed.compareAndSet(false, true)) {
                        counter.addAndGet(System.currentTimeMillis() - start);
                    }
                }
            };
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) Timer(org.apache.calcite.avatica.metrics.Timer)

Example 2 with Timer

use of org.apache.calcite.avatica.metrics.Timer in project calcite-avatica by apache.

the class DropwizardMetricsSystemTest method testTimer.

@Test
public void testTimer() {
    final String name = "timer";
    final com.codahale.metrics.Timer mockTimer = mock(com.codahale.metrics.Timer.class);
    final com.codahale.metrics.Timer.Context mockContext = mock(com.codahale.metrics.Timer.Context.class);
    when(mockRegistry.timer(name)).thenReturn(mockTimer);
    when(mockTimer.time()).thenReturn(mockContext);
    Timer timer = metrics.getTimer(name);
    Context context = timer.start();
    context.close();
    verify(mockTimer).time();
    verify(mockContext).stop();
}
Also used : Context(org.apache.calcite.avatica.metrics.Timer.Context) Timer(org.apache.calcite.avatica.metrics.Timer) Test(org.junit.Test)

Example 3 with Timer

use of org.apache.calcite.avatica.metrics.Timer in project druid by druid-io.

the class AvaticaMonitor method getTimer.

@Override
public Timer getTimer(final String name) {
    final AtomicLong counter = makeCounter(name);
    return new Timer() {

        @Override
        public Context start() {
            final long start = System.currentTimeMillis();
            final AtomicBoolean closed = new AtomicBoolean();
            return new Context() {

                @Override
                public void close() {
                    if (closed.compareAndSet(false, true)) {
                        counter.addAndGet(System.currentTimeMillis() - start);
                    }
                }
            };
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) Timer(org.apache.calcite.avatica.metrics.Timer)

Example 4 with Timer

use of org.apache.calcite.avatica.metrics.Timer 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;
        }
    });
}
Also used : Context(org.apache.calcite.avatica.metrics.Timer.Context) Histogram(org.apache.calcite.avatica.metrics.Histogram) Counter(org.apache.calcite.avatica.metrics.Counter) Timer(org.apache.calcite.avatica.metrics.Timer) Meter(org.apache.calcite.avatica.metrics.Meter) MetricsSystem(org.apache.calcite.avatica.metrics.MetricsSystem) Test(org.junit.Test)

Example 5 with Timer

use of org.apache.calcite.avatica.metrics.Timer in project calcite-avatica by apache.

the class DropwizardMetricsSystemTest method testTimer.

@Test
public void testTimer() {
    final String name = "timer";
    final com.codahale.metrics.Timer mockTimer = mock(com.codahale.metrics.Timer.class);
    final com.codahale.metrics.Timer.Context mockContext = mock(com.codahale.metrics.Timer.Context.class);
    when(mockRegistry.timer(name)).thenReturn(mockTimer);
    when(mockTimer.time()).thenReturn(mockContext);
    Timer timer = metrics.getTimer(name);
    Context context = timer.start();
    context.close();
    verify(mockTimer).time();
    verify(mockContext).stop();
}
Also used : Context(org.apache.calcite.avatica.metrics.Timer.Context) Timer(org.apache.calcite.avatica.metrics.Timer) Test(org.junit.Test)

Aggregations

Timer (org.apache.calcite.avatica.metrics.Timer)5 Context (org.apache.calcite.avatica.metrics.Timer.Context)3 Test (org.junit.Test)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Counter (org.apache.calcite.avatica.metrics.Counter)1 Histogram (org.apache.calcite.avatica.metrics.Histogram)1 Meter (org.apache.calcite.avatica.metrics.Meter)1 MetricsSystem (org.apache.calcite.avatica.metrics.MetricsSystem)1