Search in sources :

Example 36 with S3AsyncClient

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();
}
Also used : ChecksumMode(software.amazon.awssdk.services.s3.model.ChecksumMode) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WireMock.any(com.github.tomakehurst.wiremock.client.WireMock.any) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) Function(java.util.function.Function) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) AsyncResponseTransformer(software.amazon.awssdk.core.async.AsyncResponseTransformer) URI(java.net.URI) Region(software.amazon.awssdk.regions.Region) CaptureChecksumValidationInterceptor(software.amazon.awssdk.services.s3.utils.CaptureChecksumValidationInterceptor) ChecksumValidation(software.amazon.awssdk.core.checksums.ChecksumValidation) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) S3Client(software.amazon.awssdk.services.s3.S3Client) WireMockRuntimeInfo(com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) Algorithm(software.amazon.awssdk.core.checksums.Algorithm) S3ClientBuilder(software.amazon.awssdk.services.s3.S3ClientBuilder) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) WireMock.anyUrl(com.github.tomakehurst.wiremock.client.WireMock.anyUrl) BufferedReader(java.io.BufferedReader) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) InputStream(java.io.InputStream) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.jupiter.api.Test) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest)

Example 37 with S3AsyncClient

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();
}
Also used : ChecksumMode(software.amazon.awssdk.services.s3.model.ChecksumMode) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WireMock.any(com.github.tomakehurst.wiremock.client.WireMock.any) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) Function(java.util.function.Function) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) AsyncResponseTransformer(software.amazon.awssdk.core.async.AsyncResponseTransformer) URI(java.net.URI) Region(software.amazon.awssdk.regions.Region) CaptureChecksumValidationInterceptor(software.amazon.awssdk.services.s3.utils.CaptureChecksumValidationInterceptor) ChecksumValidation(software.amazon.awssdk.core.checksums.ChecksumValidation) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) S3Client(software.amazon.awssdk.services.s3.S3Client) WireMockRuntimeInfo(com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) Algorithm(software.amazon.awssdk.core.checksums.Algorithm) S3ClientBuilder(software.amazon.awssdk.services.s3.S3ClientBuilder) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) WireMock.anyUrl(com.github.tomakehurst.wiremock.client.WireMock.anyUrl) BufferedReader(java.io.BufferedReader) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) InputStream(java.io.InputStream) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.jupiter.api.Test) WireMockTest(com.github.tomakehurst.wiremock.junit5.WireMockTest)

Example 38 with S3AsyncClient

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);
}
Also used : CompletionException(java.util.concurrent.CompletionException) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.Test)

Example 39 with S3AsyncClient

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();
}
Also used : ListObjectsRequest(software.amazon.awssdk.services.s3.model.ListObjectsRequest) ListObjectsResponse(software.amazon.awssdk.services.s3.model.ListObjectsResponse)

Example 40 with S3AsyncClient

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();
    }
}
Also used : S3AsyncWaiter(software.amazon.awssdk.services.s3.waiters.S3AsyncWaiter) HeadBucketRequest(software.amazon.awssdk.services.s3.model.HeadBucketRequest) CreateBucketRequest(software.amazon.awssdk.services.s3.model.CreateBucketRequest)

Aggregations

S3AsyncClient (software.amazon.awssdk.services.s3.S3AsyncClient)28 Test (org.junit.Test)18 Region (software.amazon.awssdk.regions.Region)14 S3AsyncClientBuilder (software.amazon.awssdk.services.s3.S3AsyncClientBuilder)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)10 WireMock.any (com.github.tomakehurst.wiremock.client.WireMock.any)10 WireMock.anyUrl (com.github.tomakehurst.wiremock.client.WireMock.anyUrl)10 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)10 URI (java.net.URI)10 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)10 StaticCredentialsProvider (software.amazon.awssdk.auth.credentials.StaticCredentialsProvider)10 S3Client (software.amazon.awssdk.services.s3.S3Client)8 S3ClientBuilder (software.amazon.awssdk.services.s3.S3ClientBuilder)8 Collectors (java.util.stream.Collectors)7 GetObjectResponse (software.amazon.awssdk.services.s3.model.GetObjectResponse)7 WireMockRule (com.github.tomakehurst.wiremock.junit.WireMockRule)6 AsyncResponseTransformer (software.amazon.awssdk.core.async.AsyncResponseTransformer)6 InputStream (java.io.InputStream)5 ByteBuffer (java.nio.ByteBuffer)5