This is an automated email from the ASF dual-hosted git repository. aldettinger 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 d85f230 Ported camel-redis test to camel-test-infra d85f230 is described below commit d85f230d1b7acaee2594e5fc1b561dd2e4eb3268 Author: aldettinger <aldettin...@gmail.com> AuthorDate: Mon Jan 4 16:36:10 2021 +0100 Ported camel-redis test to camel-test-infra --- components/camel-redis/pom.xml | 82 ++++++++++++++++++++ .../processor/aggregate/AggregateRedisTest.java | 18 ++--- .../camel-test-infra-redis}/pom.xml | 56 +++++--------- .../src/main/resources/META-INF/MANIFEST.MF | 0 .../test/infra/redis/common/RedisProperties.java | 29 +++++++ .../redis/services/RedisLocalContainerService.java | 88 ++++++++++++++++++++++ .../infra/redis/services/RedisRemoteService.java | 54 +++++++++++++ .../test/infra/redis/services/RedisService.java | 46 +++++++++++ .../infra/redis/services/RedisServiceFactory.java | 43 +++++++++++ test-infra/pom.xml | 1 + 10 files changed, 369 insertions(+), 48 deletions(-) diff --git a/components/camel-redis/pom.xml b/components/camel-redis/pom.xml index 23739a3..637fecd 100644 --- a/components/camel-redis/pom.xml +++ b/components/camel-redis/pom.xml @@ -64,6 +64,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-redis</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + </dependencies> <build> @@ -79,4 +96,69 @@ </plugins> </build> + <profiles> + <profile> + <id>redis-skip-tests</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>true</skipTests> + </configuration> + </plugin> + </plugins> + </build> + </profile> + + <!-- activate test if the docker socket file is accessible --> + <profile> + <id>redis-tests-docker-file</id> + <activation> + <file> + <exists>/var/run/docker.sock</exists> + </file> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>${skipTests}</skipTests> + <systemPropertyVariables> + <visibleassertions.silence>true</visibleassertions.silence> + </systemPropertyVariables> + </configuration> + </plugin> + </plugins> + </build> + </profile> + + <!-- activate test if the DOCKER_HOST env var is set --> + <profile> + <id>redis-tests-docker-env</id> + <activation> + <property> + <name>env.DOCKER_HOST</name> + </property> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skipTests>${skipTests}</skipTests> + <systemPropertyVariables> + <visibleassertions.silence>true</visibleassertions.silence> + </systemPropertyVariables> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> + </project> diff --git a/components/camel-redis/src/test/java/org/apache/camel/component/redis/processor/aggregate/AggregateRedisTest.java b/components/camel-redis/src/test/java/org/apache/camel/component/redis/processor/aggregate/AggregateRedisTest.java index 5629c8d..ea304ba 100644 --- a/components/camel-redis/src/test/java/org/apache/camel/component/redis/processor/aggregate/AggregateRedisTest.java +++ b/components/camel-redis/src/test/java/org/apache/camel/component/redis/processor/aggregate/AggregateRedisTest.java @@ -18,23 +18,23 @@ package org.apache.camel.component.redis.processor.aggregate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.infra.redis.services.RedisService; +import org.apache.camel.test.infra.redis.services.RedisServiceFactory; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; /** * The ABC example for using the Aggregator EIP. * <p/> - * This example have 4 messages send to the aggregator, by which one message is published which contains the aggregation + * This example have 4 messages sent to the aggregator, by which one message is published which contains the aggregation * of message 1,2 and 4 as they use the same correlation key. * <p/> */ -@Disabled("Requires manually testing") public class AggregateRedisTest extends CamelTestSupport { - // TODO: use docker test-containers for testing - - private String endpoint = System.getProperty("endpoint"); //ip:port + @RegisterExtension + static RedisService service = RedisServiceFactory.createService(); @Test public void testABC() throws Exception { @@ -50,14 +50,14 @@ public class AggregateRedisTest extends CamelTestSupport { } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("direct:start") .log("Sending ${body} with correlation key ${header.myId}") .aggregate(header("myId"), new MyAggregationStrategy()) - .aggregationRepository(new RedisAggregationRepository("aggregation", endpoint)) + .aggregationRepository(new RedisAggregationRepository("aggregation", service.getServiceAddress())) .completionSize(3) .log("Sending out ${body}") .to("mock:result"); diff --git a/components/camel-redis/pom.xml b/test-infra/camel-test-infra-redis/pom.xml similarity index 50% copy from components/camel-redis/pom.xml copy to test-infra/camel-test-infra-redis/pom.xml index 23739a3..985625a 100644 --- a/components/camel-redis/pom.xml +++ b/test-infra/camel-test-infra-redis/pom.xml @@ -17,66 +17,44 @@ 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/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - +<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> - <artifactId>components</artifactId> + <relativePath>../camel-test-infra-parent/pom.xml</relativePath> <version>3.8.0-SNAPSHOT</version> </parent> - <artifactId>camel-redis</artifactId> - <packaging>jar</packaging> - <name>Camel :: Redis</name> - <description>Aggregation repository using Redis as datastore</description> + <modelVersion>4.0.0</modelVersion> - <properties> - <firstVersion>3.5.0</firstVersion> - <label>database</label> - <supportLevel>Preview</supportLevel> - </properties> + <artifactId>camel-test-infra-redis</artifactId> + <name>Camel :: Test Infra :: Redis</name> <dependencies> - - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-support</artifactId> - </dependency> - - <dependency> - <groupId>org.redisson</groupId> - <artifactId>redisson</artifactId> - <version>${redisson-version}</version> - </dependency> - - <!-- testing --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-test-junit5</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> - <scope>test</scope> + <groupId>org.testcontainers</groupId> + <artifactId>testcontainers</artifactId> </dependency> - </dependencies> <build> <plugins> <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <systemPropertyVariables> - <endpoint>${endpoint}</endpoint> - </systemPropertyVariables> - </configuration> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> </plugin> </plugins> </build> + </project> diff --git a/test-infra/camel-test-infra-redis/src/main/resources/META-INF/MANIFEST.MF b/test-infra/camel-test-infra-redis/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..e69de29 diff --git a/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/common/RedisProperties.java b/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/common/RedisProperties.java new file mode 100644 index 0000000..b6a3922 --- /dev/null +++ b/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/common/RedisProperties.java @@ -0,0 +1,29 @@ +/* + * 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.redis.common; + +public final class RedisProperties { + public static final String SERVICE_ADDRESS = "redis.service.address"; + public static final String HOST = "redis.host"; + public static final String PORT = "redis.port"; + public static final int DEFAULT_PORT = 6379; + + private RedisProperties() { + + } +} diff --git a/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisLocalContainerService.java b/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisLocalContainerService.java new file mode 100644 index 0000000..50a0f00 --- /dev/null +++ b/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisLocalContainerService.java @@ -0,0 +1,88 @@ +/* + * 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.redis.services; + +import org.apache.camel.test.infra.common.services.ContainerService; +import org.apache.camel.test.infra.redis.common.RedisProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; + +public class RedisLocalContainerService implements RedisService, ContainerService<GenericContainer> { + public static final String CONTAINER_IMAGE = "redis:6.0.9"; + public static final String CONTAINER_NAME = "redis"; + + private static final Logger LOG = LoggerFactory.getLogger(RedisLocalContainerService.class); + + private GenericContainer container; + + public RedisLocalContainerService() { + String containerName = System.getProperty("redis.container", CONTAINER_IMAGE); + + initContainer(containerName); + } + + public RedisLocalContainerService(String imageName) { + initContainer(imageName); + } + + protected void initContainer(String imageName) { + container = new GenericContainer<>(DockerImageName.parse(imageName)) + .withNetworkAliases(CONTAINER_NAME) + .withExposedPorts(RedisProperties.DEFAULT_PORT) + .waitingFor(Wait.forListeningPort()); + } + + @Override + public void registerProperties() { + System.setProperty(RedisProperties.SERVICE_ADDRESS, getServiceAddress()); + System.setProperty(RedisProperties.PORT, String.valueOf(port())); + System.setProperty(RedisProperties.HOST, host()); + } + + @Override + public void initialize() { + LOG.info("Trying to start the Redis container"); + container.start(); + + registerProperties(); + LOG.info("Redis instance running at {}", getServiceAddress()); + } + + @Override + public void shutdown() { + LOG.info("Stopping the Redis container"); + container.stop(); + } + + @Override + public GenericContainer getContainer() { + return container; + } + + @Override + public String host() { + return container.getContainerIpAddress(); + } + + @Override + public int port() { + return container.getMappedPort(RedisProperties.DEFAULT_PORT); + } +} diff --git a/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisRemoteService.java b/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisRemoteService.java new file mode 100644 index 0000000..f4ea83e --- /dev/null +++ b/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisRemoteService.java @@ -0,0 +1,54 @@ +/* + * 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.redis.services; + +import org.apache.camel.test.infra.redis.common.RedisProperties; + +public class RedisRemoteService implements RedisService { + + @Override + public void registerProperties() { + // NO-OP + } + + @Override + public void initialize() { + registerProperties(); + } + + @Override + public void shutdown() { + // NO-OP + } + + @Override + public String host() { + return System.getProperty(RedisProperties.HOST); + } + + @Override + public int port() { + String port = System.getProperty(RedisProperties.PORT); + + if (port == null) { + return RedisProperties.DEFAULT_PORT; + } + + return Integer.valueOf(port); + } + +} diff --git a/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisService.java b/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisService.java new file mode 100644 index 0000000..ec73f3a --- /dev/null +++ b/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisService.java @@ -0,0 +1,46 @@ +/* + * 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.redis.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 Redis + */ +public interface RedisService extends BeforeAllCallback, AfterAllCallback, TestService { + + String host(); + + int port(); + + default String getServiceAddress() { + return String.format("%s:%d", host(), port()); + } + + @Override + default void beforeAll(ExtensionContext extensionContext) { + initialize(); + } + + @Override + default void afterAll(ExtensionContext extensionContext) { + shutdown(); + } +} diff --git a/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisServiceFactory.java b/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisServiceFactory.java new file mode 100644 index 0000000..0e7cd30 --- /dev/null +++ b/test-infra/camel-test-infra-redis/src/test/java/org/apache/camel/test/infra/redis/services/RedisServiceFactory.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.redis.services; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class RedisServiceFactory { + private static final Logger LOG = LoggerFactory.getLogger(RedisServiceFactory.class); + + private RedisServiceFactory() { + + } + + public static RedisService createService() { + String instanceType = System.getProperty("redis.instance.type"); + + if (instanceType == null || instanceType.equals("local-redis-container")) { + return new RedisLocalContainerService(); + } + + if (instanceType.equals("remote")) { + return new RedisRemoteService(); + } + + LOG.error("The property \"redis.instance.type\" must be one of 'local-redis-container' or 'remote"); + throw new UnsupportedOperationException("Invalid Redis instance type"); + } +} diff --git a/test-infra/pom.xml b/test-infra/pom.xml index ce8ae4c..d3acc33 100644 --- a/test-infra/pom.xml +++ b/test-infra/pom.xml @@ -62,6 +62,7 @@ <module>camel-test-infra-nats</module> <module>camel-test-infra-nsq</module> <module>camel-test-infra-pulsar</module> + <module>camel-test-infra-redis</module> <module>camel-test-infra-xmpp</module> <module>camel-test-infra-zookeeper</module> <module>camel-test-infra-postgres</module>