Package com.codahale.metrics

Examples of com.codahale.metrics.Meter


    }

    @Test
    public void anExceptionMeteredAnnotatedMethod_WithPublicScope_ButDifferentTypeOfException() throws Exception {

        final Meter metric = registry.getMeters().get(name(InstrumentedWithExceptionMetered.class,
                                                          "failures"));
        assertMetricIsSetup(metric);

        assertThat("Metric intialises to zero",
                   metric.getCount(),
                   is(0L));
        try {
            instance.errorProneMethod(new MyOtherException());
            fail("Expected an exception to be thrown");
        } catch (MyOtherException ignored) {
        }

        assertThat("Metric should not be marked if the exception is a different type",
                   metric.getCount(),
                   is(0L));
    }
View Full Code Here


            instance.causeAnOutOfBoundsException();
        } catch (ArrayIndexOutOfBoundsException ignored) {

        }

        final Meter metric = registry.getMeters().get(name(InstrumentedWithExceptionMetered.class,
                                                          "things"));

        assertMetricIsSetup(metric);

        assertThat("Guice creates a meter which gets marked",
                   metric.getCount(),
                   is(1L));
    }
View Full Code Here

    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 aMeteredAnnotatedMethod() throws Exception {

        meteredInstance.doAThing();

        final Meter metric = registry.getMeters().get(name(InstrumentedWithMetered.class, "things"));

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

        assertThat("Guice creates a meter which gets marked",
                   metric.getCount(),
                   is(1L));
    }
View Full Code Here

    @Test
    public void aMeteredAnnotatedMethod() throws Exception {

        instance.doAThing();

        final Meter metric = registry.getMeters().get(name(InstrumentedWithMetered.class, "things"));

        assertMetricIsSetup(metric);

        assertThat("Guice creates a meter which gets marked",
                   metric.getCount(),
                   is(1L));
    }
View Full Code Here

    }

    @Test
    public void aMeteredAnnotatedMethodWithDefaultScope() throws Exception {

        final Meter metric = registry.getMeters().get(name(InstrumentedWithMetered.class, "doAThingWithDefaultScope",
            MeteredInterceptor.METERED_SUFFIX));
        assertMetricIsSetup(metric);

        assertThat("Metric initialises to zero",
                   metric.getCount(),
                   is(0L));

        instance.doAThingWithDefaultScope();

        assertThat("Metric is marked",
                   metric.getCount(),
                   is(1L));
    }
View Full Code Here

    }

    @Test
    public void aMeteredAnnotatedMethodWithProtectedScope() throws Exception {

        final Meter metric = registry.getMeters().get(name(InstrumentedWithMetered.class, "doAThingWithProtectedScope",
            MeteredInterceptor.METERED_SUFFIX));

        assertMetricIsSetup(metric);

        assertThat("Metric initialises to zero",
                   metric.getCount(),
                   is(0L));

        instance.doAThingWithProtectedScope();

        assertThat("Metric is marked",
                   metric.getCount(),
                   is(1L));
    }
View Full Code Here

    }

    @Test
    public void aMeteredAnnotatedMethodWithName() throws Exception {

        final Meter metric = registry.getMeters().get(name(InstrumentedWithMetered.class, "n"));

        assertMetricIsSetup(metric);

        assertThat("Metric initialises to zero",
                   metric.getCount(),
                   is(0L));

        instance.doAThingWithName();

        assertThat("Metric is marked",
                   metric.getCount(),
                   is(1L));
    }
View Full Code Here

                   is(1L));
    }

    @Test
    public void aMeteredAnnotatedMethodWithAbsoluteName() {
        final Meter metric = registry.getMeters().get(name("nameAbs"));

        assertMetricIsSetup(metric);

        assertThat("Metric initialises to zero",
            metric.getCount(),
            is(0L));

        instance.doAThingWithAbsoluteName();

        assertThat("Metric is marked",
            metric.getCount(),
            is(1L));
    }
View Full Code Here

  public void mark(String jobName, String stepName) {
    String metricName = stepName == null ?
        name(group, jobName, JOB_KIND, METERED_KIND) :
        name(group, jobName, STEP_KIND, stepName, STEP_KIND, METERED_KIND);

    Meter meter = metricRegistry.meter(metricName);
    meter.mark();
  }
View Full Code Here

TOP

Related Classes of com.codahale.metrics.Meter

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.