Package com.codahale.metrics

Examples of com.codahale.metrics.Timer


    @Test
    public void aTimedAnnotatedMethod() throws Exception {

        instance.doAThing();

        final Timer metric = registry.getTimers().get(name(InstrumentedWithTimed.class,
            "things"));

        assertMetricSetup(metric);

        assertThat("Guice creates a timer which records invocation length",
            metric.getCount(),
            is(1L));
    }
View Full Code Here


    @Test
    public void aTimedAnnotatedMethodWithDefaultScope() throws Exception {

        instance.doAThingWithDefaultScope();

        final Timer metric = registry.getTimers().get(name(InstrumentedWithTimed.class,
            "doAThingWithDefaultScope", TimedInterceptor.TIMED_SUFFIX));

        assertMetricSetup(metric);
    }
View Full Code Here

    @Test
    public void aTimedAnnotatedMethodWithProtectedScope() throws Exception {

        instance.doAThingWithProtectedScope();

        final Timer metric = registry.getTimers().get(name(InstrumentedWithTimed.class,
            "doAThingWithProtectedScope", TimedInterceptor.TIMED_SUFFIX));

        assertMetricSetup(metric);
    }
View Full Code Here

    @Test
    public void aTimedAnnotatedMethodWithAbsoluteName() throws Exception {

        instance.doAThingWithAbsoluteName();

        final Timer metric = registry.getTimers().get(name("absoluteName"));

        assertMetricSetup(metric);
    }
View Full Code Here


    @Test
    public void aMethodAnnotatedWithBothATimerAndAnExceptionCounter() throws Exception {

        final Timer timedMetric = registry.getTimers().get(name(InstrumentedWithExceptionMetered.class,
            "timedAndException", TimedInterceptor.TIMED_SUFFIX));

        final Meter errorMetric = registry.getMeters().get(name(InstrumentedWithExceptionMetered.class,
            "timedAndException", DEFAULT_NAME_SUFFIX));

        assertThat("Guice creates a metric",
                   timedMetric,
                   is(notNullValue()));

        assertThat("Guice creates a timer",
                   timedMetric,
                   is(instanceOf(Timer.class)));

        assertThat("Guice creates a metric",
                   errorMetric,
                   is(notNullValue()));

        assertThat("Guice creates a meter",
                   errorMetric,
                   is(instanceOf(Meter.class)));

        // Counts should start at zero       
        assertThat("Timer Metric should be zero when initialised",
                   timedMetric.getCount(),
                   is(0L));


        assertThat("Error Metric should be zero when initialised",
                   errorMetric.getCount(),
                   is(0L));

        // Invoke, but don't throw an exception
        instance.timedAndException(null);

        assertThat("Expected the meter metric to be marked on invocation",
                   timedMetric.getCount(),
                   is(1L));

        assertThat("Expected the exception metric to be zero since no exceptions thrown",
                   errorMetric.getCount(),
                   is(0L));

        // Invoke and throw an exception
        try {
            instance.timedAndException(new RuntimeException());
            fail("Should have thrown an exception");
        } catch (Exception ignored) {}

        assertThat("Expected a count of 2, one for each invocation",
                   timedMetric.getCount(),
                   is(2L));

        assertThat("Expected exception count to be 1 as one (of two) invocations threw an exception",
                   errorMetric.getCount(),
                   is(1L));
View Full Code Here

    @Test
    public void aTimedAnnotatedMethod() throws Exception {

        timedInstance.doAThing();

        final Timer metric = registry.getTimers().get(name(InstrumentedWithTimed.class,
            "things"));

        assertThat("Guice did not create a metric for timed",
                   metric,
                   is(nullValue()));
View Full Code Here

      HikariDataSource ds = new HikariDataSource(config);
      try {
         ds.getConnection().close();

         Timer timer = metricRegistry.getTimers(new MetricFilter() {
            /** {@inheritDoc} */
            @Override
            public boolean matches(String name, Metric metric)
            {
               return "test.pool.Wait".equals(MetricRegistry.name("test", "pool", "Wait"));
            }
         }).values().iterator().next();

         Assert.assertEquals(1, timer.getCount());
         Assert.assertTrue(timer.getMeanRate() > 0.0);
      }
      finally {
         ds.close();
      }
   }
View Full Code Here

        inOrder.verifyNoMoreInteractions();
    }

    @Test
    public void reportsTimers() throws Exception {
        final Timer timer = mock(Timer.class);
        when(timer.getCount()).thenReturn(1L);
        when(timer.getMeanRate()).thenReturn(2.0);
        when(timer.getOneMinuteRate()).thenReturn(3.0);
        when(timer.getFiveMinuteRate()).thenReturn(4.0);
        when(timer.getFifteenMinuteRate()).thenReturn(5.0);

        final Snapshot snapshot = mock(Snapshot.class);
        when(snapshot.getMax()).thenReturn(TimeUnit.MILLISECONDS.toNanos(100));
        when(snapshot.getMean()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(200));
        when(snapshot.getMin()).thenReturn(TimeUnit.MILLISECONDS.toNanos(300));
        when(snapshot.getStdDev()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(400));
        when(snapshot.getMedian()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(500));
        when(snapshot.get75thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(600));
        when(snapshot.get95thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(700));
        when(snapshot.get98thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(800));
        when(snapshot.get99thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS.toNanos(900));
        when(snapshot.get999thPercentile()).thenReturn((double) TimeUnit.MILLISECONDS
                                                                        .toNanos(1000));

        when(timer.getSnapshot()).thenReturn(snapshot);

        reporter.report(this.<Gauge>map(),
                        this.<Counter>map(),
                        this.<Histogram>map(),
                        this.<Meter>map(),
View Full Code Here

  public void time(String jobName, String stepName, String kind) {
    String metricName = stepName == null ?
        name(group, jobName, kind, TIMED_KIND) :
        name(group, jobName, STEP_KIND, stepName, kind, TIMED_KIND);
    Timer timer = metricRegistry.timer(metricName);
    Timer.Context timerContext = timer.time();
    timerContexts.put(metricName, timerContext);
  }
View Full Code Here

  @VisibleForTesting
  HttpResponse executeRequest(final ProxyRepository repository, final ResourceStoreRequest request,
                              final HttpUriRequest httpRequest, final String baseUrl, final boolean contentRequest)
      throws RemoteStorageException
  {
    final Timer timer = timer(repository, httpRequest, baseUrl);
    final Timer.Context timerContext = timer.time();
    Stopwatch stopwatch = null;
    if (outboundRequestLog.isDebugEnabled()) {
      stopwatch = new Stopwatch().start();
    }
    try {
View Full Code Here

TOP

Related Classes of com.codahale.metrics.Timer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.