PrometheusPullServer implements PrometheusExporter { @Override public void quit() { this.server.stop(); } PrometheusPullServer(int pullingPort, CollectorRegistry registry); @Override void flush(); @Override void quit();  }
@Test public void testConstructor() throws IOException { int port = 8181; String counterName = "constructor_test_total"; String counterHelp = "constructor_test_help"; double counterValue = 1234.6789; CollectorRegistry registry = new CollectorRegistry(); Counter counter = Counter.build().name(counterName).help(counterHelp).register(registry); counter.inc(counterValue); String expectedResponseText = String.join( "\n", String.format("# HELP %s %s", counterName, counterHelp), String.format("# TYPE %s %s", counterName, counter.getClass().getSimpleName().toLowerCase()), String.format("%s %.4f", counterName, counterValue) ); PrometheusPullServer exporter = null; try { exporter = new PrometheusPullServer(port, registry); HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(String.format("http: HttpResponse response = client.execute(request); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String responseText = rd.lines().collect(Collectors.joining("\n")); Assert.assertEquals(responseText, expectedResponseText); } finally { if (exporter != null) { exporter.quit(); } } }
@Test(expectedExceptions = { HttpHostConnectException.class }, expectedExceptionsMessageRegExp = ".* failed: Connection refused \\(Connection refused\\)") public void testQuit() throws IOException { int port = 8181; CollectorRegistry registry = new CollectorRegistry(); PrometheusPullServer exporter = new PrometheusPullServer(port, registry); exporter.quit(); HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(String.format("http: client.execute(request); }