MetricsExporterFixtureProvider { @Nullable public static MetricsExporterFixture create(DataStoreOptions options, Whiteboard wb) throws Exception { if (options.exportMetrics()) { CollectorRegistry collectorRegistry = new CollectorRegistry(); wb.register(CollectorRegistry.class, collectorRegistry, emptyMap()); MetricRegistry metricRegistry = getService(wb, MetricRegistry.class); ExportMetricsArgs metricsArgs = new ExportMetricsArgs(options.exportMetricsArgs()); if (metricsArgs.getExporterType() == ExporterType.pushgateway) { PushGateway pg = new PushGateway(metricsArgs.getPushUri()); new DropwizardExports(metricRegistry).register(collectorRegistry); wb.register(PushGateway.class, pg, emptyMap()); return new MetricsExporterFixture<PushGateway>() { @Override public ExporterType getExporterType() { return ExporterType.pushgateway; } @Override public PushGateway getMetricsExporter() { return pg; } @Override public void close() throws IOException { pg.pushAdd(collectorRegistry, PushGateway.class.getName(), metricsArgs.getPushMap()); } }; } } return null; }  @Nullable static MetricsExporterFixture create(DataStoreOptions options, Whiteboard wb);  }
@Test public void checkCorrectPushGatewayInit() throws Exception { OptionParser parser = new OptionParser(); DataStoreOptions dataStoreOptions = new DataStoreOptions(parser); OptionSet option = parser.parse("--export-metrics", "pushgateway;localhost:9091;key1=value1,key2=value2"); dataStoreOptions.configure(option); MetricsExporterFixture metricsExporterFixture = MetricsExporterFixtureProvider.create(dataStoreOptions, new DefaultWhiteboard()); assertEquals("pushgateway", metricsExporterFixture.getExporterType().name()); Object metricsExporter = metricsExporterFixture.getMetricsExporter(); assertTrue(metricsExporter instanceof PushGateway); }