use of org.apache.hc.core5.http.NoHttpResponseException in project metrics by dropwizard.
the class InstrumentedHttpClientsTest method registersExpectedExceptionMetrics.
@Test
public void registersExpectedExceptionMetrics() throws Exception {
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
final HttpGet get = new HttpGet("http://localhost:" + httpServer.getAddress().getPort() + "/");
final String requestMetricName = "request";
final String exceptionMetricName = "exception";
httpServer.createContext("/", HttpExchange::close);
httpServer.start();
when(metricNameStrategy.getNameFor(any(), any(HttpRequest.class))).thenReturn(requestMetricName);
when(metricNameStrategy.getNameFor(any(), any(Exception.class))).thenReturn(exceptionMetricName);
try {
client.execute(get);
fail();
} catch (NoHttpResponseException expected) {
assertThat(metricRegistry.getMeters()).containsKey("exception");
} finally {
httpServer.stop(0);
}
}
Aggregations