PushGatewayPeriodical extends Periodical { @Override public void doRun() { try { pushGateway.push( collectorRegistry, configuration.getJobName(), configuration.getGroupingKey()); } catch (IOException e) { LOG.error("Error while sending metrics to Prometheus Pushgateway", e); } } @Inject  PushGatewayPeriodical(MetricsPrometheusReporterConfiguration configuration,
                                 CollectorRegistry collectorRegistry,
                                 PushGateway pushGateway); @Override void doRun(); @Override boolean runsForever(); @Override boolean stopOnGracefulShutdown(); @Override boolean masterOnly(); @Override boolean startOnThisNode(); @Override boolean isDaemon(); @Override int getInitialDelaySeconds(); @Override int getPeriodSeconds();  }
@Test public void doRunHandlesException() throws Exception { doThrow(new IOException("Test")) .when(pushGateway).push(collectorRegistry, configuration.getJobName(), configuration.getGroupingKey()); periodical.doRun(); }
@Test public void doRunReportsMetrics() throws Exception { periodical.doRun(); verify(pushGateway).push(collectorRegistry, configuration.getJobName(), configuration.getGroupingKey()); }