MetricsCatcher { @Subscribe public void error(ErrorCode c) { registry.meter(prefix + ".errors") .mark(); registry.counter(prefix + ".errors-count") .inc(); if (this.configuration.isErrorsByCode()) { registry.meter(name(c)) .mark(); registry.counter(name(c) + "-count") .inc(); } if (this.configuration.isErrorsByType()) { registry.meter(prefix + ".error-severity-" + c.getSeverity() .name()) .mark(); registry.counter(prefix + ".error-severity-" + c.getSeverity() .name() + "-count") .inc(); } } @Autowired  MetricsCatcher(MetricRegistry registry, EventBus bus, Configuration configuration); @Subscribe void requestStart(AddQuery<T> data); @Subscribe void requestComplete(RemoveQuery<T> data); @Subscribe void requestStart(AddLabelledQuery<T> data); @Subscribe void requestComplete(RemoveLabelledQuery<T> data); @Subscribe void finished(SystemData data); @Subscribe void jobStarted(JobStartEvent data); @Subscribe void jobComplete(JobCompleteEvent data); @Subscribe void error(ErrorCode c); @Subscribe void error(ErrorEvent event); @Subscribe void genericEvent(GenericEvent event);  }
@Test public void testErrorCount() { catcher.error(ErrorCode.medium(10, "hello world")); assertThat(registry.counter(this.config.getPrefix() + ".error-MEDIUM-10-count") .getCount(), equalTo(1l)); }
@Test public void testErrorMeter() { catcher.error(ErrorCode.medium(10, "hello world")); assertThat(registry.meter(this.config.getPrefix() + ".error-MEDIUM-10") .getMeanRate(), greaterThan(0.00)); }
@Test public void testSeverityErrorCount() { catcher.error(ErrorCode.medium(10, "hello world")); assertThat(registry.counter(this.config.getPrefix() + ".error-severity-MEDIUM-count") .getCount(), equalTo(1l)); }
@Test public void testErrorSeverityMeter() { catcher.error(ErrorCode.medium(10, "hello world")); assertThat(registry.meter(this.config.getPrefix() + ".error-severity-MEDIUM") .getMeanRate(), greaterThan(0.00)); }