Adding redis-common and disable elasticsearch.

This commit is contained in:
Corneil du Plessis
2022-10-06 22:43:17 +02:00
parent 68f2900aad
commit b5ed0bdf1e
10 changed files with 111 additions and 21 deletions

View File

@@ -19,6 +19,7 @@
<module>geode-common</module>
<module>metadata-store-common</module>
<module>mqtt-common</module>
<module>redis-common</module>
<module>tcp-common</module>
<module>twitter-common</module>
<module>tensorflow-common</module>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud.fn</groupId>
<artifactId>spring-functions-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../spring-functions-parent/pom.xml</relativePath>
</parent>
<artifactId>redis-common</artifactId>
<name>redis-common</name>
<description>Redis Common</description>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>Jar Tests Package</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1 @@
# empty

View File

@@ -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();
}
}

View File

@@ -26,7 +26,7 @@
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.15.2</version>
<version>${elasticsearch.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -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 {

View File

@@ -14,10 +14,6 @@
<name>redis-consumer</name>
<description>Redis Consumer</description>
<properties>
<embedded-redis.version>2.0.11</embedded-redis.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -27,18 +23,24 @@
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-redis</artifactId>
</dependency>
<dependency>
<groupId>com.playtika.testcontainers</groupId>
<artifactId>embedded-redis</artifactId>
<version>${embedded-redis.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>${spring-cloud-starters.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud.fn</groupId>
<artifactId>redis-common</artifactId>
<version>4.0.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -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<Message<?>> redisConsumer;

View File

@@ -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.<Topic>singletonList(new ChannelTopic(topic)));
container.start();
Awaitility.await().until(() -> TestUtils.getPropertyValue(container, "subscriptionTask.connection",
RedisConnection.class) != null);
Awaitility.await().until(container::isListening);
Message<String> message = MessageBuilder.withPayload("hello").build();
for (int i = 0; i < numToTest; i++) {

View File

@@ -1,3 +1 @@
spring.redis.host=${embedded.redis.host}
spring.redis.port=${embedded.redis.port}
spring.redis.password=${embedded.redis.password}
# Empty