use of software.amazon.awssdk.core.client.handler.SdkAsyncClientHandler in project aws-sdk-java-v2 by aws.
the class AsyncClientHandlerExceptionTest method methodSetup.
@BeforeEach
public void methodSetup() throws Exception {
executionParams = new ClientExecutionParams<SdkRequest, SdkResponse>().withInput(request).withMarshaller(marshaller).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler);
SdkClientConfiguration config = HttpTestUtils.testClientConfiguration().toBuilder().option(SdkClientOption.ASYNC_HTTP_CLIENT, asyncHttpClient).option(SdkClientOption.RETRY_POLICY, RetryPolicy.none()).option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, Runnable::run).build();
clientHandler = new SdkAsyncClientHandler(config);
when(request.overrideConfiguration()).thenReturn(Optional.empty());
when(marshaller.marshall(eq(request))).thenReturn(ValidSdkObjects.sdkHttpFullRequest().build());
when(responseHandler.handle(any(SdkHttpFullResponse.class), any(ExecutionAttributes.class))).thenReturn(VoidSdkResponse.builder().build());
when(asyncHttpClient.execute(any(AsyncExecuteRequest.class))).thenAnswer((Answer<CompletableFuture<Void>>) invocationOnMock -> {
SdkAsyncHttpResponseHandler handler = invocationOnMock.getArgument(0, AsyncExecuteRequest.class).responseHandler();
handler.onHeaders(SdkHttpFullResponse.builder().statusCode(200).build());
handler.onStream(new EmptyPublisher<>());
return CompletableFuture.completedFuture(null);
});
}
use of software.amazon.awssdk.core.client.handler.SdkAsyncClientHandler in project aws-sdk-java-v2 by aws.
the class AsyncClientHandlerInterceptorExceptionTest method testSetup.
@Before
public void testSetup() throws Exception {
executionParams = new ClientExecutionParams<SdkRequest, SdkResponse>().withInput(request).withMarshaller(marshaller).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler);
SdkClientConfiguration config = HttpTestUtils.testClientConfiguration().toBuilder().option(SdkClientOption.EXECUTION_INTERCEPTORS, Collections.singletonList(hook.interceptor())).option(SdkClientOption.ASYNC_HTTP_CLIENT, asyncHttpClient).option(SdkClientOption.RETRY_POLICY, RetryPolicy.none()).option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, Runnable::run).build();
clientHandler = new SdkAsyncClientHandler(config);
when(request.overrideConfiguration()).thenReturn(Optional.empty());
when(marshaller.marshall(eq(request))).thenReturn(ValidSdkObjects.sdkHttpFullRequest().build());
when(responseHandler.handle(any(SdkHttpFullResponse.class), any(ExecutionAttributes.class))).thenReturn(VoidSdkResponse.builder().build());
Answer<CompletableFuture<Void>> prepareRequestAnswer;
if (hook != Hook.ON_EXECUTION_FAILURE) {
prepareRequestAnswer = invocationOnMock -> {
SdkAsyncHttpResponseHandler handler = invocationOnMock.getArgument(0, AsyncExecuteRequest.class).responseHandler();
handler.onHeaders(SdkHttpFullResponse.builder().statusCode(200).build());
handler.onStream(new EmptyPublisher<>());
return CompletableFuture.completedFuture(null);
};
} else {
prepareRequestAnswer = invocationOnMock -> {
SdkAsyncHttpResponseHandler handler = invocationOnMock.getArgument(0, AsyncExecuteRequest.class).responseHandler();
RuntimeException error = new RuntimeException("Something went horribly wrong!");
handler.onError(error);
return CompletableFutureUtils.failedFuture(error);
};
}
when(asyncHttpClient.execute(any(AsyncExecuteRequest.class))).thenAnswer(prepareRequestAnswer);
}
Aggregations