public static HttpAsyncClientBuilder custom(MetricRegistry metricRegistry) {
        return custom(metricRegistry, METHOD_ONLY);
    }
@Test
    public void registersExpectedExceptionMetrics() throws Exception {
        client = InstrumentedHttpAsyncClients.custom(metricRegistry, metricNameStrategy).disableAutomaticRetries().build();
        client.start();

        final CountDownLatch countDownLatch = new CountDownLatch(1);
        final SimpleHttpRequest request = SimpleRequestBuilder
                .get("http://localhost:" + httpServer.getAddress().getPort() + "/")
                .build();
        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 {
            final Future<SimpleHttpResponse> responseFuture = client.execute(request, new FutureCallback<SimpleHttpResponse>() {
                @Override
                public void completed(SimpleHttpResponse result) {
                    fail();
                }

                @Override
                public void failed(Exception ex) {
                    countDownLatch.countDown();
                }

                @Override
                public void cancelled() {
                    fail();
                }
            });
            countDownLatch.await(5, TimeUnit.SECONDS);
            responseFuture.get(5, TimeUnit.SECONDS);

            fail();
        } catch (ExecutionException e) {
            assertThat(e).hasCauseInstanceOf(ConnectionClosedException.class);
            await().atMost(5, TimeUnit.SECONDS)
                    .untilAsserted(() -> assertThat(metricRegistry.getMeters()).containsKey("exception"));
        }
    }