This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 1d7ff2a Migrates zookeeper related components to the new test-infra (#4722) 1d7ff2a is described below commit 1d7ff2a489d0db24df86ef60b0bdeec4c5e7e4f7 Author: Otavio Rodolfo Piske <orpi...@users.noreply.github.com> AuthorDate: Fri Dec 4 14:23:12 2020 +0100 Migrates zookeeper related components to the new test-infra (#4722) Includes: - camel-zookeeper - camel-zookeeper-master --- components/camel-zookeeper-master/pom.xml | 18 ++++- .../MasterEndpointFailoverTest.java | 12 +-- .../component/zookeepermaster/group/GroupTest.java | 18 ++--- .../zookeepermaster/MasterEndpointTest-context.xml | 2 +- .../MasterQuartzEndpointTest-context.xml | 2 +- components/camel-zookeeper/pom.xml | 22 +++-- .../component/zookeeper/ConsumeChildrenTest.java | 2 +- .../camel/component/zookeeper/ConsumeDataTest.java | 2 +- .../component/zookeeper/ZooKeeperContainer.java | 94 ---------------------- .../zookeeper/ZooKeeperManagedEndpointTest.java | 2 +- .../component/zookeeper/ZooKeeperProducerTest.java | 14 ++-- .../component/zookeeper/ZooKeeperTestSupport.java | 19 +++-- .../cloud/SpringZooKeeperServiceCallRouteTest.java | 20 +++-- .../cloud/ZooKeeperServiceCallRouteTest.java | 19 ++--- .../cloud/ZooKeeperServiceDiscoveryTest.java | 15 ++-- .../ZooKeeperServiceRegistrationTestBase.java | 2 +- .../ZooKeeperClusteredRoutePolicyFactoryTest.java | 36 ++++----- .../cluster/ZooKeeperClusteredRoutePolicyTest.java | 36 ++++----- .../zookeeper/cluster/ZooKeeperMasterTest.java | 36 ++++----- .../cloud/SpringZooKeeperServiceCallRouteTest.xml | 2 +- ...ingZooKeeperClusteredRouteConfigurationTest.xml | 2 +- test-infra/camel-test-infra-zookeeper/pom.xml | 60 ++++++++++++++ .../src/main/resources/META-INF/MANIFEST.MF | 0 .../zookeeper/common/ZooKeeperProperties.java | 26 ++++++ .../zookeeper/services/ZooKeeperContainer.java | 21 ++--- .../services/ZooKeeperLocalContainerService.java | 72 +++++++++++++++++ .../zookeeper/services/ZooKeeperRemoteService.java | 42 ++++++++++ .../infra/zookeeper/services/ZooKeeperService.java | 39 +++++++++ .../services/ZooKeeperServiceFactory.java | 43 ++++++++++ test-infra/pom.xml | 1 + 30 files changed, 434 insertions(+), 245 deletions(-) diff --git a/components/camel-zookeeper-master/pom.xml b/components/camel-zookeeper-master/pom.xml index 38c82bd..4615903 100644 --- a/components/camel-zookeeper-master/pom.xml +++ b/components/camel-zookeeper-master/pom.xml @@ -136,16 +136,26 @@ <scope>test</scope> </dependency> - <!-- testing --> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>test</scope> + </dependency> + + <!-- test infra --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-testcontainers-spring</artifactId> + <artifactId>camel-test-infra-common</artifactId> + <version>${project.version}</version> + <type>test-jar</type> <scope>test</scope> </dependency> <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-zookeeper</artifactId> + <version>${project.version}</version> + <type>test-jar</type> <scope>test</scope> </dependency> diff --git a/components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/MasterEndpointFailoverTest.java b/components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/MasterEndpointFailoverTest.java index 49e7106..367a90b 100644 --- a/components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/MasterEndpointFailoverTest.java +++ b/components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/MasterEndpointFailoverTest.java @@ -24,14 +24,20 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.SimpleRegistry; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperService; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperServiceFactory; import org.apache.curator.framework.CuratorFramework; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MasterEndpointFailoverTest { + @RegisterExtension + static ZooKeeperService service = ZooKeeperServiceFactory.createService(); + private static final transient Logger LOG = LoggerFactory.getLogger(MasterEndpointFailoverTest.class); protected ProducerTemplate template; @@ -41,15 +47,12 @@ public class MasterEndpointFailoverTest { protected MockEndpoint result1Endpoint; protected MockEndpoint result2Endpoint; protected AtomicInteger messageCounter = new AtomicInteger(1); - protected ZKContainer zkContainer = new ZKContainer(); protected CuratorFactoryBean zkClientBean = new CuratorFactoryBean(); @BeforeEach public void beforeRun() throws Exception { - zkContainer.start(); - // Create the zkClientBean - zkClientBean.setConnectString(zkContainer.getConnectionString()); + zkClientBean.setConnectString(service.getConnectionString()); CuratorFramework client = zkClientBean.getObject(); // Need to bind the zookeeper client with the name "curator" @@ -99,7 +102,6 @@ public class MasterEndpointFailoverTest { consumerContext2.stop(); producerContext.stop(); zkClientBean.destroy(); - zkContainer.stop(); } @Test diff --git a/components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/group/GroupTest.java b/components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/group/GroupTest.java index 53fd54b..9df6991 100644 --- a/components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/group/GroupTest.java +++ b/components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/group/GroupTest.java @@ -24,10 +24,10 @@ import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.apache.camel.component.zookeepermaster.ZKContainer; import org.apache.camel.component.zookeepermaster.group.internal.ChildData; import org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup; import org.apache.camel.test.AvailablePortFinder; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperContainer; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.RetryNTimes; @@ -64,12 +64,12 @@ public class GroupTest { } }; - private ZKContainer startZooKeeper(int port, Path root) throws Exception { + private ZooKeeperContainer startZooKeeper(int port, Path root) throws Exception { LOGGER.info("****************************************"); LOGGER.info("* Starting ZooKeeper container *"); LOGGER.info("****************************************"); - ZKContainer container = new ZKContainer(port); + ZooKeeperContainer container = new ZooKeeperContainer(port); container.withNetworkAliases("zk-" + port); if (root != null) { @@ -136,7 +136,7 @@ public class GroupTest { assertFalse(group.isMaster()); } - ZKContainer container = null; + ZooKeeperContainer container = null; Path dataDir = Files.createTempDirectory("zk-"); try { @@ -196,7 +196,7 @@ public class GroupTest { GroupCondition groupCondition = new GroupCondition(); group.add(groupCondition); - ZKContainer container = null; + ZooKeeperContainer container = null; Path dataDir = Files.createTempDirectory("zk-"); try { @@ -247,7 +247,7 @@ public class GroupTest { assertFalse(group.isMaster()); group.update(new NodeState("foo")); - ZKContainer container = null; + ZooKeeperContainer container = null; Path dataDir = Files.createTempDirectory("zk-"); try { @@ -279,7 +279,7 @@ public class GroupTest { .build(); curator.start(); - ZKContainer container = null; + ZooKeeperContainer container = null; Path dataDir = Files.createTempDirectory("zk-"); try { @@ -331,7 +331,7 @@ public class GroupTest { @Test public void testGroupClose() throws Exception { int port = AvailablePortFinder.getNextAvailable(); - ZKContainer container = null; + ZooKeeperContainer container = null; Path dataDir = Files.createTempDirectory("zk-"); try { @@ -379,7 +379,7 @@ public class GroupTest { public void testAddFieldIgnoredOnParse() throws Exception { int port = AvailablePortFinder.getNextAvailable(); - ZKContainer container = null; + ZooKeeperContainer container = null; Path dataDir = Files.createTempDirectory("zk-"); try { diff --git a/components/camel-zookeeper-master/src/test/resources/org/apache/camel/component/zookeepermaster/MasterEndpointTest-context.xml b/components/camel-zookeeper-master/src/test/resources/org/apache/camel/component/zookeepermaster/MasterEndpointTest-context.xml index 1974d25..2eb8d95 100644 --- a/components/camel-zookeeper-master/src/test/resources/org/apache/camel/component/zookeepermaster/MasterEndpointTest-context.xml +++ b/components/camel-zookeeper-master/src/test/resources/org/apache/camel/component/zookeepermaster/MasterEndpointTest-context.xml @@ -22,7 +22,7 @@ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <!-- Since this is a test case lets run a local ZK server --> - <bean id="zkContainer" class="org.apache.camel.component.zookeepermaster.ZKContainer" init-method="start" destroy-method="start"> + <bean id="zkContainer" class="org.apache.camel.test.infra.zookeeper.services.ZooKeeperContainer" init-method="start" destroy-method="start"> <constructor-arg> <value>zookeeper</value> </constructor-arg> diff --git a/components/camel-zookeeper-master/src/test/resources/org/apache/camel/component/zookeepermaster/MasterQuartzEndpointTest-context.xml b/components/camel-zookeeper-master/src/test/resources/org/apache/camel/component/zookeepermaster/MasterQuartzEndpointTest-context.xml index 0ffe65f..dd3118c 100644 --- a/components/camel-zookeeper-master/src/test/resources/org/apache/camel/component/zookeepermaster/MasterQuartzEndpointTest-context.xml +++ b/components/camel-zookeeper-master/src/test/resources/org/apache/camel/component/zookeepermaster/MasterQuartzEndpointTest-context.xml @@ -22,7 +22,7 @@ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <!-- Since this is a test case lets run a local ZK server --> - <bean id="zkContainer" class="org.apache.camel.component.zookeepermaster.ZKContainer" init-method="start" destroy-method="start"> + <bean id="zkContainer" class="org.apache.camel.test.infra.zookeeper.services.ZooKeeperContainer" init-method="start" destroy-method="start"> <constructor-arg> <value>zookeeper</value> </constructor-arg> diff --git a/components/camel-zookeeper/pom.xml b/components/camel-zookeeper/pom.xml index 96c20ed..429b8a6 100644 --- a/components/camel-zookeeper/pom.xml +++ b/components/camel-zookeeper/pom.xml @@ -110,11 +110,6 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-testcontainers-spring-junit5</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> <artifactId>camel-management</artifactId> <scope>test</scope> </dependency> @@ -179,6 +174,23 @@ <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-zookeeper</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + </dependencies> diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeChildrenTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeChildrenTest.java index 9a045c9..0a4f025 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeChildrenTest.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeChildrenTest.java @@ -39,7 +39,7 @@ public class ConsumeChildrenTest extends ZooKeeperTestSupport { protected RouteBuilder[] createRouteBuilders() throws Exception { return new RouteBuilder[] { new RouteBuilder() { public void configure() throws Exception { - from("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/grimm?repeat=true&listChildren=true") + from("zookeeper://{{zookeeper.connection.string}}/grimm?repeat=true&listChildren=true") .sort(body(), new NaturalSortComparator(Order.Descending)) .to("mock:zookeeper-data"); } diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeDataTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeDataTest.java index 9687498..9c6b300 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeDataTest.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ConsumeDataTest.java @@ -33,7 +33,7 @@ public class ConsumeDataTest extends ZooKeeperTestSupport { protected RouteBuilder[] createRouteBuilders() throws Exception { return new RouteBuilder[] { new RouteBuilder() { public void configure() throws Exception { - from("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/camel?repeat=true") + from("zookeeper://{{zookeeper.connection.string}}/camel?repeat=true") .to("mock:zookeeper-data"); } } }; diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperContainer.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperContainer.java deleted file mode 100644 index 7b18ab6..0000000 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperContainer.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.zookeeper; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.output.Slf4jLogConsumer; -import org.testcontainers.containers.wait.strategy.Wait; - -public class ZooKeeperContainer extends GenericContainer { - public static final String CONTAINER_IMAGE = "zookeeper:3.5"; - public static final String CONTAINER_NAME = "zookeeper"; - public static final int CLIENT_PORT = 2181; - - private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperContainer.class); - - public ZooKeeperContainer() { - this(CONTAINER_NAME, -1); - } - - public ZooKeeperContainer(int clientPort) { - this(CONTAINER_NAME, clientPort); - } - - public ZooKeeperContainer(String name) { - this(name, -1); - - setWaitStrategy(Wait.forListeningPort()); - - withNetworkAliases(name); - withExposedPorts(CLIENT_PORT); - withLogConsumer(new Slf4jLogConsumer(LOGGER)); - } - - public ZooKeeperContainer(String name, int clientPort) { - super(CONTAINER_IMAGE); - - setWaitStrategy(Wait.forListeningPort()); - - withNetworkAliases(name); - withLogConsumer(new Slf4jLogConsumer(LOGGER)); - - if (clientPort > 0) { - addFixedExposedPort(clientPort, CLIENT_PORT); - } else { - withExposedPorts(CLIENT_PORT); - } - } - - @Override - public void start() { - LOGGER.info("****************************************"); - LOGGER.info("* Starting ZooKeeper container *"); - LOGGER.info("****************************************"); - - super.start(); - - LOGGER.info("****************************************"); - LOGGER.info("* ZooKeeper container started *"); - LOGGER.info("****************************************"); - } - - @Override - public void stop() { - LOGGER.info("****************************************"); - LOGGER.info("* Stopping ZooKeeper container *"); - LOGGER.info("****************************************"); - - super.stop(); - - LOGGER.info("****************************************"); - LOGGER.info("* ZooKeeper container stopped *"); - LOGGER.info("****************************************"); - } - - public String getConnectionString() { - return getContainerIpAddress() + ":" + getMappedPort(CLIENT_PORT); - } -} diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java index 66b8b83..868ea2d 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperManagedEndpointTest.java @@ -79,7 +79,7 @@ public class ZooKeeperManagedEndpointTest extends ZooKeeperTestSupport { protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { - from("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/node?timeout=1000&backoff=2000") + from("zookeeper://{{zookeeper.connection.string}}/node?timeout=1000&backoff=2000") .to("mock:test"); } }; diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperProducerTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperProducerTest.java index 0a74c4a..6208466 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperProducerTest.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperProducerTest.java @@ -46,7 +46,7 @@ public class ZooKeeperProducerTest extends ZooKeeperTestSupport { new RouteBuilder() { public void configure() throws Exception { zookeeperUri - = "zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/node?create=true"; + = "zookeeper://{{zookeeper.connection.string}}/node?create=true"; from("direct:roundtrip") .to(zookeeperUri) .to("mock:producer-out"); @@ -57,28 +57,28 @@ public class ZooKeeperProducerTest extends ZooKeeperTestSupport { new RouteBuilder() { public void configure() throws Exception { from("direct:no-create-fails-set") - .to("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/doesnotexist"); + .to("zookeeper://{{zookeeper.connection.string}}/doesnotexist"); } }, new RouteBuilder() { public void configure() throws Exception { from("direct:node-from-header") - .to("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/notset?create=true"); - from("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/set?create=true") + .to("zookeeper://{{zookeeper.connection.string}}/notset?create=true"); + from("zookeeper://{{zookeeper.connection.string}}/set?create=true") .to("mock:consumed-from-set-node"); } }, new RouteBuilder() { public void configure() throws Exception { from("direct:create-mode") - .to("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/persistent?create=true&createMode=PERSISTENT") + .to("zookeeper://{{zookeeper.connection.string}}/persistent?create=true&createMode=PERSISTENT") .to("mock:create-mode"); } }, new RouteBuilder() { public void configure() throws Exception { from("direct:delete") - .to("zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/to-be-deleted") + .to("zookeeper://{{zookeeper.connection.string}}/to-be-deleted") .to("mock:delete"); } } @@ -164,7 +164,7 @@ public class ZooKeeperProducerTest extends ZooKeeperTestSupport { exchange.getIn().setHeader(ZOOKEEPER_NODE, "/set-listing/firstborn"); exchange.setPattern(ExchangePattern.InOut); template.send( - "zookeeper://{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}/set-listing?create=true&listChildren=true", + "zookeeper://{{zookeeper.connection.string}}/set-listing?create=true&listChildren=true", exchange); List<?> children = exchange.getMessage().getMandatoryBody(List.class); assertEquals(1, children.size()); diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperTestSupport.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperTestSupport.java index a68309a..5ce8629 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperTestSupport.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/ZooKeeperTestSupport.java @@ -23,7 +23,9 @@ import java.util.concurrent.CountDownLatch; import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.testcontainers.junit5.ContainerAwareTestSupport; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperService; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperServiceFactory; +import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; @@ -32,25 +34,23 @@ import org.apache.zookeeper.ZooDefs.Ids; import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.GenericContainer; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -public class ZooKeeperTestSupport extends ContainerAwareTestSupport { +public class ZooKeeperTestSupport extends CamelTestSupport { + @RegisterExtension + static ZooKeeperService service = ZooKeeperServiceFactory.createService(); + protected String testPayload = "This is a test"; protected byte[] testPayloadBytes = testPayload.getBytes(); protected TestZookeeperClient client; @Override - protected GenericContainer<?> createContainer() { - return new ZooKeeperContainer(); - } - - @Override public void doPreSetup() throws Exception { client = new TestZookeeperClient(getConnectionString(), getTestClientSessionTimeout()); } @@ -61,8 +61,7 @@ public class ZooKeeperTestSupport extends ContainerAwareTestSupport { } public String getConnectionString() { - return getContainerHost(ZooKeeperContainer.CONTAINER_NAME) + ":" - + getContainerPort(ZooKeeperContainer.CONTAINER_NAME, ZooKeeperContainer.CLIENT_PORT); + return service.getConnectionString(); } public ZooKeeper getConnection() { diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.java index d50a156..e6fb4aa 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.java @@ -17,10 +17,11 @@ package org.apache.camel.component.zookeeper.cloud; import org.apache.camel.CamelContext; -import org.apache.camel.component.zookeeper.ZooKeeperContainer; import org.apache.camel.spi.PropertiesComponent; import org.apache.camel.test.AvailablePortFinderPropertiesFunction; -import org.apache.camel.test.testcontainers.spring.junit5.ContainerAwareSpringTestSupport; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperService; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperServiceFactory; +import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; @@ -30,11 +31,14 @@ import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; import org.apache.curator.x.discovery.ServiceInstance; import org.apache.curator.x.discovery.details.JsonInstanceSerializer; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.testcontainers.containers.GenericContainer; -public class SpringZooKeeperServiceCallRouteTest extends ContainerAwareSpringTestSupport { +public class SpringZooKeeperServiceCallRouteTest extends CamelSpringTestSupport { + @RegisterExtension + static ZooKeeperService service = ZooKeeperServiceFactory.createService(); + private static final String SERVICE_NAME = "http-service"; private static final String SERVICE_PATH = "/camel"; @@ -57,19 +61,13 @@ public class SpringZooKeeperServiceCallRouteTest extends ContainerAwareSpringTes } @Override - public GenericContainer createContainer() { - return new ZooKeeperContainer(); - } - - @Override public void doPreSetup() throws Exception { super.doPreSetup(); function = new AvailablePortFinderPropertiesFunction(); curator = CuratorFrameworkFactory.builder() - .connectString(getContainerHost(ZooKeeperContainer.CONTAINER_NAME) + ":" - + getContainerPort(ZooKeeperContainer.CONTAINER_NAME, ZooKeeperContainer.CLIENT_PORT)) + .connectString(service.getConnectionString()) .retryPolicy(new ExponentialBackoffRetry(1000, 3)) .build(); diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceCallRouteTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceCallRouteTest.java index 0aa6c37..83b1eae 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceCallRouteTest.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceCallRouteTest.java @@ -21,8 +21,9 @@ import java.util.List; import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.zookeeper.ZooKeeperContainer; import org.apache.camel.test.AvailablePortFinder; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperService; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperServiceFactory; import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; @@ -33,14 +34,17 @@ import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; import org.apache.curator.x.discovery.ServiceInstance; import org.apache.curator.x.discovery.details.JsonInstanceSerializer; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; public class ZooKeeperServiceCallRouteTest extends CamelTestSupport { + @RegisterExtension + static ZooKeeperService service = ZooKeeperServiceFactory.createService(); + private static final int SERVER_PORT = AvailablePortFinder.getNextAvailable(); private static final String SERVICE_NAME = "http-service"; private static final int SERVICE_COUNT = 5; private static final String SERVICE_PATH = "/camel"; - protected ZooKeeperContainer container; private CuratorFramework curator; private ServiceDiscovery<ZooKeeperServiceDiscovery.MetaData> discovery; private List<ServiceInstance<ZooKeeperServiceDiscovery.MetaData>> instances; @@ -54,11 +58,8 @@ public class ZooKeeperServiceCallRouteTest extends CamelTestSupport { protected void doPreSetup() throws Exception { super.doPreSetup(); - container = new ZooKeeperContainer(); - container.start(); - curator = CuratorFrameworkFactory.builder() - .connectString(container.getConnectionString()) + .connectString(service.getConnectionString()) .retryPolicy(new ExponentialBackoffRetry(1000, 3)) .build(); @@ -103,10 +104,6 @@ public class ZooKeeperServiceCallRouteTest extends CamelTestSupport { CloseableUtils.closeQuietly(discovery); CloseableUtils.closeQuietly(curator); - - if (container != null) { - container.stop(); - } } // ************************************************************************* @@ -137,7 +134,7 @@ public class ZooKeeperServiceCallRouteTest extends CamelTestSupport { .name(SERVICE_NAME) .component("http") .defaultLoadBalancer() - .zookeeperServiceDiscovery(container.getConnectionString(), SERVICE_PATH) + .zookeeperServiceDiscovery(service.getConnectionString(), SERVICE_PATH) .end() .to("log:org.apache.camel.component.zookeeper.cloud?level=INFO&showAll=true&multiline=true") .to("mock:result"); diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceDiscoveryTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceDiscoveryTest.java index 2c0d97c..93a72b8 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceDiscoveryTest.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceDiscoveryTest.java @@ -20,35 +20,36 @@ import java.util.ArrayList; import java.util.List; import org.apache.camel.cloud.ServiceDefinition; -import org.apache.camel.component.zookeeper.ZooKeeperContainer; import org.apache.camel.component.zookeeper.ZooKeeperCuratorConfiguration; import org.apache.camel.component.zookeeper.ZooKeeperCuratorHelper; import org.apache.camel.test.AvailablePortFinder; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperService; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperServiceFactory; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.curator.utils.CloseableUtils; import org.apache.curator.x.discovery.ServiceDiscovery; import org.apache.curator.x.discovery.ServiceInstance; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; public class ZooKeeperServiceDiscoveryTest { + @RegisterExtension + static ZooKeeperService service = ZooKeeperServiceFactory.createService(); @Test public void testServiceDiscovery() throws Exception { ZooKeeperCuratorConfiguration configuration = new ZooKeeperCuratorConfiguration(); ServiceDiscovery<ZooKeeperServiceDiscovery.MetaData> zkDiscovery = null; - ZooKeeperContainer container = null; try { - container = new ZooKeeperContainer(); - container.start(); configuration.setBasePath("/camel"); configuration.setCuratorFramework(CuratorFrameworkFactory.builder() - .connectString(container.getConnectionString()) + .connectString(service.getConnectionString()) .retryPolicy(new ExponentialBackoffRetry(1000, 3)) .build()); @@ -99,10 +100,6 @@ public class ZooKeeperServiceDiscoveryTest { } finally { CloseableUtils.closeQuietly(zkDiscovery); CloseableUtils.closeQuietly(configuration.getCuratorFramework()); - - if (container != null) { - container.stop(); - } } } } diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceRegistrationTestBase.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceRegistrationTestBase.java index 2396c1c..a8eb54b 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceRegistrationTestBase.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/ZooKeeperServiceRegistrationTestBase.java @@ -23,8 +23,8 @@ import java.util.UUID; import org.apache.camel.CamelContext; import org.apache.camel.cloud.ServiceDefinition; -import org.apache.camel.component.zookeeper.ZooKeeperContainer; import org.apache.camel.test.AvailablePortFinder; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperContainer; import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryTest.java index fd4797d..04d9d5f 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryTest.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyFactoryTest.java @@ -27,10 +27,12 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.zookeeper.ZooKeeperContainer; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.impl.cluster.ClusteredRoutePolicyFactory; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperService; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperServiceFactory; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +40,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; public final class ZooKeeperClusteredRoutePolicyFactoryTest { + @RegisterExtension + static ZooKeeperService service = ZooKeeperServiceFactory.createService(); + private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperClusteredRoutePolicyFactoryTest.class); private static final List<String> CLIENTS = IntStream.range(0, 3).mapToObj(Integer::toString).collect(Collectors.toList()); private static final List<String> RESULTS = new ArrayList<>(); @@ -50,27 +55,16 @@ public final class ZooKeeperClusteredRoutePolicyFactoryTest { @Test public void test() throws Exception { - ZooKeeperContainer container = null; - - try { - container = new ZooKeeperContainer(); - container.start(); - - String connectString = container.getConnectionString(); - for (String id : CLIENTS) { - SCHEDULER.submit(() -> run(connectString, id)); - } - - LATCH.await(1, TimeUnit.MINUTES); - SCHEDULER.shutdownNow(); - - assertEquals(CLIENTS.size(), RESULTS.size()); - assertTrue(RESULTS.containsAll(CLIENTS)); - } finally { - if (container != null) { - container.stop(); - } + String connectString = service.getConnectionString(); + for (String id : CLIENTS) { + SCHEDULER.submit(() -> run(connectString, id)); } + + LATCH.await(1, TimeUnit.MINUTES); + SCHEDULER.shutdownNow(); + + assertEquals(CLIENTS.size(), RESULTS.size()); + assertTrue(RESULTS.containsAll(CLIENTS)); } // ************************************ diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyTest.java index 5c332a8..166ce8e 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyTest.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperClusteredRoutePolicyTest.java @@ -27,10 +27,12 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.zookeeper.ZooKeeperContainer; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.impl.cluster.ClusteredRoutePolicy; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperService; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperServiceFactory; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +40,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; public final class ZooKeeperClusteredRoutePolicyTest { + @RegisterExtension + static ZooKeeperService service = ZooKeeperServiceFactory.createService(); + private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperClusteredRoutePolicyTest.class); private static final List<String> CLIENTS = IntStream.range(0, 3).mapToObj(Integer::toString).collect(Collectors.toList()); private static final List<String> RESULTS = new ArrayList<>(); @@ -50,27 +55,16 @@ public final class ZooKeeperClusteredRoutePolicyTest { @Test public void test() throws Exception { - ZooKeeperContainer container = null; - - try { - container = new ZooKeeperContainer(); - container.start(); - - String connectString = container.getConnectionString(); - for (String id : CLIENTS) { - SCHEDULER.submit(() -> run(connectString, id)); - } - - LATCH.await(1, TimeUnit.MINUTES); - SCHEDULER.shutdownNow(); - - assertEquals(CLIENTS.size(), RESULTS.size()); - assertTrue(RESULTS.containsAll(CLIENTS)); - } finally { - if (container != null) { - container.stop(); - } + String connectString = service.getConnectionString(); + for (String id : CLIENTS) { + SCHEDULER.submit(() -> run(connectString, id)); } + + LATCH.await(1, TimeUnit.MINUTES); + SCHEDULER.shutdownNow(); + + assertEquals(CLIENTS.size(), RESULTS.size()); + assertTrue(RESULTS.containsAll(CLIENTS)); } // ************************************ diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterTest.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterTest.java index 7f7ac77..6b153ed 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterTest.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cluster/ZooKeeperMasterTest.java @@ -27,9 +27,11 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.zookeeper.ZooKeeperContainer; import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperService; +import org.apache.camel.test.infra.zookeeper.services.ZooKeeperServiceFactory; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,6 +39,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; public final class ZooKeeperMasterTest { + @RegisterExtension + static ZooKeeperService service = ZooKeeperServiceFactory.createService(); + private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperMasterTest.class); private static final List<String> CLIENTS = IntStream.range(0, 3).mapToObj(Integer::toString).collect(Collectors.toList()); private static final List<String> RESULTS = new ArrayList<>(); @@ -49,27 +54,16 @@ public final class ZooKeeperMasterTest { @Test public void test() throws Exception { - ZooKeeperContainer container = null; - - try { - container = new ZooKeeperContainer(); - container.start(); - - String connectString = container.getConnectionString(); - for (String id : CLIENTS) { - SCHEDULER.submit(() -> run(connectString, id)); - } - - LATCH.await(1, TimeUnit.MINUTES); - SCHEDULER.shutdownNow(); - - assertEquals(CLIENTS.size(), RESULTS.size()); - assertTrue(RESULTS.containsAll(CLIENTS)); - } finally { - if (container != null) { - container.stop(); - } + String connectString = service.getConnectionString(); + for (String id : CLIENTS) { + SCHEDULER.submit(() -> run(connectString, id)); } + + LATCH.await(1, TimeUnit.MINUTES); + SCHEDULER.shutdownNow(); + + assertEquals(CLIENTS.size(), RESULTS.size()); + assertTrue(RESULTS.containsAll(CLIENTS)); } // ************************************ diff --git a/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.xml b/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.xml index f622a04..71d8738 100644 --- a/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.xml +++ b/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cloud/SpringZooKeeperServiceCallRouteTest.xml @@ -34,7 +34,7 @@ <route id="scall"> <from uri="direct:start"/> <serviceCall name="http-service" component="http"> - <zookeeperServiceDiscovery nodes="{{container:host:zookeeper}}:{{container:port:2181@zookeeper}}" basePath="/camel"/> + <zookeeperServiceDiscovery nodes="{{zookeeper.connection.string}}" basePath="/camel"/> </serviceCall> <to uri="mock:result"/> </route> diff --git a/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cluster/SpringZooKeeperClusteredRouteConfigurationTest.xml b/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cluster/SpringZooKeeperClusteredRouteConfigurationTest.xml index 2b91015..a0d6e3a 100644 --- a/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cluster/SpringZooKeeperClusteredRouteConfigurationTest.xml +++ b/components/camel-zookeeper/src/test/resources/org/apache/camel/component/zookeeper/cluster/SpringZooKeeperClusteredRouteConfigurationTest.xml @@ -25,7 +25,7 @@ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> - <bean id="zkContainer" class="org.apache.camel.component.zookeeper.ZooKeeperContainer" init-method="start" destroy-method="start"> + <bean id="zkContainer" class="org.apache.camel.test.infra.zookeeper.services.ZooKeeperContainer" init-method="start" destroy-method="start"> <constructor-arg> <value>zookeeper</value> </constructor-arg> diff --git a/test-infra/camel-test-infra-zookeeper/pom.xml b/test-infra/camel-test-infra-zookeeper/pom.xml new file mode 100644 index 0000000..beabf35 --- /dev/null +++ b/test-infra/camel-test-infra-zookeeper/pom.xml @@ -0,0 +1,60 @@ +<?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.7.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <artifactId>camel-test-infra-zookeeper</artifactId> + <name>Camel :: Test Infra :: ZooKeeper</name> + + <dependencies> + <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.testcontainers</groupId> + <artifactId>testcontainers</artifactId> + </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-zookeeper/src/main/resources/META-INF/MANIFEST.MF b/test-infra/camel-test-infra-zookeeper/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e69de29 diff --git a/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/common/ZooKeeperProperties.java b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/common/ZooKeeperProperties.java new file mode 100644 index 0000000..e1eb495 --- /dev/null +++ b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/common/ZooKeeperProperties.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.zookeeper.common; + +public final class ZooKeeperProperties { + public static final String CONNECTION_STRING = "zookeeper.connection.string"; + + private ZooKeeperProperties() { + + } +} diff --git a/components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/ZKContainer.java b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperContainer.java similarity index 73% rename from components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/ZKContainer.java rename to test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperContainer.java index d1eba96..4d90dd3 100644 --- a/components/camel-zookeeper-master/src/test/java/org/apache/camel/component/zookeepermaster/ZKContainer.java +++ b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperContainer.java @@ -14,43 +14,46 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.component.zookeepermaster; +package org.apache.camel.test.infra.zookeeper.services; +import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; -public class ZKContainer extends GenericContainer { +public class ZooKeeperContainer extends GenericContainer { public static final String CONTAINER_IMAGE = "zookeeper:3.5"; public static final String CONTAINER_NAME = "zookeeper"; public static final int CLIENT_PORT = 2181; - public ZKContainer() { + private static final Logger LOGGER = LoggerFactory.getLogger(ZooKeeperContainer.class); + + public ZooKeeperContainer() { this(CONTAINER_NAME, -1); } - public ZKContainer(int clientPort) { + public ZooKeeperContainer(int clientPort) { this(CONTAINER_NAME, clientPort); } - public ZKContainer(String name) { + public ZooKeeperContainer(String name) { this(name, -1); setWaitStrategy(Wait.forListeningPort()); withNetworkAliases(name); withExposedPorts(CLIENT_PORT); - withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(ZKContainer.class))); + withLogConsumer(new Slf4jLogConsumer(LOGGER)); } - public ZKContainer(String name, int clientPort) { + public ZooKeeperContainer(String name, int clientPort) { super(CONTAINER_IMAGE); setWaitStrategy(Wait.forListeningPort()); withNetworkAliases(name); - withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(ZKContainer.class))); + withLogConsumer(new Slf4jLogConsumer(LOGGER)); if (clientPort > 0) { addFixedExposedPort(clientPort, CLIENT_PORT); @@ -60,6 +63,6 @@ public class ZKContainer extends GenericContainer { } public String getConnectionString() { - return getContainerIpAddress() + ":" + getMappedPort(CLIENT_PORT); + return String.format("%s:%d", getContainerIpAddress(), getMappedPort(CLIENT_PORT)); } } diff --git a/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperLocalContainerService.java b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperLocalContainerService.java new file mode 100644 index 0000000..00eaf56 --- /dev/null +++ b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperLocalContainerService.java @@ -0,0 +1,72 @@ +/* + * 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.zookeeper.services; + +import org.apache.camel.test.infra.common.services.ContainerService; +import org.apache.camel.test.infra.zookeeper.common.ZooKeeperProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ZooKeeperLocalContainerService implements ZooKeeperService, ContainerService<ZooKeeperContainer> { + private static final Logger LOG = LoggerFactory.getLogger(ZooKeeperLocalContainerService.class); + + private ZooKeeperContainer container; + + public ZooKeeperLocalContainerService() { + String imageName = System.getProperty("zookeeper.container"); + + if (imageName == null) { + container = new ZooKeeperContainer(); + } else { + container = new ZooKeeperContainer(imageName); + } + } + + public ZooKeeperLocalContainerService(String imageName) { + container = new ZooKeeperContainer(imageName); + } + + @Override + public void registerProperties() { + System.setProperty(ZooKeeperProperties.CONNECTION_STRING, getConnectionString()); + } + + @Override + public void initialize() { + LOG.info("Trying to start the ZooKeeper container"); + container.start(); + + registerProperties(); + LOG.info("ZooKeeper instance running at {}", getConnectionString()); + } + + @Override + public void shutdown() { + LOG.info("Stopping the ZooKeeper container"); + container.stop(); + } + + @Override + public ZooKeeperContainer getContainer() { + return container; + } + + @Override + public String getConnectionString() { + return container.getConnectionString(); + } +} diff --git a/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperRemoteService.java b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperRemoteService.java new file mode 100644 index 0000000..4da0ad5 --- /dev/null +++ b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperRemoteService.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.zookeeper.services; + +import org.apache.camel.test.infra.zookeeper.common.ZooKeeperProperties; + +public class ZooKeeperRemoteService implements ZooKeeperService { + + @Override + public void registerProperties() { + // NO-OP + } + + @Override + public void initialize() { + registerProperties(); + } + + @Override + public void shutdown() { + // NO-OP + } + + @Override + public String getConnectionString() { + return System.getProperty(ZooKeeperProperties.CONNECTION_STRING); + } +} diff --git a/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperService.java b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperService.java new file mode 100644 index 0000000..86cb1b6 --- /dev/null +++ b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperService.java @@ -0,0 +1,39 @@ +/* + * 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.zookeeper.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 ZooKeeper + */ +public interface ZooKeeperService extends BeforeAllCallback, AfterAllCallback, TestService { + String getConnectionString(); + + @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-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperServiceFactory.java b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperServiceFactory.java new file mode 100644 index 0000000..9134ac1 --- /dev/null +++ b/test-infra/camel-test-infra-zookeeper/src/test/java/org/apache/camel/test/infra/zookeeper/services/ZooKeeperServiceFactory.java @@ -0,0 +1,43 @@ +/* + * 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.zookeeper.services; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class ZooKeeperServiceFactory { + private static final Logger LOG = LoggerFactory.getLogger(ZooKeeperServiceFactory.class); + + private ZooKeeperServiceFactory() { + + } + + public static ZooKeeperService createService() { + String instanceType = System.getProperty("zookeeper.instance.type"); + + if (instanceType == null || instanceType.equals("local-zookeeper-container")) { + return new ZooKeeperLocalContainerService(); + } + + if (instanceType.equals("remote")) { + return new ZooKeeperRemoteService(); + } + + LOG.error("ZooKeeper instance must be one of 'local-zookeeper-container' or 'remote"); + throw new UnsupportedOperationException("Invalid ZooKeeper instance type"); + } +} diff --git a/test-infra/pom.xml b/test-infra/pom.xml index 598481c..057bbd0 100644 --- a/test-infra/pom.xml +++ b/test-infra/pom.xml @@ -63,5 +63,6 @@ <module>camel-test-infra-nsq</module> <module>camel-test-infra-pulsar</module> <module>camel-test-infra-xmpp</module> + <module>camel-test-infra-zookeeper</module> </modules> </project>