RpcServerMetricsCollector { public void requestCompletedExceptionally(Timer.Context context, Object destination, Throwable error) { if (context != null) { context.stop(); } Meter specificMeter = metrics.getMeter(identifierPrefix, "error", destination == null ? null : String.valueOf(destination)); specificMeter.mark(); totalNumberOfErrorRequests.mark(); } RpcServerMetricsCollector(String identifier, Metrics metrics); Timer.Context requestReceived(Object destination); void requestCompleted(Timer.Context context, Object reply); void requestCompletedExceptionally(Timer.Context context, Object destination, Throwable error);  }
@Test void requestCompletedExceptionally() { sut.requestCompletedExceptionally(metrics.getTimer("foo").time(), "req3", new RuntimeException("4 test")); assertThat(metrics.getMeter("rpcServer.requests.total").getCount(), Matchers.is(0L)); assertThat(metrics.getTimer("rpcServer.requests.req3").getCount(), Matchers.is(0L)); assertThat(metrics.getMeter("rpcServer.completed.total").getCount(), Matchers.is(0L)); assertThat(metrics.getMeter("rpcServer.error.total").getCount(), Matchers.is(1L)); assertThat(metrics.getMeter("rpcServer.error.req3").getCount(), Matchers.is(1L)); }
@Test void requestCompletedExceptionallyWithNullDestinationPossible() { sut.requestCompletedExceptionally(metrics.getTimer("foo").time(), null, null); assertThat(metrics.getMeter("rpcServer.requests.total").getCount(), Matchers.is(0L)); assertThat(metrics.getTimer("rpcServer.requests").getCount(), Matchers.is(0L)); assertThat(metrics.getMeter("rpcServer.completed.total").getCount(), Matchers.is(0L)); assertThat(metrics.getMeter("rpcServer.timeout.total").getCount(), Matchers.is(0L)); assertThat(metrics.getMeter("rpcServer.error.total").getCount(), Matchers.is(1L)); }