Skip to content

Commit 8c192e3

Browse files
committed
Additional tests for IOException for core metrics
1 parent 6c88840 commit 8c192e3

File tree

1 file changed

+56
-6
lines changed
  • test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/metrics

1 file changed

+56
-6
lines changed

test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/metrics/CoreMetricsTest.java

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.services.metrics;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.hamcrest.Matchers.is;
1920
import static org.mockito.Matchers.any;
2021
import static org.mockito.Mockito.mock;
2122
import static org.mockito.Mockito.verify;
@@ -232,17 +233,66 @@ public void testApiCall_clientSideExceptionThrown_includedInMetrics() {
232233
when(mockHttpClient.prepareRequest(any(HttpExecuteRequest.class))).thenThrow(new RuntimeException("oops"));
233234

234235
thrown.expect(RuntimeException.class);
236+
try {
237+
client.allTypes();
238+
} finally {
235239

236-
client.allTypes();
240+
ArgumentCaptor<MetricCollection> collectionCaptor = ArgumentCaptor.forClass(MetricCollection.class);
241+
verify(mockPublisher).publish(collectionCaptor.capture());
237242

238-
ArgumentCaptor<MetricCollection> collectionCaptor = ArgumentCaptor.forClass(MetricCollection.class);
239-
verify(mockPublisher).publish(collectionCaptor.capture());
243+
MetricCollection capturedCollection = collectionCaptor.getValue();
240244

241-
MetricCollection capturedCollection = collectionCaptor.getValue();
245+
MetricCollection requestMetrics = capturedCollection.children().get(0);
242246

243-
MetricCollection requestMetrics = capturedCollection.children().get(0);
247+
assertThat(requestMetrics.metricValues(CoreMetric.EXCEPTION).get(0))
248+
.isExactlyInstanceOf(RuntimeException.class);
249+
}
250+
}
251+
252+
@Test
253+
public void testApiCall_requestExecutionThrowsClientSideException_includedInMetrics() throws IOException {
254+
IOException ioe = new IOException("oops");
255+
ExecutableHttpRequest mockExecutableRequest = mock(ExecutableHttpRequest.class);
256+
when(mockExecutableRequest.call()).thenThrow(ioe);
244257

245-
assertThat(requestMetrics.metricValues(CoreMetric.EXCEPTION).get(0)).isExactlyInstanceOf(RuntimeException.class);
258+
when(mockHttpClient.prepareRequest(any(HttpExecuteRequest.class))).thenReturn(mockExecutableRequest);
259+
260+
thrown.expectCause(is(ioe));
261+
try {
262+
client.allTypes();
263+
} finally {
264+
ArgumentCaptor<MetricCollection> collectionCaptor = ArgumentCaptor.forClass(MetricCollection.class);
265+
verify(mockPublisher).publish(collectionCaptor.capture());
266+
267+
MetricCollection callMetrics = collectionCaptor.getValue();
268+
MetricCollection attemptMetrics = callMetrics.children().get(0);
269+
270+
assertThat(attemptMetrics.metricValues(CoreMetric.EXCEPTION)).containsExactly(ioe);
271+
}
272+
}
273+
274+
@Test
275+
public void testApiCall_streamingOutput_transformerThrows_includedInMetrics() throws IOException {
276+
IOException ioe = new IOException("oops");
277+
ExecutableHttpRequest mockExecutableRequest = mock(ExecutableHttpRequest.class);
278+
when(mockExecutableRequest.call()).thenThrow(ioe);
279+
280+
when(mockHttpClient.prepareRequest(any(HttpExecuteRequest.class))).thenReturn(mockExecutableRequest);
281+
282+
thrown.expectCause(is(ioe));
283+
try {
284+
client.streamingOutputOperation(req -> {}, (response, is) -> {
285+
throw ioe;
286+
});
287+
} finally {
288+
ArgumentCaptor<MetricCollection> collectionCaptor = ArgumentCaptor.forClass(MetricCollection.class);
289+
verify(mockPublisher).publish(collectionCaptor.capture());
290+
291+
MetricCollection callMetrics = collectionCaptor.getValue();
292+
MetricCollection attemptMetrics = callMetrics.children().get(0);
293+
294+
assertThat(attemptMetrics.metricValues(CoreMetric.EXCEPTION)).containsExactly(ioe);
295+
}
246296
}
247297

248298
private static HttpExecuteResponse mockExecuteResponse(SdkHttpFullResponse httpResponse) {

0 commit comments

Comments
 (0)