Search in sources :

Example 6 with ServerMetricsEvent

use of com.nike.riposte.server.metrics.ServerMetricsEvent in project riposte by Nike-Inc.

the class CodahaleMetricsListenerTest method onEvent_gracefully_handles_thrown_exceptions.

@Test
public void onEvent_gracefully_handles_thrown_exceptions() {
    // given
    ServerMetricsEvent event = ServerMetricsEvent.RESPONSE_SENT;
    RuntimeException ex = new RuntimeException("kaboom");
    doThrow(ex).when(listener.inflightRequests).dec();
    Logger loggerMock = mock(Logger.class);
    doReturn(false).when(loggerMock).isDebugEnabled();
    Whitebox.setInternalState(listener, "logger", loggerMock);
    // when
    listener.onEvent(event, state);
    // then
    // Should have blown up before the processedRequests stuff.
    verifyZeroInteractions(listener.processedRequests);
    verify(loggerMock).error("Metrics Error: ", ex);
}
Also used : ServerMetricsEvent(com.nike.riposte.server.metrics.ServerMetricsEvent) Logger(org.slf4j.Logger) Test(org.junit.Test)

Aggregations

ServerMetricsEvent (com.nike.riposte.server.metrics.ServerMetricsEvent)6 Test (org.junit.Test)6 Endpoint (com.nike.riposte.server.http.Endpoint)2 StandardEndpoint (com.nike.riposte.server.http.StandardEndpoint)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 Matchers.anyLong (org.mockito.Matchers.anyLong)2 Logger (org.slf4j.Logger)2 HttpMethod (io.netty.handler.codec.http.HttpMethod)1 Matchers.anyString (org.mockito.Matchers.anyString)1