This is an automated email from the ASF dual-hosted git repository. ppalaga pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 68777929af1a0d53be8b699f1c203dbe43395242 Author: Peter Palaga <[email protected]> AuthorDate: Tue Feb 23 16:02:28 2021 +0100 Simplify the client creation in KinesisTest --- .../component/aws2/kinesis/it/Aws2KinesisTest.java | 77 ++++++++++------------ 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/integration-tests-aws2/aws2-kinesis/src/test/java/org/apache/camel/quarkus/component/aws2/kinesis/it/Aws2KinesisTest.java b/integration-tests-aws2/aws2-kinesis/src/test/java/org/apache/camel/quarkus/component/aws2/kinesis/it/Aws2KinesisTest.java index d093e10..cfc8a43 100644 --- a/integration-tests-aws2/aws2-kinesis/src/test/java/org/apache/camel/quarkus/component/aws2/kinesis/it/Aws2KinesisTest.java +++ b/integration-tests-aws2/aws2-kinesis/src/test/java/org/apache/camel/quarkus/component/aws2/kinesis/it/Aws2KinesisTest.java @@ -16,7 +16,6 @@ */ package org.apache.camel.quarkus.component.aws2.kinesis.it; -import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.concurrent.TimeUnit; @@ -25,6 +24,7 @@ import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; +import org.apache.camel.quarkus.test.support.aws2.Aws2Client; import org.apache.camel.quarkus.test.support.aws2.Aws2TestResource; import org.apache.commons.lang3.RandomStringUtils; import org.awaitility.Awaitility; @@ -33,12 +33,9 @@ import org.eclipse.microprofile.config.ConfigProvider; import org.hamcrest.Matchers; import org.jboss.logging.Logger; import org.junit.jupiter.api.Test; -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; -import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import org.testcontainers.containers.localstack.LocalStackContainer.Service; import software.amazon.awssdk.core.ResponseInputStream; -import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.s3.S3Client; -import software.amazon.awssdk.services.s3.S3ClientBuilder; import software.amazon.awssdk.services.s3.model.GetObjectRequest; import software.amazon.awssdk.services.s3.model.GetObjectResponse; import software.amazon.awssdk.services.s3.model.ListObjectsRequest; @@ -51,6 +48,9 @@ class Aws2KinesisTest { private static final Logger LOG = Logger.getLogger(Aws2KinesisTest.class); + @Aws2Client(Service.S3) + S3Client client; + @Test public void kinesis() { final String msg = "kinesis-" + java.util.UUID.randomUUID().toString().replace("-", ""); @@ -77,8 +77,10 @@ class Aws2KinesisTest { + msgPrefix + "..."); final long deadline = System.currentTimeMillis() + (Aws2KinesisTestEnvCustomizer.BUFFERING_TIME_SEC * 1000); while (bytesSent < maxDataBytes && System.currentTimeMillis() < deadline) { - /* Send at least 1MB of data but do not spend more than a minute by doing it. - * This is to overpass minimum buffering limits we have set via BufferingHints in the EnvCustomizer */ + /* + * Send at least 1MB of data but do not spend more than a minute by doing it. + * This is to overpass minimum buffering limits we have set via BufferingHints in the EnvCustomizer + */ RestAssured.given() // .contentType(ContentType.TEXT) .body(msg) @@ -92,45 +94,34 @@ class Aws2KinesisTest { final Config config = ConfigProvider.getConfig(); - S3ClientBuilder builder = S3Client.builder() - .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create( - config.getValue("camel.component.aws2-kinesis.access-key", String.class), - config.getValue("camel.component.aws2-kinesis.secret-key", String.class)))) - .region(Region.of(config.getValue("camel.component.aws2-kinesis.region", String.class))); - - config.getOptionalValue("camel.component.aws2-kinesis.uri-endpoint-override", - String.class).ifPresent(endpointOverride -> builder.endpointOverride(URI.create(endpointOverride))); - try (S3Client client = builder.build()) { - - final String bucketName = config.getValue("aws-kinesis.s3-bucket-name", String.class); + final String bucketName = config.getValue("aws-kinesis.s3-bucket-name", String.class); - Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(120, TimeUnit.SECONDS).until( - () -> { - final ListObjectsResponse objects = client - .listObjects(ListObjectsRequest.builder().bucket(bucketName).build()); - final List<S3Object> objs = objects.contents(); - LOG.info("There are " + objs.size() + " objects in bucket " + bucketName); - for (S3Object obj : objs) { - LOG.info("Checking object " + obj.key() + " of size " + obj.size()); - try (ResponseInputStream<GetObjectResponse> o = client - .getObject(GetObjectRequest.builder().bucket(bucketName).key(obj.key()).build())) { - final StringBuilder sb = new StringBuilder(msg.length()); - final byte[] buf = new byte[1024]; - int len; - while ((len = o.read(buf)) >= 0 && sb.length() < msgPrefix.length()) { - sb.append(new String(buf, 0, len, StandardCharsets.UTF_8)); - } - final String foundContent = sb.toString(); - if (foundContent.startsWith(msgPrefix)) { - /* Yes, this is what we have sent */ - LOG.info("Found the expected content in object " + obj.key()); - return true; - } + Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(120, TimeUnit.SECONDS).until( + () -> { + final ListObjectsResponse objects = client + .listObjects(ListObjectsRequest.builder().bucket(bucketName).build()); + final List<S3Object> objs = objects.contents(); + LOG.info("There are " + objs.size() + " objects in bucket " + bucketName); + for (S3Object obj : objs) { + LOG.info("Checking object " + obj.key() + " of size " + obj.size()); + try (ResponseInputStream<GetObjectResponse> o = client + .getObject(GetObjectRequest.builder().bucket(bucketName).key(obj.key()).build())) { + final StringBuilder sb = new StringBuilder(msg.length()); + final byte[] buf = new byte[1024]; + int len; + while ((len = o.read(buf)) >= 0 && sb.length() < msgPrefix.length()) { + sb.append(new String(buf, 0, len, StandardCharsets.UTF_8)); + } + final String foundContent = sb.toString(); + if (foundContent.startsWith(msgPrefix)) { + /* Yes, this is what we have sent */ + LOG.info("Found the expected content in object " + obj.key()); + return true; } } - return false; - }); - } + } + return false; + }); }
