Skip to content

Commit 46ec3e3

Browse files
committed
Polish "Support service connections for redis-stack and redis-stack-server"
See gh-41327
1 parent 2634d0c commit 46ec3e3

File tree

8 files changed

+87
-82
lines changed

8 files changed

+87
-82
lines changed

spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/redis/RedisDockerComposeConnectionDetailsFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
*/
3434
class RedisDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<RedisConnectionDetails> {
3535

36-
private static final String[] REDIS_IMAGE_NAMES = { "redis", "bitnami/redis", "redis/redis-stack",
36+
private static final String[] REDIS_CONTAINER_NAMES = { "redis", "bitnami/redis", "redis/redis-stack",
3737
"redis/redis-stack-server" };
3838

3939
private static final int REDIS_PORT = 6379;
4040

4141
RedisDockerComposeConnectionDetailsFactory() {
42-
super(REDIS_IMAGE_NAMES);
42+
super(REDIS_CONTAINER_NAMES);
4343
}
4444

4545
@Override

spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/testcontainers.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The following service connection factories are provided in the `spring-boot-test
8787
| Containers of type `RabbitMQContainer`
8888

8989
| `RedisConnectionDetails`
90-
| Containers named "redis", "bitnami/redis", "redis/redis-stack" or "redis/redis-stack-server"
90+
| Containers named "redis", "redis/redis-stack" or "redis/redis-stack-server"
9191

9292
| `ZipkinConnectionDetails`
9393
| Containers named "openzipkin/zipkin"

spring-boot-project/spring-boot-testcontainers/src/dockerTest/java/org/springframework/boot/testcontainers/service/connection/redis/BitnamiRedisContainerConnectionDetailsFactoryTests.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

spring-boot-project/spring-boot-testcontainers/src/dockerTest/java/org/springframework/boot/testcontainers/service/connection/redis/RedisStackContainerConnectionDetailsFactoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.testcontainers.service.connection.redis;
1818

1919
import org.junit.jupiter.api.Test;
20-
import org.testcontainers.containers.GenericContainer;
2120
import org.testcontainers.junit.jupiter.Container;
2221
import org.testcontainers.junit.jupiter.Testcontainers;
2322

@@ -26,6 +25,7 @@
2625
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
2726
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails;
2827
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
28+
import org.springframework.boot.testsupport.container.RedisStackContainer;
2929
import org.springframework.boot.testsupport.container.TestImage;
3030
import org.springframework.context.annotation.Configuration;
3131
import org.springframework.data.redis.connection.RedisConnection;
@@ -46,7 +46,7 @@ class RedisStackContainerConnectionDetailsFactoryTests {
4646

4747
@Container
4848
@ServiceConnection
49-
static final GenericContainer<?> redis = TestImage.REDIS_STACK.genericContainer().withExposedPorts(6379);
49+
static final RedisStackContainer redis = TestImage.container(RedisStackContainer.class);
5050

5151
@Autowired(required = false)
5252
private RedisConnectionDetails connectionDetails;

spring-boot-project/spring-boot-testcontainers/src/dockerTest/java/org/springframework/boot/testcontainers/service/connection/redis/RedisStackServerContainerConnectionDetailsFactoryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.testcontainers.service.connection.redis;
1818

1919
import org.junit.jupiter.api.Test;
20-
import org.testcontainers.containers.GenericContainer;
2120
import org.testcontainers.junit.jupiter.Container;
2221
import org.testcontainers.junit.jupiter.Testcontainers;
2322

@@ -26,6 +25,7 @@
2625
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
2726
import org.springframework.boot.autoconfigure.data.redis.RedisConnectionDetails;
2827
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
28+
import org.springframework.boot.testsupport.container.RedisStackServerContainer;
2929
import org.springframework.boot.testsupport.container.TestImage;
3030
import org.springframework.context.annotation.Configuration;
3131
import org.springframework.data.redis.connection.RedisConnection;
@@ -46,7 +46,7 @@ class RedisStackServerContainerConnectionDetailsFactoryTests {
4646

4747
@Container
4848
@ServiceConnection
49-
static final GenericContainer<?> redis = TestImage.REDIS_STACK_SERVER.genericContainer().withExposedPorts(6379);
49+
static final RedisStackServerContainer redis = TestImage.container(RedisStackServerContainer.class);
5050

5151
@Autowired(required = false)
5252
private RedisConnectionDetails connectionDetails;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.testsupport.container;
18+
19+
import org.testcontainers.containers.GenericContainer;
20+
import org.testcontainers.utility.DockerImageName;
21+
22+
/**
23+
* A {@link GenericContainer} for Redis Stack.
24+
*
25+
* @author Andy Wilkinson
26+
* @author Madhura Bhave
27+
*/
28+
public class RedisStackContainer extends GenericContainer<RedisStackContainer> {
29+
30+
public RedisStackContainer(DockerImageName dockerImageName) {
31+
super(dockerImageName);
32+
addExposedPorts(6379);
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.testsupport.container;
18+
19+
import org.testcontainers.containers.GenericContainer;
20+
import org.testcontainers.utility.DockerImageName;
21+
22+
/**
23+
* A {@link GenericContainer} for Redis Stack Server.
24+
*
25+
* @author Andy Wilkinson
26+
* @author Madhura Bhave
27+
*/
28+
public class RedisStackServerContainer extends GenericContainer<RedisStackServerContainer> {
29+
30+
public RedisStackServerContainer(DockerImageName dockerImageName) {
31+
super(dockerImageName);
32+
addExposedPorts(6379);
33+
}
34+
35+
}

spring-boot-project/spring-boot-tools/spring-boot-test-support-docker/src/main/java/org/springframework/boot/testsupport/container/TestImage.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,16 @@ public enum TestImage {
186186
/**
187187
* A container image suitable for testing Redis Stack.
188188
*/
189-
REDIS_STACK("redis/redis-stack", "7.2.0-v11"),
189+
REDIS_STACK("redis/redis-stack", "7.2.0-v11", () -> RedisStackContainer.class,
190+
(container) -> ((RedisStackContainer) container).withStartupAttempts(5)
191+
.withStartupTimeout(Duration.ofMinutes(10))),
190192

191193
/**
192194
* A container image suitable for testing Redis Stack Server.
193195
*/
194-
REDIS_STACK_SERVER("redis/redis-stack-server", "7.2.0-v11"),
196+
REDIS_STACK_SERVER("redis/redis-stack-server", "7.2.0-v11", () -> RedisStackServerContainer.class,
197+
(container) -> ((RedisStackServerContainer) container).withStartupAttempts(5)
198+
.withStartupTimeout(Duration.ofMinutes(10))),
195199

196200
/**
197201
* A container image suitable for testing Redpanda.
@@ -281,6 +285,10 @@ public enum TestImage {
281285
this(name, tag, containerClass, null);
282286
}
283287

288+
TestImage(String name, String tag, Consumer<?> containerSetup) {
289+
this(name, tag, null, containerSetup);
290+
}
291+
284292
TestImage(String name, String tag, Supplier<Class<?>> containerClass, Consumer<?> containerSetup) {
285293
this.name = name;
286294
this.tag = tag;

0 commit comments

Comments
 (0)