Package com.codahale.metrics

Examples of com.codahale.metrics.Meter


*/
class ExceptionMeteredInterceptor implements MethodInterceptor {
    static MethodInterceptor forMethod(MetricRegistry metricRegistry, Class<?> klass, Method method) {
        final ExceptionMetered annotation = method.getAnnotation(ExceptionMetered.class);
        if (annotation != null) {
            final Meter meter = metricRegistry.meter(determineName(annotation, klass, method));
            return new ExceptionMeteredInterceptor(meter, annotation.cause());
        }
        return null;
    }
View Full Code Here


    }

    @Test
    public void anExceptionMeteredAnnotatedMethodWithPublicScope() throws Exception {

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

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

        try {
            instance.explodeWithPublicScope(true);
            fail("Expected an exception to be thrown");
        } catch (RuntimeException e) {
            // Swallow the expected exception
        }

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

    }

    @Test
    public void anExceptionMeteredAnnotatedMethod_WithNoMetricName() throws Exception {

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

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

        try {
            instance.explodeForUnnamedMetric();
            fail("Expected an exception to be thrown");
        } catch (RuntimeException e) {
            // Swallow the expected exception
        }

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

    }

    @Test
    public void anExceptionMeteredAnnotatedMethod_WithName() throws Exception {

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

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

        try {
            instance.explodeForMetricWithName();
            fail("Expected an exception to be thrown");
        } catch (RuntimeException e) {
            // Swallow the expected exception
        }

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


    @Test
    public void anExceptionMeteredAnnotatedMethod_WithAbsoluteName() throws Exception {

        final Meter metric = registry.getMeters().get(name("absoluteName"));
        assertMetricIsSetup(metric);

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

        try {
            instance.explodeForMetricWithAbsoluteName();
            fail("Expected an exception to be thrown");
        } catch (RuntimeException e) {
            // Swallow the expected exception
        }

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


    @Test
    public void anExceptionMeteredAnnotatedMethod_WithPublicScopeButNoExceptionThrown() throws Exception {

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

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

        instance.explodeWithPublicScope(false);

        assertThat("Metric should remain at zero if no exception is thrown",
                   metric.getCount(),
                   is(0L));
    }
View Full Code Here

    }

    @Test
    public void anExceptionMeteredAnnotatedMethod_WithDefaultScope() throws Exception {

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

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

        try {
            instance.explodeWithDefaultScope();
            fail("Expected an exception to be thrown");
        } catch (RuntimeException ignored) {
        }

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

    }

    @Test
    public void anExceptionMeteredAnnotatedMethod_WithProtectedScope() throws Exception {

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

        assertMetricIsSetup(metric);

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

        try {
            instance.explodeWithProtectedScope();
            fail("Expected an exception to be thrown");
        } catch (RuntimeException ignored) {
        }

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

    }

    @Test
    public void anExceptionMeteredAnnotatedMethod_WithPublicScope_AndSpecificTypeOfException() 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 MyException());
            fail("Expected an exception to be thrown");
        } catch (MyException ignored) {
        }

        assertThat("Metric should be marked when the specified exception type is thrown",
                   metric.getCount(),
                   is(1L));
    }
View Full Code Here

    }

    @Test
    public void anExceptionMeteredAnnotatedMethod_WithPublicScope_AndSubclassesOfSpecifiedException() 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 MySpecialisedException());
            fail("Expected an exception to be thrown");
        } catch (MyException ignored) {
        }

        assertThat(
                "Metric should be marked when a subclass of the specified exception type is thrown",
                metric.getCount(),
                is(1L));
    }
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.