use of software.amazon.awssdk.core.SdkResponse in project aws-sdk-java-v2 by aws.
the class AsyncClientHandlerTransformerVerificationTest method marshallerThrowsException_shouldTriggerExceptionOccurred.
@Test
public void marshallerThrowsException_shouldTriggerExceptionOccurred() {
SdkClientException exception = SdkClientException.create("Could not handle response");
when(marshaller.marshall(any(SdkRequest.class))).thenThrow(exception);
AtomicBoolean exceptionOccurred = new AtomicBoolean(false);
executeAndWaitError(new TestTransformer<SdkResponse, Void>() {
@Override
public void exceptionOccurred(Throwable error) {
exceptionOccurred.set(true);
super.exceptionOccurred(error);
}
});
assertThat(exceptionOccurred.get()).isTrue();
}
use of software.amazon.awssdk.core.SdkResponse in project aws-sdk-java-v2 by aws.
the class AsyncClientHandlerTransformerVerificationTest method prepareCallsEqualToExecuteAttempts.
@Test
public void prepareCallsEqualToExecuteAttempts() {
mockSuccessfulResponse();
AtomicLong prepareCalls = new AtomicLong(0);
executeAndWaitError(new TestTransformer<SdkResponse, Void>() {
@Override
public CompletableFuture<Void> prepare() {
prepareCalls.incrementAndGet();
return super.prepare();
}
@Override
public void onStream(SdkPublisher<ByteBuffer> stream) {
stream.subscribe(new DrainingSubscriber<ByteBuffer>() {
@Override
public void onComplete() {
transformFuture().completeExceptionally(RetryableException.builder().message("retry me please: " + prepareCalls.get()).build());
}
});
}
});
assertThat(prepareCalls.get()).isEqualTo(1 + RETRY_POLICY.numRetries());
}
use of software.amazon.awssdk.core.SdkResponse in project aws-sdk-java-v2 by aws.
the class AsyncClientHandlerTransformerVerificationTest method nonRetryableErrorDoesNotTriggerRetry.
@Test
public void nonRetryableErrorDoesNotTriggerRetry() {
mockSuccessfulResponse();
AtomicLong prepareCalls = new AtomicLong(0);
executeAndWaitError(new TestTransformer<SdkResponse, Void>() {
@Override
public CompletableFuture<Void> prepare() {
prepareCalls.incrementAndGet();
return super.prepare();
}
@Override
public void onStream(SdkPublisher<ByteBuffer> stream) {
super.transformFuture().completeExceptionally(new RuntimeException("some error"));
}
});
assertThat(prepareCalls.get()).isEqualTo(1L);
}
use of software.amazon.awssdk.core.SdkResponse in project aws-sdk-java-v2 by aws.
the class BaseAsyncClientHandler method execute.
@Override
public <InputT extends SdkRequest, OutputT extends SdkResponse, ReturnT> CompletableFuture<ReturnT> execute(ClientExecutionParams<InputT, OutputT> executionParams, AsyncResponseTransformer<OutputT, ReturnT> asyncResponseTransformer) {
return measureApiCallSuccess(executionParams, () -> {
if (executionParams.getCombinedResponseHandler() != null) {
// attempt to do this.
throw new IllegalArgumentException("A streaming 'asyncResponseTransformer' may not be used when a " + "'combinedResponseHandler' has been specified in a " + "ClientExecutionParams object.");
}
ExecutionAttributes executionAttributes = executionParams.executionAttributes();
executionAttributes.putAttribute(InternalCoreExecutionAttribute.EXECUTION_ATTEMPT, 1);
AsyncStreamingResponseHandler<OutputT, ReturnT> asyncStreamingResponseHandler = new AsyncStreamingResponseHandler<>(asyncResponseTransformer);
// For streaming requests, prepare() should be called as early as possible to avoid NPE in client
// See https://github.com/aws/aws-sdk-java-v2/issues/1268. We do this with a wrapper that caches the prepare
// result until the execution attempt number changes. This guarantees that prepare is only called once per
// execution.
TransformingAsyncResponseHandler<ReturnT> wrappedAsyncStreamingResponseHandler = IdempotentAsyncResponseHandler.create(asyncStreamingResponseHandler, () -> executionAttributes.getAttribute(InternalCoreExecutionAttribute.EXECUTION_ATTEMPT), Integer::equals);
wrappedAsyncStreamingResponseHandler.prepare();
// Running beforeExecution interceptors and modifyRequest interceptors.
ExecutionContext context = invokeInterceptorsAndCreateExecutionContext(executionParams);
HttpResponseHandler<OutputT> decoratedResponseHandlers = decorateResponseHandlers(executionParams.getResponseHandler(), context);
asyncStreamingResponseHandler.responseHandler(decoratedResponseHandlers);
TransformingAsyncResponseHandler<? extends SdkException> errorHandler = resolveErrorResponseHandler(executionParams.getErrorResponseHandler(), context, crc32Validator);
TransformingAsyncResponseHandler<Response<ReturnT>> combinedResponseHandler = new CombinedResponseAsyncHttpResponseHandler<>(wrappedAsyncStreamingResponseHandler, errorHandler);
return doExecute(executionParams, context, combinedResponseHandler);
});
}
use of software.amazon.awssdk.core.SdkResponse in project aws-sdk-java-v2 by aws.
the class BaseAsyncClientHandler method execute.
@Override
public <InputT extends SdkRequest, OutputT extends SdkResponse> CompletableFuture<OutputT> execute(ClientExecutionParams<InputT, OutputT> executionParams) {
return measureApiCallSuccess(executionParams, () -> {
// Running beforeExecution interceptors and modifyRequest interceptors.
ExecutionContext executionContext = invokeInterceptorsAndCreateExecutionContext(executionParams);
TransformingAsyncResponseHandler<Response<OutputT>> combinedResponseHandler = createCombinedResponseHandler(executionParams, executionContext);
return doExecute(executionParams, executionContext, combinedResponseHandler);
});
}
Aggregations