From b5ed0bdf1e4d33784da8183ec9a36147d96ac5d8 Mon Sep 17 00:00:00 2001 From: Corneil du Plessis Date: Thu, 6 Oct 2022 22:43:17 +0200 Subject: [PATCH] Adding redis-common and disable elasticsearch. --- common/pom.xml | 1 + common/redis-common/pom.xml | 42 +++++++++++++++++++ .../src/main/resources/application.properties | 1 + .../redis/RedisTestContainerSupport.java | 41 ++++++++++++++++++ consumer/elasticsearch-consumer/pom.xml | 2 +- ...ElasticsearchConsumerApplicationTests.java | 2 + consumer/redis-consumer/pom.xml | 22 +++++----- .../redis/AbstractRedisConsumerTests.java | 9 +++- .../redis/RedisConsumerTopicTests.java | 8 +--- .../src/test/resources/application.properties | 4 +- 10 files changed, 111 insertions(+), 21 deletions(-) create mode 100644 common/redis-common/pom.xml create mode 100644 common/redis-common/src/main/resources/application.properties create mode 100644 common/redis-common/src/test/java/org/springframework/cloud/fn/consumer/redis/RedisTestContainerSupport.java diff --git a/common/pom.xml b/common/pom.xml index fae2a428..80c5e784 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -19,6 +19,7 @@ geode-common metadata-store-common mqtt-common + redis-common tcp-common twitter-common tensorflow-common diff --git a/common/redis-common/pom.xml b/common/redis-common/pom.xml new file mode 100644 index 00000000..1a55aaa2 --- /dev/null +++ b/common/redis-common/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + + org.springframework.cloud.fn + spring-functions-parent + 4.0.0-SNAPSHOT + ../../spring-functions-parent/pom.xml + + + redis-common + redis-common + Redis Common + + + + org.testcontainers + testcontainers + test + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.2 + + + Jar Tests Package + package + + test-jar + + + + + + + diff --git a/common/redis-common/src/main/resources/application.properties b/common/redis-common/src/main/resources/application.properties new file mode 100644 index 00000000..1bb8bf6d --- /dev/null +++ b/common/redis-common/src/main/resources/application.properties @@ -0,0 +1 @@ +# empty diff --git a/common/redis-common/src/test/java/org/springframework/cloud/fn/consumer/redis/RedisTestContainerSupport.java b/common/redis-common/src/test/java/org/springframework/cloud/fn/consumer/redis/RedisTestContainerSupport.java new file mode 100644 index 00000000..cbe55d29 --- /dev/null +++ b/common/redis-common/src/test/java/org/springframework/cloud/fn/consumer/redis/RedisTestContainerSupport.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022-2022 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.cloud.fn.consumer.redis; + +import org.junit.jupiter.api.BeforeAll; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Testcontainers; + +/** + * Provides a static Redis Container that can be shared across test classes. + * + * @author Corneil du Plessis + */ +@Testcontainers(disabledWithoutDocker = true) +public interface RedisTestContainerSupport { + GenericContainer REDIS_CONTAINER = new GenericContainer<>("redis:7.0.2") + .withExposedPorts(6379); + + @BeforeAll + static void startContainer() { + REDIS_CONTAINER.start(); + } + + static String getUri() { + return "redis://localhost:" + REDIS_CONTAINER.getFirstMappedPort(); + } +} diff --git a/consumer/elasticsearch-consumer/pom.xml b/consumer/elasticsearch-consumer/pom.xml index ab250980..60859ec1 100644 --- a/consumer/elasticsearch-consumer/pom.xml +++ b/consumer/elasticsearch-consumer/pom.xml @@ -26,7 +26,7 @@ org.elasticsearch.client elasticsearch-rest-high-level-client - 7.15.2 + ${elasticsearch.version} org.springframework.boot diff --git a/consumer/elasticsearch-consumer/src/test/java/org/springframework/cloud/fn/consumer/elasticsearch/ElasticsearchConsumerApplicationTests.java b/consumer/elasticsearch-consumer/src/test/java/org/springframework/cloud/fn/consumer/elasticsearch/ElasticsearchConsumerApplicationTests.java index 1c35fe2e..ed28fd24 100644 --- a/consumer/elasticsearch-consumer/src/test/java/org/springframework/cloud/fn/consumer/elasticsearch/ElasticsearchConsumerApplicationTests.java +++ b/consumer/elasticsearch-consumer/src/test/java/org/springframework/cloud/fn/consumer/elasticsearch/ElasticsearchConsumerApplicationTests.java @@ -31,6 +31,7 @@ import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.testcontainers.elasticsearch.ElasticsearchContainer; @@ -52,6 +53,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Andrea Montemaggio */ @Tag("integration") +@Disabled @Testcontainers(disabledWithoutDocker = true) public class ElasticsearchConsumerApplicationTests { diff --git a/consumer/redis-consumer/pom.xml b/consumer/redis-consumer/pom.xml index 8299b352..b2473299 100644 --- a/consumer/redis-consumer/pom.xml +++ b/consumer/redis-consumer/pom.xml @@ -14,10 +14,6 @@ redis-consumer Redis Consumer - - 2.0.11 - - org.springframework.boot @@ -27,18 +23,24 @@ org.springframework.integration spring-integration-redis - - com.playtika.testcontainers - embedded-redis - ${embedded-redis.version} - test - org.springframework.cloud spring-cloud-starter-bootstrap ${spring-cloud-starters.version} test + + org.testcontainers + testcontainers + test + + + org.springframework.cloud.fn + redis-common + 4.0.0-SNAPSHOT + test-jar + test + diff --git a/consumer/redis-consumer/src/test/java/org/springframework/cloud/fn/consumer/redis/AbstractRedisConsumerTests.java b/consumer/redis-consumer/src/test/java/org/springframework/cloud/fn/consumer/redis/AbstractRedisConsumerTests.java index 36134db1..d7af0153 100644 --- a/consumer/redis-consumer/src/test/java/org/springframework/cloud/fn/consumer/redis/AbstractRedisConsumerTests.java +++ b/consumer/redis-consumer/src/test/java/org/springframework/cloud/fn/consumer/redis/AbstractRedisConsumerTests.java @@ -27,6 +27,8 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.messaging.Message; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; /** * @author Soby Chacko @@ -35,7 +37,12 @@ import org.springframework.test.annotation.DirtiesContext; @SpringBootTest @DirtiesContext @Tag("integration") -public class AbstractRedisConsumerTests { +public class AbstractRedisConsumerTests implements RedisTestContainerSupport { + + @DynamicPropertySource + static void redisProperties(DynamicPropertyRegistry registry) { + registry.add("spring.data.redis.url", RedisTestContainerSupport::getUri); + } @Autowired Consumer> redisConsumer; diff --git a/consumer/redis-consumer/src/test/java/org/springframework/cloud/fn/consumer/redis/RedisConsumerTopicTests.java b/consumer/redis-consumer/src/test/java/org/springframework/cloud/fn/consumer/redis/RedisConsumerTopicTests.java index 6d7ce0dc..f559f882 100644 --- a/consumer/redis-consumer/src/test/java/org/springframework/cloud/fn/consumer/redis/RedisConsumerTopicTests.java +++ b/consumer/redis-consumer/src/test/java/org/springframework/cloud/fn/consumer/redis/RedisConsumerTopicTests.java @@ -44,9 +44,6 @@ import static org.assertj.core.api.Assertions.assertThat; @TestPropertySource(properties = "redis.consumer.topic = foo-topic") public class RedisConsumerTopicTests extends AbstractRedisConsumerTests { - @Autowired - RedisConnectionFactory connectionFactory; - @Test public void testWithTopic() throws Exception { @@ -60,13 +57,12 @@ public class RedisConsumerTopicTests extends AbstractRedisConsumerTests { listener.afterPropertiesSet(); RedisMessageListenerContainer container = new RedisMessageListenerContainer(); - container.setConnectionFactory(connectionFactory); + container.setConnectionFactory(redisTemplate.getConnectionFactory()); container.afterPropertiesSet(); container.addMessageListener(listener, Collections.singletonList(new ChannelTopic(topic))); container.start(); - Awaitility.await().until(() -> TestUtils.getPropertyValue(container, "subscriptionTask.connection", - RedisConnection.class) != null); + Awaitility.await().until(container::isListening); Message message = MessageBuilder.withPayload("hello").build(); for (int i = 0; i < numToTest; i++) { diff --git a/consumer/redis-consumer/src/test/resources/application.properties b/consumer/redis-consumer/src/test/resources/application.properties index a78ad15d..b7db2541 100644 --- a/consumer/redis-consumer/src/test/resources/application.properties +++ b/consumer/redis-consumer/src/test/resources/application.properties @@ -1,3 +1 @@ -spring.redis.host=${embedded.redis.host} -spring.redis.port=${embedded.redis.port} -spring.redis.password=${embedded.redis.password} +# Empty