Skip to content

Commit 570a8ec

Browse files
author
Corneil du Plessis
committed
Upodated aggregator RedisMessageStoreAggregatorTests to use RedisTestContainerSupport.
1 parent 3aa662f commit 570a8ec

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

applications/sink/redis-sink/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
<relativePath>../../stream-applications-core/pom.xml</relativePath>
1515
</parent>
1616

17-
<properties>
18-
<embedded-redis.version>2.0.11</embedded-redis.version>
19-
</properties>
20-
2117
<dependencies>
2218
<dependency>
2319
<groupId>org.springframework.cloud.fn</groupId>

functions/common/redis-common/src/test/java/org/springframework/cloud/fn/consumer/redis/RedisTestContainerSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
@Testcontainers(disabledWithoutDocker = true)
3131
public interface RedisTestContainerSupport {
32-
GenericContainer<?> REDIS_CONTAINER = new GenericContainer<>("redis:7.0.2")
32+
GenericContainer<?> REDIS_CONTAINER = new GenericContainer<>("redis:7")
3333
.withExposedPorts(6379)
3434
.withStartupTimeout(Duration.ofSeconds(120))
3535
.withStartupAttempts(3);

functions/function/aggregator-function/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
<artifactId>spring-boot-starter-data-redis</artifactId>
5252
<scope>runtime</scope>
5353
</dependency>
54+
<dependency>
55+
<groupId>org.springframework.cloud.fn</groupId>
56+
<artifactId>redis-common</artifactId>
57+
<version>${project.version}</version>
58+
<type>test-jar</type>
59+
<scope>test</scope>
60+
</dependency>
5461
<!--JDBC-->
5562
<dependency>
5663
<groupId>org.springframework.integration</groupId>

functions/function/aggregator-function/src/test/java/org/springframework/cloud/fn/aggregator/RedisMessageStoreAggregatorTests.java

+27-22
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@
1919
import java.time.Duration;
2020
import java.util.List;
2121

22-
import org.junit.jupiter.api.Disabled;
2322
import org.junit.jupiter.api.Test;
2423
import reactor.core.publisher.Flux;
2524
import reactor.test.StepVerifier;
2625

26+
import org.springframework.cloud.fn.consumer.redis.RedisTestContainerSupport;
2727
import org.springframework.integration.IntegrationMessageHeaderAccessor;
2828
import org.springframework.integration.redis.store.RedisMessageStore;
2929
import org.springframework.integration.support.MessageBuilder;
3030
import org.springframework.messaging.Message;
31+
import org.springframework.test.context.DynamicPropertyRegistry;
32+
import org.springframework.test.context.DynamicPropertySource;
3133
import org.springframework.test.context.TestPropertySource;
3234

3335
import static org.assertj.core.api.Assertions.assertThat;
@@ -36,35 +38,38 @@
3638
* @author Artem Bilan
3739
*/
3840
@TestPropertySource(properties = "aggregator.message-store-type=redis")
39-
@Disabled("Needs real Redis Server to be run") // TODO add redis test container
40-
public class RedisMessageStoreAggregatorTests extends AbstractAggregatorFunctionTests {
41+
public class RedisMessageStoreAggregatorTests extends AbstractAggregatorFunctionTests implements RedisTestContainerSupport {
42+
@DynamicPropertySource
43+
static void redisProperties(DynamicPropertyRegistry registry) {
44+
registry.add("spring.data.redis.url", RedisTestContainerSupport::getUri);
45+
}
4146

4247
@Test
4348
public void test() {
4449
Flux<Message<?>> input =
45-
Flux.just(MessageBuilder.withPayload("2")
46-
.setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "my_correlation")
47-
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, 2)
48-
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, 2)
49-
.build(),
50-
MessageBuilder.withPayload("1")
51-
.setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "my_correlation")
52-
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, 1)
53-
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, 2)
54-
.build());
50+
Flux.just(MessageBuilder.withPayload("2")
51+
.setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "my_correlation")
52+
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, 2)
53+
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, 2)
54+
.build(),
55+
MessageBuilder.withPayload("1")
56+
.setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "my_correlation")
57+
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, 1)
58+
.setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, 2)
59+
.build());
5560

5661
Flux<Message<?>> output = this.aggregatorFunction.apply(input);
5762

5863
output.as(StepVerifier::create)
59-
.assertNext((message) ->
60-
assertThat(message)
61-
.extracting(Message::getPayload)
62-
.isInstanceOf(List.class)
63-
.asList()
64-
.hasSize(2)
65-
.contains("1", "2"))
66-
.thenCancel()
67-
.verify(Duration.ofSeconds(10));
64+
.assertNext((message) ->
65+
assertThat(message)
66+
.extracting(Message::getPayload)
67+
.isInstanceOf(List.class)
68+
.asList()
69+
.hasSize(2)
70+
.contains("1", "2"))
71+
.thenCancel()
72+
.verify(Duration.ofSeconds(10));
6873

6974
assertThat(this.messageGroupStore).isInstanceOf(RedisMessageStore.class);
7075

0 commit comments

Comments
 (0)