You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2021/02/23 19:53:28 UTC
[camel-quarkus] 01/02: Test AWS 2 CloudWatch
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 99630f23021fd09156df9312084779c778101223
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Tue Feb 23 15:51:33 2021 +0100
Test AWS 2 CloudWatch
---
integration-tests-aws2/aws2-cw/pom.xml | 146 +++++++++++++++++++++
.../component/aws2/cw/it/Aws2CwResource.java | 64 +++++++++
.../src/main/resources/application.properties | 20 +++
.../quarkus/component/aws2/cw/it/Aws2CwIT.java | 27 ++++
.../quarkus/component/aws2/cw/it/Aws2CwTest.java | 96 ++++++++++++++
.../aws2/cw/it/Aws2CwTestEnvCustomizer.java | 34 +++++
...quarkus.test.support.aws2.Aws2TestEnvCustomizer | 1 +
integration-tests-aws2/pom.xml | 1 +
.../quarkus/test/support/aws2/Aws2Client.java | 35 +++++
.../test/support/aws2/Aws2TestEnvContext.java | 27 ++++
.../test/support/aws2/Aws2TestResource.java | 24 ++++
integration-tests/aws2-grouped/pom.xml | 21 +++
12 files changed, 496 insertions(+)
diff --git a/integration-tests-aws2/aws2-cw/pom.xml b/integration-tests-aws2/aws2-cw/pom.xml
new file mode 100644
index 0000000..0d9e9e2
--- /dev/null
+++ b/integration-tests-aws2/aws2-cw/pom.xml
@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-integration-tests-aws2</artifactId>
+ <version>1.8.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>camel-quarkus-integration-test-aws2-cw</artifactId>
+ <name>Camel Quarkus :: Integration Tests :: AWS 2 CloudWatch</name>
+ <description>Integration tests for Camel Quarkus AWS 2 CloudWatch extension</description>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bom-test</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-main</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-aws2-cw</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-quartz</artifactId>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.rest-assured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-integration-tests-support-aws2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-aws2-cw-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-main-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <quarkus.package.type>native</quarkus.package.type>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
diff --git a/integration-tests-aws2/aws2-cw/src/main/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwResource.java b/integration-tests-aws2/aws2-cw/src/main/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwResource.java
new file mode 100644
index 0000000..096c2db
--- /dev/null
+++ b/integration-tests-aws2/aws2-cw/src/main/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwResource.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.aws2.cw.it;
+
+import java.net.URI;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.scheduler.Scheduled;
+import org.apache.camel.ProducerTemplate;
+
+@Path("/aws2-cw")
+@ApplicationScoped
+public class Aws2CwResource {
+
+ @Inject
+ ProducerTemplate producerTemplate;
+
+ private volatile String endpointUri;
+
+ @Scheduled(every = "1s")
+ void schedule() {
+ if (endpointUri != null) {
+ producerTemplate.requestBody(endpointUri, null, String.class);
+ }
+ }
+
+ @Path("/send-metric/{namespace}/{metric-name}/{metric-unit}")
+ @POST
+ @Consumes(MediaType.TEXT_PLAIN)
+ @Produces(MediaType.TEXT_PLAIN)
+ public Response post(
+ String value,
+ @PathParam("namespace") String namespace,
+ @PathParam("metric-name") String name,
+ @PathParam("metric-unit") String unit) throws Exception {
+ endpointUri = "aws2-cw://" + namespace + "?name=" + name + "&value=" + value + "&unit=" + unit;
+ return Response
+ .created(new URI("https://camel.apache.org/"))
+ .build();
+ }
+}
diff --git a/integration-tests-aws2/aws2-cw/src/main/resources/application.properties b/integration-tests-aws2/aws2-cw/src/main/resources/application.properties
new file mode 100644
index 0000000..8f24b45
--- /dev/null
+++ b/integration-tests-aws2/aws2-cw/src/main/resources/application.properties
@@ -0,0 +1,20 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+camel.component.aws2-cw.access-key=${AWS_ACCESS_KEY}
+camel.component.aws2-cw.secret-key=${AWS_SECRET_KEY}
+camel.component.aws2-cw.region=${AWS_REGION:us-east-1}
diff --git a/integration-tests-aws2/aws2-cw/src/test/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwIT.java b/integration-tests-aws2/aws2-cw/src/test/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwIT.java
new file mode 100644
index 0000000..b77875c
--- /dev/null
+++ b/integration-tests-aws2/aws2-cw/src/test/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwIT.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.aws2.cw.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+//TODO disabled because of https://github.com/apache/camel-quarkus/issues/2216
+@EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY", matches = "[a-zA-Z0-9]+")
+@NativeImageTest
+class Aws2CwIT extends Aws2CwTest {
+
+}
diff --git a/integration-tests-aws2/aws2-cw/src/test/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwTest.java b/integration-tests-aws2/aws2-cw/src/test/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwTest.java
new file mode 100644
index 0000000..f5f42d7
--- /dev/null
+++ b/integration-tests-aws2/aws2-cw/src/test/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.aws2.cw.it;
+
+import java.time.Instant;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+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.awaitility.Awaitility;
+import org.jboss.logging.Logger;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.testcontainers.containers.localstack.LocalStackContainer.Service;
+import software.amazon.awssdk.services.cloudwatch.CloudWatchClient;
+import software.amazon.awssdk.services.cloudwatch.model.Datapoint;
+import software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsRequest;
+import software.amazon.awssdk.services.cloudwatch.model.Statistic;
+
+//TODO disabled because of https://github.com/apache/camel-quarkus/issues/2216
+@EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY", matches = "[a-zA-Z0-9]+")
+@QuarkusTest
+@QuarkusTestResource(Aws2TestResource.class)
+class Aws2CwTest {
+ private static final Logger LOG = Logger.getLogger(Aws2CwTest.class);
+
+ @Aws2Client(Service.CLOUDWATCH)
+ CloudWatchClient client;
+
+ @Test
+ public void metric() {
+
+ final Instant startTime = Instant.ofEpochMilli(System.currentTimeMillis() - 10000);
+
+ final String namespace = "cq-metrics-" + java.util.UUID.randomUUID().toString().replace("-", "");
+ final String metricName = "metricName" + java.util.UUID.randomUUID().toString().replace("-", "");
+ final int value = (int) (Math.random() * 10000);
+ RestAssured.given()
+ .contentType(ContentType.TEXT)
+ .body(value)
+ .post("/aws2-cw/send-metric/" + namespace + "/" + metricName + "/Count")
+ .then()
+ .statusCode(201);
+
+ final double precision = 0.0001;
+ Awaitility.await().pollInterval(1, TimeUnit.SECONDS).atMost(120, TimeUnit.SECONDS).until(
+ () -> {
+
+ List<Datapoint> datapoints = client.getMetricStatistics(
+ GetMetricStatisticsRequest.builder()
+ .namespace(namespace)
+ .metricName(metricName)
+ .statistics(Statistic.SAMPLE_COUNT, Statistic.MINIMUM, Statistic.MAXIMUM)
+ .startTime(startTime)
+ .endTime(Instant.ofEpochMilli(System.currentTimeMillis() + 10000))
+ .period(1)
+ .build())
+ .datapoints();
+ LOG.info("Expecting some datapoints for metric " + namespace + "/" + metricName + ", got " + datapoints);
+ if (datapoints.isEmpty()) {
+ return false;
+ }
+
+ Datapoint dp = datapoints.get(0);
+
+ if (dp.sampleCount().doubleValue() + precision > 1.0
+ && Math.abs(dp.minimum().doubleValue() - value) < precision
+ && Math.abs(dp.maximum().doubleValue() - value) < precision) {
+ return true;
+ }
+ throw new RuntimeException("Unexpected datapoint " + dp + "; expected sampleCount ~ 1 && minimum ~ " + value
+ + " && maximum ~ " + value);
+ });
+
+ }
+
+}
diff --git a/integration-tests-aws2/aws2-cw/src/test/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwTestEnvCustomizer.java b/integration-tests-aws2/aws2-cw/src/test/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwTestEnvCustomizer.java
new file mode 100644
index 0000000..6871824
--- /dev/null
+++ b/integration-tests-aws2/aws2-cw/src/test/java/org/apache/camel/quarkus/component/aws2/cw/it/Aws2CwTestEnvCustomizer.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.aws2.cw.it;
+
+import org.apache.camel.quarkus.test.support.aws2.Aws2TestEnvContext;
+import org.apache.camel.quarkus.test.support.aws2.Aws2TestEnvCustomizer;
+import org.testcontainers.containers.localstack.LocalStackContainer.Service;
+
+public class Aws2CwTestEnvCustomizer implements Aws2TestEnvCustomizer {
+
+ @Override
+ public Service[] localstackServices() {
+ return new Service[] { Service.CLOUDWATCH };
+ }
+
+ @Override
+ public void customize(Aws2TestEnvContext envContext) {
+
+ }
+}
diff --git a/integration-tests-aws2/aws2-cw/src/test/resources/META-INF/services/org.apache.camel.quarkus.test.support.aws2.Aws2TestEnvCustomizer b/integration-tests-aws2/aws2-cw/src/test/resources/META-INF/services/org.apache.camel.quarkus.test.support.aws2.Aws2TestEnvCustomizer
new file mode 100644
index 0000000..b8d10d2
--- /dev/null
+++ b/integration-tests-aws2/aws2-cw/src/test/resources/META-INF/services/org.apache.camel.quarkus.test.support.aws2.Aws2TestEnvCustomizer
@@ -0,0 +1 @@
+org.apache.camel.quarkus.component.aws2.cw.it.Aws2CwTestEnvCustomizer
\ No newline at end of file
diff --git a/integration-tests-aws2/pom.xml b/integration-tests-aws2/pom.xml
index 42583a0..c20091f 100644
--- a/integration-tests-aws2/pom.xml
+++ b/integration-tests-aws2/pom.xml
@@ -38,6 +38,7 @@
<modules>
<!-- extensions a..z; do not remove this comment, it is important when sorting via mvn process-resources -Pformat -->
+ <module>aws2-cw</module>
<module>aws2-ddb</module>
<module>aws2-kinesis</module>
<module>aws2-s3</module>
diff --git a/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2Client.java b/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2Client.java
new file mode 100644
index 0000000..fcebaa3
--- /dev/null
+++ b/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2Client.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.test.support.aws2;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.testcontainers.containers.localstack.LocalStackContainer.Service;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface Aws2Client {
+
+ /**
+ *
+ * @return the {@link Service} for which we want a client
+ */
+ Service value();
+}
diff --git a/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2TestEnvContext.java b/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2TestEnvContext.java
index 0b66ab2..6167883 100644
--- a/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2TestEnvContext.java
+++ b/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2TestEnvContext.java
@@ -16,13 +16,16 @@
*/
package org.apache.camel.quarkus.test.support.aws2;
+import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.EnumMap;
import java.util.LinkedHashMap;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
import java.util.function.Supplier;
@@ -41,6 +44,7 @@ import software.amazon.awssdk.regions.Region;
public class Aws2TestEnvContext {
private static final Logger LOG = Logger.getLogger(Aws2TestEnvContext.class);
private final ArrayList<AutoCloseable> closeables = new ArrayList<>();
+ private final Map<Service, ? extends SdkClient> clients = new EnumMap<>(Service.class);
private final Map<String, String> properties = new LinkedHashMap<>();
private final String accessKey;
private final String secretKey;
@@ -67,6 +71,7 @@ public class Aws2TestEnvContext {
case SNS:
case DYNAMODB:
case DYNAMODB_STREAMS:
+ case CLOUDWATCH:
// TODO https://github.com/apache/camel-quarkus/issues/2216
break;
default:
@@ -117,6 +122,10 @@ public class Aws2TestEnvContext {
ListIterator<AutoCloseable> it = closeables.listIterator(closeables.size());
while (it.hasPrevious()) {
AutoCloseable c = it.previous();
+ if (c instanceof SdkClient) {
+ clients.entrySet().stream().filter(en -> c == en.getValue()).map(Entry::getKey).findFirst()
+ .map(clients::remove);
+ }
try {
c.close();
} catch (Exception e) {
@@ -157,6 +166,22 @@ public class Aws2TestEnvContext {
return client;
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ SdkClient client(Service service, Class<?> clientType) {
+ SdkClient result = clients.get(service);
+ if (result != null) {
+ return result;
+ }
+ return client(service, () -> {
+ try {
+ return (AwsClientBuilder) clientType.getDeclaredMethod("builder").invoke(null);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
+ | SecurityException e) {
+ throw new RuntimeException("Could not call " + clientType.getName() + ".builder()", e);
+ }
+ });
+ }
+
private static String camelServiceAcronym(Service service) {
switch (service) {
case DYNAMODB:
@@ -165,6 +190,8 @@ public class Aws2TestEnvContext {
return "ddbstream";
case FIREHOSE:
return "kinesis-firehose";
+ case CLOUDWATCH:
+ return "cw";
default:
return service.name().toLowerCase(Locale.ROOT);
}
diff --git a/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2TestResource.java b/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2TestResource.java
index f1be06f..803bfbc 100644
--- a/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2TestResource.java
+++ b/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2TestResource.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.quarkus.test.support.aws2;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -29,6 +30,7 @@ import org.jboss.logging.Logger;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.containers.localstack.LocalStackContainer.Service;
import org.testcontainers.utility.DockerImageName;
+import software.amazon.awssdk.core.SdkClient;
public final class Aws2TestResource implements ContainerResourceLifecycleManager {
private static final Logger LOG = Logger.getLogger(Aws2TestResource.class);
@@ -93,4 +95,26 @@ public final class Aws2TestResource implements ContainerResourceLifecycleManager
envContext.close();
}
+ @Override
+ public void inject(Object testInstance) {
+ Class<?> c = testInstance.getClass();
+ while (c != Object.class) {
+ for (Field f : c.getDeclaredFields()) {
+ Aws2Client clientAnnot = f.getAnnotation(Aws2Client.class);
+ if (clientAnnot != null) {
+ Service service = clientAnnot.value();
+ f.setAccessible(true);
+ SdkClient client = envContext.client(service, f.getType());
+ try {
+ f.set(testInstance, client);
+ } catch (IllegalArgumentException | IllegalAccessException e) {
+ throw new RuntimeException("Could not set " + c.getName() + "." + f.getName(), e);
+ }
+ }
+ }
+ c = c.getSuperclass();
+ }
+
+ }
+
}
diff --git a/integration-tests/aws2-grouped/pom.xml b/integration-tests/aws2-grouped/pom.xml
index 787f499..52051e1 100644
--- a/integration-tests/aws2-grouped/pom.xml
+++ b/integration-tests/aws2-grouped/pom.xml
@@ -45,6 +45,10 @@
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
+ <artifactId>quarkus-quartz</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
@@ -53,6 +57,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-aws2-cw</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-aws2-ddb</artifactId>
</dependency>
<dependency>
@@ -104,6 +112,19 @@
<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-aws2-cw-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-aws2-ddb-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>