Skip to content

Commit 8e9dc35

Browse files
committed
Update @DynamicPropertySource examples regarding changes in Testcontainers
Closes gh-29939
1 parent b8a7aa9 commit 8e9dc35

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

framework-docs/src/docs/asciidoc/testing/testcontext-framework.adoc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,12 +2022,14 @@ properties.
20222022
class ExampleIntegrationTests {
20232023
20242024
@Container
2025-
static RedisContainer redis = new RedisContainer();
2025+
static GenericContainer redis =
2026+
new GenericContainer(DockerImageName.parse("redis:5.0.3-alpine"))
2027+
.withExposedPorts(6379);
20262028
20272029
@DynamicPropertySource
20282030
static void redisProperties(DynamicPropertyRegistry registry) {
20292031
registry.add("redis.host", redis::getHost);
2030-
registry.add("redis.port", redis::getMappedPort);
2032+
registry.add("redis.port", redis::getFirstMappedPort);
20312033
}
20322034
20332035
// tests ...
@@ -2045,13 +2047,15 @@ properties.
20452047
20462048
@Container
20472049
@JvmStatic
2048-
val redis: RedisContainer = RedisContainer()
2050+
val redis: GenericContainer =
2051+
GenericContainer(DockerImageName.parse("redis:5.0.3-alpine"))
2052+
.withExposedPorts(6379)
20492053
20502054
@DynamicPropertySource
20512055
@JvmStatic
20522056
fun redisProperties(registry: DynamicPropertyRegistry) {
20532057
registry.add("redis.host", redis::getHost)
2054-
registry.add("redis.port", redis::getMappedPort)
2058+
registry.add("redis.port", redis::getFirstMappedPort)
20552059
}
20562060
}
20572061

spring-test/src/main/java/org/springframework/test/context/DynamicPropertySource.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,14 +70,16 @@
7070
* class ExampleIntegrationTests {
7171
*
7272
* @Container
73-
* static RedisContainer redis = new RedisContainer();
73+
* static GenericContainer redis =
74+
* new GenericContainer(DockerImageName.parse("redis:5.0.3-alpine"))
75+
* .withExposedPorts(6379);
7476
*
7577
* // ...
7678
*
7779
* @DynamicPropertySource
7880
* static void redisProperties(DynamicPropertyRegistry registry) {
7981
* registry.add("redis.host", redis::getHost);
80-
* registry.add("redis.port", redis::getMappedPort);
82+
* registry.add("redis.port", redis::getFirstMappedPort);
8183
* }
8284
*
8385
* }</pre>

0 commit comments

Comments
 (0)