You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2021/04/09 09:39:03 UTC

[camel] 04/04: CAMEL-16399 - Add DynamoDB and DynamoDB Streams to camel-test-infra-aws-v2 module - DynamoDB

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 9d6c3650aea947ba433e59193591221119f6cdf7
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Apr 9 11:32:45 2021 +0200

    CAMEL-16399 - Add DynamoDB and DynamoDB Streams to camel-test-infra-aws-v2 module - DynamoDB
---
 components/camel-aws/camel-aws2-ddb/pom.xml        | 34 ++++++++++++++++++
 .../camel/component/aws2/ddb/Ddb2Endpoint.java     |  6 +++-
 .../component/aws2/ddb/localstack/Aws2DDBBase.java | 41 ++++++++++++++++++++++
 .../src/test/resources/log4j2.properties           |  2 +-
 .../infra/aws2/services/AWSServiceFactory.java     |  4 +++
 5 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/components/camel-aws/camel-aws2-ddb/pom.xml b/components/camel-aws/camel-aws2-ddb/pom.xml
index 479c934..be6df81 100644
--- a/components/camel-aws/camel-aws2-ddb/pom.xml
+++ b/components/camel-aws/camel-aws2-ddb/pom.xml
@@ -67,5 +67,39 @@
             <artifactId>log4j-slf4j-impl</artifactId>
             <scope>test</scope>
         </dependency>
+
+        <!-- test infra -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-common</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-aws-common</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-aws-v2</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
 </project>
diff --git a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Endpoint.java b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Endpoint.java
index 1828ee9..8bebf21 100644
--- a/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Endpoint.java
+++ b/components/camel-aws/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Endpoint.java
@@ -39,11 +39,13 @@ import software.amazon.awssdk.http.apache.ProxyConfiguration;
 import software.amazon.awssdk.regions.Region;
 import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
 import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder;
+import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
 import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest;
 import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest;
 import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement;
 import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput;
 import software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException;
+import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType;
 import software.amazon.awssdk.services.dynamodb.model.TableDescription;
 import software.amazon.awssdk.services.dynamodb.model.TableStatus;
 import software.amazon.awssdk.utils.AttributeMap;
@@ -122,7 +124,9 @@ public class Ddb2Endpoint extends ScheduledPollEndpoint {
                 .keySchema(KeySchemaElement.builder().attributeName(configuration.getKeyAttributeName())
                         .keyType(configuration.getKeyAttributeType()).build())
                 .provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(configuration.getReadCapacity())
-                        .writeCapacityUnits(configuration.getWriteCapacity()).build());
+                        .writeCapacityUnits(configuration.getWriteCapacity()).build())
+                .attributeDefinitions(AttributeDefinition.builder().attributeName(configuration.getKeyAttributeName())
+                        .attributeType(ScalarAttributeType.S).build());
         return getDdbClient().createTable(createTableRequest.build()).tableDescription();
     }
 
diff --git a/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/localstack/Aws2DDBBase.java b/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/localstack/Aws2DDBBase.java
new file mode 100644
index 0000000..9f81df6
--- /dev/null
+++ b/components/camel-aws/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/localstack/Aws2DDBBase.java
@@ -0,0 +1,41 @@
+/*
+ * 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.component.aws2.ddb.localstack;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.aws2.ddb.Ddb2Component;
+import org.apache.camel.test.infra.aws.common.services.AWSService;
+import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils;
+import org.apache.camel.test.infra.aws2.services.AWSServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class Aws2DDBBase extends CamelTestSupport {
+
+    @RegisterExtension
+    public static AWSService service = AWSServiceFactory.createDynamodbService();
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        Ddb2Component eventbridgeComponent = context.getComponent("aws2-ddb", Ddb2Component.class);
+        eventbridgeComponent.getConfiguration().setAmazonDDBClient(AWSSDKClientUtils.newDynamoDBClient());
+        return context;
+    }
+}
diff --git a/components/camel-aws/camel-aws2-ddb/src/test/resources/log4j2.properties b/components/camel-aws/camel-aws2-ddb/src/test/resources/log4j2.properties
index bccd7df..0eb3f78 100644
--- a/components/camel-aws/camel-aws2-ddb/src/test/resources/log4j2.properties
+++ b/components/camel-aws/camel-aws2-ddb/src/test/resources/log4j2.properties
@@ -24,5 +24,5 @@ appender.out.type = Console
 appender.out.name = out
 appender.out.layout.type = PatternLayout
 appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
-rootLogger.level = DEBUG
+rootLogger.level = INFO
 rootLogger.appenderRef.file.ref = file
diff --git a/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSServiceFactory.java b/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSServiceFactory.java
index c2f7162..91f3af2 100644
--- a/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSServiceFactory.java
+++ b/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSServiceFactory.java
@@ -86,4 +86,8 @@ public final class AWSServiceFactory {
     public static AWSService createSTSService() {
         return createService(AWSSTSLocalContainerService::new);
     }
+
+    public static AWSService createDynamodbService() {
+        return createService(AWSDynamodbLocalContainerService::new);
+    }
 }