MetricTracker implements AutoCloseable { public void start() { result = executorService.scheduleWithFixedDelay(new Runnable() { public void run() { try { metricPubSubEventHandler.getPubSubEventHandler().onNext(new MetricTrackEvent()); metricPubSubEventHandler.getPubSubEventHandler().onNext(new MetricUpdateEvent()); } catch (final Exception e) { e.printStackTrace(); } } }, groupTrackingInterval, groupTrackingInterval, TimeUnit.MILLISECONDS); } @Inject private  MetricTracker(final MetricTrackerExecutorServiceWrapper executorServiceWrapper,
                        @Parameter(MetricTrackingInterval.class) final long groupTrackingInterval,
                        final MistPubSubEventHandler metricPubSubEventHandler); void start(); @Override void close();  }
@Test(timeout = 1000L) public void testTwoGroupMetricTracking() throws InjectionException { tracker.start(); handler.waitForTracking(); assigner.waitForTracking(); }