Search in sources :

Example 31 with S3AsyncClient

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();
}
Also used : S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) AfterAll(org.junit.jupiter.api.AfterAll)

Example 32 with S3AsyncClient

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);
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WireMock.any(com.github.tomakehurst.wiremock.client.WireMock.any) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) ByteBuffer(java.nio.ByteBuffer) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) URI(java.net.URI) Region(software.amazon.awssdk.regions.Region) Subscriber(org.reactivestreams.Subscriber) PutObjectResponse(software.amazon.awssdk.services.s3.model.PutObjectResponse) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Test(org.junit.Test) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.putRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) Optional(java.util.Optional) WireMock.anyUrl(com.github.tomakehurst.wiremock.client.WireMock.anyUrl) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) PutObjectResponse(software.amazon.awssdk.services.s3.model.PutObjectResponse) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.Test)

Example 33 with S3AsyncClient

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");
}
Also used : Subscriber(org.reactivestreams.Subscriber) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) ExecutionException(java.util.concurrent.ExecutionException) ByteBuffer(java.nio.ByteBuffer) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.Test)

Example 34 with S3AsyncClient

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);
}
Also used : S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) S3Client(software.amazon.awssdk.services.s3.S3Client) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WireMock.any(com.github.tomakehurst.wiremock.client.WireMock.any) Test(org.junit.Test) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) Rule(org.junit.Rule) GetBucketPolicyResponse(software.amazon.awssdk.services.s3.model.GetBucketPolicyResponse) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) S3ClientBuilder(software.amazon.awssdk.services.s3.S3ClientBuilder) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) WireMock.anyUrl(com.github.tomakehurst.wiremock.client.WireMock.anyUrl) URI(java.net.URI) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) GetBucketPolicyResponse(software.amazon.awssdk.services.s3.model.GetBucketPolicyResponse) Test(org.junit.Test)

Example 35 with S3AsyncClient

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");
    }
}
Also used : BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ResponsePublisher(software.amazon.awssdk.core.async.ResponsePublisher) S3BucketUtils.temporaryBucketName(software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName) CompletableFuture(java.util.concurrent.CompletableFuture) ByteBuffer(java.nio.ByteBuffer) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) Context(software.amazon.awssdk.core.interceptor.Context) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) AsyncResponseTransformer(software.amazon.awssdk.core.async.AsyncResponseTransformer) Path(java.nio.file.Path) AfterClass(org.junit.AfterClass) ImmutableMap(software.amazon.awssdk.utils.ImmutableMap) Files(java.nio.file.Files) IOException(java.io.IOException) Test(org.junit.Test) SdkPublisher(software.amazon.awssdk.core.async.SdkPublisher) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) SimpleSubscriber(software.amazon.awssdk.http.async.SimpleSubscriber) SdkResponse(software.amazon.awssdk.core.SdkResponse) RandomTempFile(software.amazon.awssdk.testutils.RandomTempFile) Assert.assertEquals(org.junit.Assert.assertEquals) ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncResponseTransformer(software.amazon.awssdk.core.async.AsyncResponseTransformer) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) SdkPublisher(software.amazon.awssdk.core.async.SdkPublisher) SimpleSubscriber(software.amazon.awssdk.http.async.SimpleSubscriber) Test(org.junit.Test)

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