@Test public void metricPusherShouldPushSafeUsingPushGateway() throws IOException { PushGatewayPusherCreator pushGatewayPusherCreator = new PushGatewayPusherCreator(); PushGateway pushGateway = mock(PushGateway.class); Map<String, String> groupingKey = Collections.emptyMap(); pushGatewayPusherCreator.create(() -> pushGateway).pushSafe(mock(CollectorRegistry.class), "job", groupingKey); verify(pushGateway, times(1)).push(any(CollectorRegistry.class), eq("job"), eq(groupingKey)); }
public MetricPusher create(String address) { Supplier<PushGateway> pushGatewaySupplier = () -> { try { return new PushGateway(address); } catch (Exception e) { logger.error("PushGateway creation failed.", e); return null; } }; return create(pushGatewaySupplier); }
PushGatewayPusherCreator implements MetricPusherCreator { public MetricPusher create(String address) { Supplier<PushGateway> pushGatewaySupplier = () -> { try { return new PushGateway(address); } catch (Exception e) { logger.error("PushGateway creation failed.", e); return null; } }; return create(pushGatewaySupplier); } }
PushGatewayPusherCreator implements MetricPusherCreator { public MetricPusher create(String address) { Supplier<PushGateway> pushGatewaySupplier = () -> { try { return new PushGateway(address); } catch (Exception e) { logger.error("PushGateway creation failed.", e); return null; } }; return create(pushGatewaySupplier); }  }
PushGatewayPusherCreator implements MetricPusherCreator { public MetricPusher create(String address) { Supplier<PushGateway> pushGatewaySupplier = () -> { try { return new PushGateway(address); } catch (Exception e) { logger.error("PushGateway creation failed.", e); return null; } }; return create(pushGatewaySupplier); }  MetricPusher create(String address); MetricPusher create(Supplier<PushGateway> pushGatewaySupplier); }
PushGatewayPusherCreator implements MetricPusherCreator { public MetricPusher create(String address) { Supplier<PushGateway> pushGatewaySupplier = () -> { try { return new PushGateway(address); } catch (Exception e) { logger.error("PushGateway creation failed.", e); return null; } }; return create(pushGatewaySupplier); }  MetricPusher create(String address); MetricPusher create(Supplier<PushGateway> pushGatewaySupplier);  }