You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/09/30 16:39:13 UTC
[camel] 01/02: CAMEL-10173: camel-etcd3 - Add Test infra for etcd3
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch CAMEL-10173/component-etcd-v3
in repository https://gitbox.apache.org/repos/asf/camel.git
commit ce942f7d84b4d96474550dd7b56ae4fe89764a82
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Fri Sep 30 18:21:39 2022 +0200
CAMEL-10173: camel-etcd3 - Add Test infra for etcd3
---
test-infra/camel-test-infra-etcd3/pom.xml | 63 ++++++++++++++++
.../src/main/resources/META-INF/MANIFEST.MF | 0
.../test/infra/etcd3/common/Etcd3Properties.java | 26 +++++++
.../etcd3/services/Etcd3LocalContainerService.java | 86 ++++++++++++++++++++++
.../infra/etcd3/services/Etcd3RemoteService.java | 42 +++++++++++
.../test/infra/etcd3/services/Etcd3Service.java | 40 ++++++++++
.../infra/etcd3/services/Etcd3ServiceFactory.java | 37 ++++++++++
test-infra/pom.xml | 1 +
8 files changed, 295 insertions(+)
diff --git a/test-infra/camel-test-infra-etcd3/pom.xml b/test-infra/camel-test-infra-etcd3/pom.xml
new file mode 100644
index 00000000000..0635d951487
--- /dev/null
+++ b/test-infra/camel-test-infra-etcd3/pom.xml
@@ -0,0 +1,63 @@
+<?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">
+ <parent>
+ <artifactId>camel-test-infra-parent</artifactId>
+ <groupId>org.apache.camel</groupId>
+ <relativePath>../camel-test-infra-parent/pom.xml</relativePath>
+ <version>3.19.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>camel-test-infra-etcd3</artifactId>
+ <name>Camel :: Test Infra :: EtcD v3</name>
+ <description>EtcD v3 test infrastructure for Camel</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-common</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-launcher</artifactId>
+ <version>${jetcd-version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/test-infra/camel-test-infra-etcd3/src/main/resources/META-INF/MANIFEST.MF b/test-infra/camel-test-infra-etcd3/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/common/Etcd3Properties.java b/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/common/Etcd3Properties.java
new file mode 100644
index 00000000000..e221ab757af
--- /dev/null
+++ b/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/common/Etcd3Properties.java
@@ -0,0 +1,26 @@
+/*
+ * 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.test.infra.etcd3.common;
+
+public final class Etcd3Properties {
+ public static final String SERVICE_ADDRESS = "etcd.service.address";
+ public static final String ETCD_CONTAINER = "etcd.container";
+
+ private Etcd3Properties() {
+
+ }
+}
diff --git a/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3LocalContainerService.java b/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3LocalContainerService.java
new file mode 100644
index 00000000000..98d63fcb61f
--- /dev/null
+++ b/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3LocalContainerService.java
@@ -0,0 +1,86 @@
+/*
+ * 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.test.infra.etcd3.services;
+
+import java.util.List;
+import java.util.UUID;
+
+import io.etcd.jetcd.launcher.EtcdContainer;
+import org.apache.camel.test.infra.common.services.ContainerService;
+import org.apache.camel.test.infra.etcd3.common.Etcd3Properties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Etcd3LocalContainerService implements Etcd3Service, ContainerService<EtcdContainer> {
+ public static final String CONTAINER_IMAGE = "gcr.io/etcd-development/etcd:v3.5.5";
+ public static final String CONTAINER_NAME = "etcd";
+ public static final int ETCD_CLIENT_PORT = 2379;
+ public static final int ETCD_PEER_PORT = 2380;
+
+ private static final Logger LOG = LoggerFactory.getLogger(Etcd3LocalContainerService.class);
+
+ private final EtcdContainer container;
+
+ public Etcd3LocalContainerService() {
+ this(System.getProperty("etcd.container", CONTAINER_IMAGE));
+ }
+
+ public Etcd3LocalContainerService(String imageName) {
+ container = initContainer(imageName, CONTAINER_NAME);
+ }
+
+ public Etcd3LocalContainerService(EtcdContainer container) {
+ this.container = container;
+ }
+
+ public EtcdContainer initContainer(String imageName, String containerName) {
+ return new EtcdContainer(imageName, CONTAINER_NAME, List.of(CONTAINER_NAME))
+ .withNetworkAliases(containerName)
+ .withClusterToken(UUID.randomUUID().toString())
+ .withExposedPorts(ETCD_CLIENT_PORT, ETCD_PEER_PORT);
+ }
+
+ @Override
+ public void registerProperties() {
+ System.setProperty(Etcd3Properties.SERVICE_ADDRESS, getServiceAddress());
+ }
+
+ @Override
+ public void initialize() {
+ LOG.info("Trying to start the Etcd container");
+ container.start();
+
+ registerProperties();
+ LOG.info("Etcd instance running at {}", getServiceAddress());
+ }
+
+ @Override
+ public void shutdown() {
+ LOG.info("Stopping the Etcd container");
+ container.stop();
+ }
+
+ @Override
+ public EtcdContainer getContainer() {
+ return container;
+ }
+
+ @Override
+ public String getServiceAddress() {
+ return String.format("http://%s:%d", container.getHost(), container.getMappedPort(ETCD_CLIENT_PORT));
+ }
+}
diff --git a/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3RemoteService.java b/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3RemoteService.java
new file mode 100644
index 00000000000..7680f91f11c
--- /dev/null
+++ b/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3RemoteService.java
@@ -0,0 +1,42 @@
+/*
+ * 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.test.infra.etcd3.services;
+
+import org.apache.camel.test.infra.etcd3.common.Etcd3Properties;
+
+public class Etcd3RemoteService implements Etcd3Service {
+
+ @Override
+ public void registerProperties() {
+ // NO-OP
+ }
+
+ @Override
+ public void initialize() {
+ registerProperties();
+ }
+
+ @Override
+ public void shutdown() {
+ // NO-OP
+ }
+
+ @Override
+ public String getServiceAddress() {
+ return System.getProperty(Etcd3Properties.SERVICE_ADDRESS);
+ }
+}
diff --git a/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3Service.java b/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3Service.java
new file mode 100644
index 00000000000..6db74e51ca4
--- /dev/null
+++ b/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3Service.java
@@ -0,0 +1,40 @@
+/*
+ * 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.test.infra.etcd3.services;
+
+import org.apache.camel.test.infra.common.services.TestService;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * Test infra service for EtcD
+ */
+public interface Etcd3Service extends BeforeAllCallback, AfterAllCallback, TestService {
+
+ String getServiceAddress();
+
+ @Override
+ default void beforeAll(ExtensionContext extensionContext) throws Exception {
+ initialize();
+ }
+
+ @Override
+ default void afterAll(ExtensionContext extensionContext) throws Exception {
+ shutdown();
+ }
+}
diff --git a/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3ServiceFactory.java b/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3ServiceFactory.java
new file mode 100644
index 00000000000..73e34b04085
--- /dev/null
+++ b/test-infra/camel-test-infra-etcd3/src/test/java/org/apache/camel/test/infra/etcd3/services/Etcd3ServiceFactory.java
@@ -0,0 +1,37 @@
+/*
+ * 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.test.infra.etcd3.services;
+
+import org.apache.camel.test.infra.common.services.SimpleTestServiceBuilder;
+
+public final class Etcd3ServiceFactory {
+
+ private Etcd3ServiceFactory() {
+
+ }
+
+ public static SimpleTestServiceBuilder<Etcd3Service> builder() {
+ return new SimpleTestServiceBuilder<>("etcd");
+ }
+
+ public static Etcd3Service createService() {
+ return builder()
+ .addLocalMapping(Etcd3LocalContainerService::new)
+ .addRemoteMapping(Etcd3RemoteService::new)
+ .build();
+ }
+}
diff --git a/test-infra/pom.xml b/test-infra/pom.xml
index e5d6d7eb68e..6e2bde6fcb6 100644
--- a/test-infra/pom.xml
+++ b/test-infra/pom.xml
@@ -75,5 +75,6 @@
<module>camel-test-infra-ignite</module>
<module>camel-test-infra-hashicorp-vault</module>
<module>camel-test-infra-jetty</module>
+ <module>camel-test-infra-etcd3</module>
</modules>
</project>