use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class S3CrtAsyncClientStabilityTest method cleanup.
@AfterAll
public static void cleanup() {
try (S3AsyncClient s3NettyClient = S3AsyncClient.builder().httpClientBuilder(NettyNioAsyncHttpClient.builder().maxConcurrency(CONCURRENCY)).credentialsProvider(CREDENTIALS_PROVIDER_CHAIN).build()) {
deleteBucketAndAllContents(s3NettyClient, BUCKET_NAME);
}
s3CrtAsyncClient.close();
s3ApacheClient.close();
CrtResource.waitForNoResources();
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class ContentLengthMismatchTest method checksumDoesNotExceedContentLengthHeaderForPuts.
@Test
public void checksumDoesNotExceedContentLengthHeaderForPuts() {
String bucket = "Example-Bucket";
String key = "Example-Object";
String content = "Hello, World!";
String eTag = "65A8E27D8879283831B664BD8B7F0AD4";
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("ETag", eTag)));
S3AsyncClient s3Client = getAsyncClientBuilder().build();
PutObjectResponse response = s3Client.putObject(r -> r.bucket(bucket).key(key).contentLength((long) content.length()), AsyncRequestBody.fromString(content + " Extra stuff!")).join();
verify(putRequestedFor(anyUrl()).withRequestBody(equalTo(content)));
assertThat(response.eTag()).isEqualTo(eTag);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class ContentLengthMismatchTest method contentShorterThanContentLengthHeaderFails.
@Test
public void contentShorterThanContentLengthHeaderFails() {
String bucket = "Example-Bucket";
String key = "Example-Object";
S3AsyncClient s3Client = getAsyncClientBuilder().build();
AsyncRequestBody requestBody = new AsyncRequestBody() {
@Override
public Optional<Long> contentLength() {
return Optional.empty();
}
@Override
public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
AsyncRequestBody.fromString("A").subscribe(subscriber);
}
};
assertThatThrownBy(() -> s3Client.putObject(r -> r.bucket(bucket).key(key).contentLength(2L), requestBody).get(10, TimeUnit.SECONDS)).isInstanceOf(ExecutionException.class).hasMessageContaining("content-length");
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class GetBucketPolicyFunctionalTest method getBucketPolicy_asyncClient.
@Test
public void getBucketPolicy_asyncClient() {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(EXAMPLE_POLICY)));
S3AsyncClient s3Client = getAsyncClientBuilder().build();
GetBucketPolicyResponse response = s3Client.getBucketPolicy(r -> r.bucket(EXAMPLE_BUCKET)).join();
assertThat(response.policy()).isEqualTo(EXAMPLE_POLICY);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class GetObjectAsyncIntegrationTest method customResponseHandler_InterceptorRecievesResponsePojo.
@Test
public void customResponseHandler_InterceptorRecievesResponsePojo() throws Exception {
final CompletableFuture<String> cf = new CompletableFuture<>();
try (S3AsyncClient asyncWithInterceptor = createClientWithInterceptor(new AssertingExecutionInterceptor())) {
String result = asyncWithInterceptor.getObject(getObjectRequest, new AsyncResponseTransformer<GetObjectResponse, String>() {
@Override
public CompletableFuture<String> prepare() {
return cf;
}
@Override
public void onResponse(GetObjectResponse response) {
// POJO returned by modifyResponse should be delivered to the AsyncResponseTransformer
assertThat(response.metadata()).hasEntrySatisfying("x-amz-assert", s -> assertThat(s).isEqualTo("injected-value"));
}
@Override
public void onStream(SdkPublisher<ByteBuffer> publisher) {
publisher.subscribe(new SimpleSubscriber(b -> {
}) {
@Override
public void onComplete() {
super.onComplete();
cf.complete("result");
}
});
}
@Override
public void exceptionOccurred(Throwable throwable) {
cf.completeExceptionally(throwable);
}
}).join();
assertThat(result).isEqualTo("result");
}
}
Aggregations