Search in sources :

Example 1 with NoHttpResponseException

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);
    }
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) NoHttpResponseException(org.apache.hc.core5.http.NoHttpResponseException) InetSocketAddress(java.net.InetSocketAddress) HttpGet(org.apache.hc.client5.http.classic.methods.HttpGet) HttpServer(com.sun.net.httpserver.HttpServer) HttpExchange(com.sun.net.httpserver.HttpExchange) NoHttpResponseException(org.apache.hc.core5.http.NoHttpResponseException) Test(org.junit.Test)

Aggregations

HttpExchange (com.sun.net.httpserver.HttpExchange)1 HttpServer (com.sun.net.httpserver.HttpServer)1 InetSocketAddress (java.net.InetSocketAddress)1 HttpGet (org.apache.hc.client5.http.classic.methods.HttpGet)1 HttpRequest (org.apache.hc.core5.http.HttpRequest)1 NoHttpResponseException (org.apache.hc.core5.http.NoHttpResponseException)1 Test (org.junit.Test)1