MetricsCatcher { @Subscribe public void jobComplete(JobCompleteEvent data) { if (this.configuration.isJobsByType()) { jobs.complete(data.getCorrelationId()); registry.counter(prefix + ".jobs-active-" + data.getType() + "-count") .dec(); registry.counter(prefix + ".jobs-processed-" + data.getType() + "-count-data") .inc(data.getDataSize()); registry.meter(prefix + ".jobs-processed-" + data.getType() + "-meter-data") .mark(data.getDataSize()); registry.counter(prefix + ".jobs-errors-" + data.getType() + "-count-data") .inc(data.getErrors()); registry.meter(prefix + ".jobs-errors-" + data.getType() + "-meter-data") .mark(data.getErrors()); if (data.getErrors() > 0l) { registry.counter(prefix + ".jobs-succeeded-" + data.getType() + "-count") .inc(); registry.meter(prefix + ".jobs-succeeded-" + data.getType() + "-meter") .mark(); } else { registry.counter(prefix + ".jobs-failed-" + data.getType() + "-count") .inc(); registry.meter(prefix + ".jobs-failed-" + data.getType() + "-meter") .mark(); } } } @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 jobsCounterDec() { catcher.jobComplete(new JobCompleteEvent("10", "test", 10l, 5l)); assertThat(registry.counter(this.config.getPrefix() + ".jobs-active-test-count") .getCount(), equalTo(-1l)); }