Skip to content

Commit a657c97

Browse files
committed
Merge pull request #21480 from olamy
* pr/21480: Polish "Use the container IP address for tests using TestContainer" Use the container IP address for tests using TestContainer Closes gh-21480
2 parents afcb5d5 + 77981ac commit a657c97

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationIntegrationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void createBucket() {
7474
void setUp() {
7575
this.context = new AnnotationConfigApplicationContext();
7676
this.context.register(CouchbaseAutoConfiguration.class);
77-
TestPropertyValues.of("spring.couchbase.bootstrap-hosts=localhost",
77+
TestPropertyValues.of("spring.couchbase.bootstrap-hosts=" + couchbase.getContainerIpAddress(),
7878
"spring.couchbase.env.bootstrap.http-direct-port:" + couchbase.getMappedPort(8091),
7979
"spring.couchbase.username:spring", "spring.couchbase.password:password",
8080
"spring.couchbase.bucket.name:default").applyTo(this.context.getEnvironment());

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class CassandraDataAutoConfigurationIntegrationTests {
5656
void setUp() {
5757
this.context = new AnnotationConfigApplicationContext();
5858
TestPropertyValues
59-
.of("spring.data.cassandra.port=" + cassandra.getFirstMappedPort(),
59+
.of("spring.data.cassandra.contact-points=" + cassandra.getContainerIpAddress(),
60+
"spring.data.cassandra.port=" + cassandra.getFirstMappedPort(),
6061
"spring.data.cassandra.read-timeout=24000", "spring.data.cassandra.connect-timeout=10000")
6162
.applyTo(this.context.getEnvironment());
6263
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -54,7 +54,8 @@ class RedisRepositoriesAutoConfigurationTests {
5454

5555
@BeforeEach
5656
void setUp() {
57-
TestPropertyValues.of("spring.redis.port=" + redis.getFirstMappedPort()).applyTo(this.context.getEnvironment());
57+
TestPropertyValues.of("spring.redis.host=" + redis.getContainerIpAddress(),
58+
"spring.redis.port=" + redis.getFirstMappedPort()).applyTo(this.context.getEnvironment());
5859
}
5960

6061
@AfterEach

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -63,9 +63,8 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
6363

6464
@Test
6565
void defaultConfig() {
66-
this.contextRunner
67-
.withPropertyValues("spring.session.store-type=redis",
68-
"spring.redis.port=" + redis.getFirstMappedPort())
66+
this.contextRunner.withPropertyValues("spring.session.store-type=redis",
67+
"spring.redis.host=" + redis.getContainerIpAddress(), "spring.redis.port=" + redis.getFirstMappedPort())
6968
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
7069
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE,
7170
SaveMode.ON_SET_ATTRIBUTE, "0 * * * * *"));
@@ -77,7 +76,8 @@ void defaultConfigWithUniqueStoreImplementation() {
7776
.withClassLoader(new FilteredClassLoader(HazelcastIndexedSessionRepository.class,
7877
JdbcIndexedSessionRepository.class, MongoIndexedSessionRepository.class))
7978
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
80-
.withPropertyValues("spring.redis.port=" + redis.getFirstMappedPort())
79+
.withPropertyValues("spring.redis.host=" + redis.getContainerIpAddress(),
80+
"spring.redis.port=" + redis.getFirstMappedPort())
8181
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE,
8282
SaveMode.ON_SET_ATTRIBUTE, "0 * * * * *"));
8383
}
@@ -88,6 +88,7 @@ void redisSessionStoreWithCustomizations() {
8888
.withPropertyValues("spring.session.store-type=redis", "spring.session.redis.namespace=foo",
8989
"spring.session.redis.flush-mode=immediate", "spring.session.redis.save-mode=on-get-attribute",
9090
"spring.session.redis.cleanup-cron=0 0 12 * * *",
91+
"spring.redis.host=" + redis.getContainerIpAddress(),
9192
"spring.redis.port=" + redis.getFirstMappedPort())
9293
.run(validateSpringSessionUsesRedis("foo:event:0:created:", FlushMode.IMMEDIATE,
9394
SaveMode.ON_GET_ATTRIBUTE, "0 0 12 * * *"));
@@ -97,6 +98,7 @@ void redisSessionStoreWithCustomizations() {
9798
void redisSessionWithConfigureActionNone() {
9899
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
99100
.withPropertyValues("spring.session.store-type=redis", "spring.session.redis.configure-action=none",
101+
"spring.redis.host=" + redis.getContainerIpAddress(),
100102
"spring.redis.port=" + redis.getFirstMappedPort())
101103
.run(validateStrategy(ConfigureRedisAction.NO_OP.getClass()));
102104
}
@@ -105,6 +107,7 @@ void redisSessionWithConfigureActionNone() {
105107
void redisSessionWithDefaultConfigureActionNone() {
106108
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
107109
.withPropertyValues("spring.session.store-type=redis",
110+
"spring.redis.host=" + redis.getContainerIpAddress(),
108111
"spring.redis.port=" + redis.getFirstMappedPort())
109112
.run(validateStrategy(ConfigureNotifyKeyspaceEventsAction.class,
110113
entry("notify-keyspace-events", "gxE")));
@@ -115,6 +118,7 @@ void redisSessionWithCustomConfigureRedisActionBean() {
115118
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
116119
.withUserConfiguration(MaxEntriesRedisAction.class)
117120
.withPropertyValues("spring.session.store-type=redis",
121+
"spring.redis.host=" + redis.getContainerIpAddress(),
118122
"spring.redis.port=" + redis.getFirstMappedPort())
119123
.run(validateStrategy(MaxEntriesRedisAction.class, entry("set-max-intset-entries", "1024")));
120124

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestIntegrationTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class DataRedisTestIntegrationTests {
6060

6161
@DynamicPropertySource
6262
static void redisProperties(DynamicPropertyRegistry registry) {
63+
registry.add("spring.redis.host", redis::getContainerIpAddress);
6364
registry.add("spring.redis.port", redis::getFirstMappedPort);
6465
}
6566

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestPropertiesIntegrationTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class DataRedisTestPropertiesIntegrationTests {
4646

4747
@DynamicPropertySource
4848
static void redisProperties(DynamicPropertyRegistry registry) {
49+
registry.add("spring.redis.host", redis::getContainerIpAddress);
4950
registry.add("spring.redis.port", redis::getFirstMappedPort);
5051
}
5152

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestWithIncludeFilterIntegrationTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class DataRedisTestWithIncludeFilterIntegrationTests {
4949

5050
@DynamicPropertySource
5151
static void redisProperties(DynamicPropertyRegistry registry) {
52+
registry.add("spring.redis.host", redis::getContainerIpAddress);
5253
registry.add("spring.redis.port", redis::getFirstMappedPort);
5354
}
5455

0 commit comments

Comments
 (0)