ElasticSearchMonitorJob implements Job { @Override public void execute(JobContext context) { try { ElasticSearchNodeStats nodeStats = elasticSearchClient.stats(host); for (ElasticSearchNodeStats.Node node : nodeStats.nodes.values()) { String host = node.name; Stats stats = collect(node); publishStats(host, stats); } } catch (Throwable e) { logger.error(e.getMessage(), e); publishError(e); } } ElasticSearchMonitorJob(ElasticSearchClient elasticSearchClient, String app, String host, MessagePublisher<StatMessage> publisher); @Override void execute(JobContext context); public double highHeapUsageThreshold; public double highDiskUsageThreshold; }
@Test void execute() throws IOException { when(elasticSearchClient.stats("localhost")) .thenReturn(JSON.fromJSON(ElasticSearchNodeStats.class, ClasspathResources.text("es-job-test/stats.json"))); job.execute(null); verify(publisher).publish(argThat(message -> "es-0".equals(message.host))); }