use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method async_getObject_with_validation_enabled_no_http_checksum.
@Test
public void async_getObject_with_validation_enabled_no_http_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(EXAMPLE_RESPONSE_BODY)));
S3AsyncClient s3Client = getAsyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
String response = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key").checksumMode(ChecksumMode.ENABLED), AsyncResponseTransformer.toBytes()).join().asUtf8String();
assertThat(response).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isEqualTo(ChecksumValidation.CHECKSUM_ALGORITHM_NOT_FOUND);
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isNull();
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method async_getObject_with_validation_not_enabled_incorrect_http_checksum.
@Test
public void async_getObject_with_validation_not_enabled_incorrect_http_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("x-amz-checksum-crc32", "incorrect").withBody(EXAMPLE_RESPONSE_BODY)));
S3AsyncClient s3Client = getAsyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
String response = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key"), AsyncResponseTransformer.toBytes()).join().asUtf8String();
assertThat(response).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isNull();
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isNull();
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class CompleteMultipartUploadFunctionalTest method completeMultipartUpload_asyncClient_errorInResponseBody_invalidErrorXml.
@Test
public void completeMultipartUpload_asyncClient_errorInResponseBody_invalidErrorXml() {
String bucket = "Example-Bucket";
String key = "Example-Object";
String xmlResponseBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Error>\n" + "<SomethingWeird></SomethingWeird>" + "</Error>";
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(xmlResponseBody)));
S3AsyncClient s3Client = getAsyncClientBuilder().build();
assertThatThrownBy(() -> s3Client.completeMultipartUpload(r -> r.bucket(bucket).key(key).uploadId("upload-id")).join()).isInstanceOf(CompletionException.class).hasCauseInstanceOf(S3Exception.class);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project flink by splunk.
the class AWSServicesTestUtils method listBucketObjects.
public static List<S3Object> listBucketObjects(S3AsyncClient s3, String bucketName) throws ExecutionException, InterruptedException {
ListObjectsRequest listObjects = ListObjectsRequest.builder().bucket(bucketName).build();
CompletableFuture<ListObjectsResponse> res = s3.listObjects(listObjects);
return res.get().contents();
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project flink by splunk.
the class AWSServicesTestUtils method createBucket.
public static void createBucket(S3AsyncClient s3Client, String bucketName) throws ExecutionException, InterruptedException {
CreateBucketRequest bucketRequest = CreateBucketRequest.builder().bucket(bucketName).build();
s3Client.createBucket(bucketRequest);
HeadBucketRequest bucketRequestWait = HeadBucketRequest.builder().bucket(bucketName).build();
try (final S3AsyncWaiter waiter = s3Client.waiter()) {
waiter.waitUntilBucketExists(bucketRequestWait).get();
}
}
Aggregations