MetricsCatcher { @Subscribe public void genericEvent(GenericEvent event) { GenericEvent.GenericEventData eventData = event.getData(); String name = prefix + ".event-" + eventData.getName(); registry.counter(name + "-count").inc(); registry.meter(name + "-meter").mark(); if (Objects.nonNull(eventData.getSubTypes())) { for (String subType : eventData.getSubTypes()) { name = name + "." + subType; registry.counter(name + "-count").inc(); registry.meter(name + "-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 testGenericEvent() { GenericEvent.trigger("generic", bus, "data", new String[] {"p1", "p2"}); assertThat(registry.meter(this.config.getPrefix() + ".event-generic-meter").getCount(), greaterThan(0L)); assertThat(registry.counter(this.config.getPrefix() + ".event-generic-count").getCount(), greaterThan(0L)); assertThat(registry.meter(this.config.getPrefix() + ".event-generic.p1-meter").getCount(), greaterThan(0L)); assertThat(registry.counter(this.config.getPrefix() + ".event-generic.p1-count").getCount(), greaterThan(0L)); assertThat(registry.meter(this.config.getPrefix() + ".event-generic.p1.p2-meter").getCount(), greaterThan(0L)); assertThat(registry.counter(this.config.getPrefix() + ".event-generic.p1.p2-count").getCount(), greaterThan(0L)); }