use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class Aws4EventStreamSignerTest method testBackPressure.
/**
* Test that without demand from subscriber, trailing empty frame is not delivered
*/
@Test
public void testBackPressure() {
TestVector testVector = generateTestVector();
SdkHttpFullRequest.Builder request = testVector.httpFullRequest();
AwsBasicCredentials credentials = AwsBasicCredentials.create("access", "secret");
SdkHttpFullRequest signedRequest = SignerTestUtils.signRequest(signer, request.build(), credentials, "demo", signingClock(), "us-east-1");
AsyncRequestBody transformedPublisher = SignerTestUtils.signAsyncRequest(signer, signedRequest, testVector.requestBodyPublisher(), credentials, "demo", signingClock(), "us-east-1");
Subscriber<Object> subscriber = Mockito.spy(new Subscriber<Object>() {
@Override
public void onSubscribe(Subscription s) {
// Only request the number of request body (excluding trailing empty frame)
s.request(testVector.requestBody().size());
}
@Override
public void onNext(Object o) {
}
@Override
public void onError(Throwable t) {
fail("onError should never been called");
}
@Override
public void onComplete() {
fail("onComplete should never been called");
}
});
Flowable.fromPublisher(transformedPublisher).flatMap(new Function<ByteBuffer, Publisher<?>>() {
Queue<Message> messages = new LinkedList<>();
MessageDecoder decoder = new MessageDecoder(message -> messages.offer(message));
@Override
public Publisher<?> apply(ByteBuffer byteBuffer) throws Exception {
decoder.feed(byteBuffer.array());
List<Message> messageList = new ArrayList<>();
while (!messages.isEmpty()) {
messageList.add(messages.poll());
}
return Flowable.fromIterable(messageList);
}
}).subscribe(subscriber);
// The number of events equal to the size of request body (excluding trailing empty frame)
verify(subscriber, times(testVector.requestBody().size())).onNext(any());
// subscriber is not terminated (no onError/onComplete) since trailing empty frame is not delivered yet
verify(subscriber, never()).onError(any());
verify(subscriber, never()).onComplete();
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class NonStreamingAsyncBodyAws4SignerTest method test_sign_futureCancelled_propagatedToPublisher.
@Test
void test_sign_futureCancelled_propagatedToPublisher() {
SdkHttpFullRequest httpRequest = SdkHttpFullRequest.builder().protocol("https").host("my-cool-aws-service.us-west-2.amazonaws.com").method(SdkHttpMethod.GET).putHeader("header1", "headerval1").build();
AwsCredentials credentials = AwsBasicCredentials.create("akid", "skid");
Aws4SignerParams signerParams = Aws4SignerParams.builder().awsCredentials(credentials).signingClockOverride(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC"))).signingName("my-cool-aws-service").signingRegion(Region.US_WEST_2).build();
AsyncRequestBody mockRequestBody = mock(AsyncRequestBody.class);
Subscription mockSubscription = mock(Subscription.class);
doAnswer((Answer<Void>) invocationOnMock -> {
Subscriber subscriber = invocationOnMock.getArgument(0, Subscriber.class);
subscriber.onSubscribe(mockSubscription);
return null;
}).when(mockRequestBody).subscribe(any(Subscriber.class));
AsyncAws4Signer asyncAws4Signer = AsyncAws4Signer.create();
CompletableFuture<SdkHttpFullRequest> signedRequestFuture = asyncAws4Signer.signWithBody(httpRequest, mockRequestBody, signerParams);
signedRequestFuture.cancel(true);
verify(mockSubscription).cancel();
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class ExecutionInterceptorChain method modifyHttpRequestAndHttpContent.
public InterceptorContext modifyHttpRequestAndHttpContent(InterceptorContext context, ExecutionAttributes executionAttributes) {
InterceptorContext result = context;
for (ExecutionInterceptor interceptor : interceptors) {
AsyncRequestBody asyncRequestBody = interceptor.modifyAsyncHttpContent(result, executionAttributes).orElse(null);
RequestBody requestBody = interceptor.modifyHttpContent(result, executionAttributes).orElse(null);
SdkHttpRequest interceptorResult = interceptor.modifyHttpRequest(result, executionAttributes);
validateInterceptorResult(result.httpRequest(), interceptorResult, interceptor, "modifyHttpRequest");
result = applySdkHttpFullRequestHack(result);
result = result.copy(b -> b.httpRequest(interceptorResult).asyncRequestBody(asyncRequestBody).requestBody(requestBody));
}
return result;
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class SignedAsyncRequestBodyUploadIntegrationTest method setup.
@BeforeClass
public static void setup() throws Exception {
S3IntegrationTestBase.setUp();
// Use a mock so we can introspect easily to verify that the signer was used for the request
mockSigner = mock(TestSigner.class);
AsyncAws4Signer realSigner = AsyncAws4Signer.create();
when(mockSigner.sign(any(SdkHttpFullRequest.class), any(AsyncRequestBody.class), any(ExecutionAttributes.class))).thenAnswer(i -> {
SdkHttpFullRequest request = i.getArgument(0, SdkHttpFullRequest.class);
AsyncRequestBody body = i.getArgument(1, AsyncRequestBody.class);
ExecutionAttributes executionAttributes = i.getArgument(2, ExecutionAttributes.class);
return realSigner.sign(request, body, executionAttributes);
});
testClient = s3AsyncClientBuilder().overrideConfiguration(o -> o.putAdvancedOption(SIGNER, mockSigner).addExecutionInterceptor(capturingInterceptor)).build();
createBucket(BUCKET);
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class ChecksumCalculatingAsyncRequestBodyTest method fileConstructorHasCorrectContentType.
@Test
public void fileConstructorHasCorrectContentType() {
AsyncRequestBody requestBody = ChecksumCalculatingAsyncRequestBody.builder().asyncRequestBody(AsyncRequestBody.fromFile(path)).algorithm(Algorithm.CRC32).trailerHeader("x-amz-checksum-crc32").build();
assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM);
}
Aggregations