ClientSideMonitoringRequestHandler extends RequestHandler2 { @Override public void afterResponse(Request<?> request, Response<?> response) { ApiCallMonitoringEvent event = generateApiCallMonitoringEvent(request); handToMonitoringListeners(event); } ClientSideMonitoringRequestHandler(String clientId, Collection<MonitoringListener> monitoringListeners); @Override void afterAttempt(HandlerAfterAttemptContext context); @Override void afterResponse(Request<?> request, Response<?> response); @Override void afterError(Request<?> request, Response<?> response, Exception e);  }
@Test public void afterResponse_shouldSendApiCallMonitoringEvent() { Request<?> request = getRequest(); AWSRequestMetrics metrics = getMetrics(3); request.setAWSRequestMetrics(metrics); requestHandler.afterResponse(request, getResponse(request)); ArgumentCaptor<ApiCallMonitoringEvent> monitoringEventArgumentCaptor = ArgumentCaptor.forClass(ApiCallMonitoringEvent.class); verify(agentMonitoringListener, times(1)).handleEvent(monitoringEventArgumentCaptor.capture()); verify(customMonitoringListener, times(1)).handleEvent(any(ApiCallMonitoringEvent.class)); ApiCallMonitoringEvent event = monitoringEventArgumentCaptor.getValue(); verifyApiCallMonitoringEvent(3, event); }
@Test public void afterResponse_customMonitoringListenerThrowException_shouldNotAffectAgentListener() { Request<?> request = getRequest(); Response<?> response = getResponse(request); doThrow(new RuntimeException("Oops")).when(customMonitoringListener).handleEvent(any(ApiMonitoringEvent.class)); requestHandler.afterResponse(request, response); verify(agentMonitoringListener, times(1)).handleEvent(any(ApiMonitoringEvent.class)); verify(customMonitoringListener, times(1)).handleEvent(any(ApiMonitoringEvent.class)); }