### Question:
TimelineMetricStoreWatcher implements Runnable { @Override public void run() { if (checkMetricStore()) { failures = 0; if (LOG.isDebugEnabled()) { LOG.debug("Successfully got metrics from TimelineMetricStore"); } } else { LOG.info("Failed to get metrics from TimelineMetricStore, attempt = " + failures); failures++; } if (failures >= configuration.getTimelineMetricsServiceWatcherMaxFailures()) { String msg = "Error getting metrics from TimelineMetricStore. " + "Shutting down by TimelineMetricStoreWatcher."; LOG.fatal(msg); ExitUtil.terminate(-1, msg); } } TimelineMetricStoreWatcher(HBaseTimelineMetricsService timelineMetricStore,
                                    TimelineMetricConfiguration configuration); @Override void run();  }### Answer:
@Test public void testRunPositive() throws Exception { HBaseTimelineMetricsService metricStore = createNiceMock(HBaseTimelineMetricsService.class); expect(metricStore.putMetricsSkipCache(anyObject(TimelineMetrics.class))) .andReturn(new TimelinePutResponse()); expect(metricStore.getTimelineMetrics(EasyMock.<List<String>>anyObject(), EasyMock.<List<String>>anyObject(), anyObject(String.class), anyObject(String.class), anyObject(Long.class), anyObject(Long.class), eq(Precision.SECONDS), eq(1), eq(true), anyObject(TopNConfig.class), anyString())) .andReturn(null).anyTimes(); mockStatic(ExitUtil.class); replay(metricStore); TimelineMetricStoreWatcher timelineMetricStoreWatcher = new TimelineMetricStoreWatcher(metricStore, TimelineMetricConfiguration.getInstance()); timelineMetricStoreWatcher.run(); timelineMetricStoreWatcher.run(); timelineMetricStoreWatcher.run(); verify(metricStore); }
@Test public void testRunNegative() throws Exception { HBaseTimelineMetricsService metricStore = createNiceMock(HBaseTimelineMetricsService.class); expect(metricStore.putMetrics(anyObject(TimelineMetrics.class))) .andReturn(new TimelinePutResponse()); expect(metricStore.getTimelineMetrics(EasyMock.<List<String>>anyObject(), EasyMock.<List<String>>anyObject(), anyObject(String.class), anyObject(String.class), anyObject(Long.class), anyObject(Long.class), eq(Precision.SECONDS), eq(1), eq(true), anyObject(TopNConfig.class), anyString())) .andReturn(null).anyTimes(); String msg = "Error getting metrics from TimelineMetricStore. " + "Shutting down by TimelineMetricStoreWatcher."; mockStatic(ExitUtil.class); ExitUtil.terminate(-1, msg); expectLastCall().anyTimes(); replayAll(); TimelineMetricStoreWatcher timelineMetricStoreWatcher = new TimelineMetricStoreWatcher(metricStore, TimelineMetricConfiguration.getInstance()); timelineMetricStoreWatcher.run(); timelineMetricStoreWatcher.run(); timelineMetricStoreWatcher.run(); verifyAll(); }