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
This commit is contained in:
Stephane Nicoll 2020-05-25 14:39:43 +02:00
commit a657c97ce8
7 changed files with 18 additions and 9 deletions

View File

@ -74,7 +74,7 @@ class CouchbaseAutoConfigurationIntegrationTests {
void setUp() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(CouchbaseAutoConfiguration.class);
TestPropertyValues.of("spring.couchbase.bootstrap-hosts=localhost",
TestPropertyValues.of("spring.couchbase.bootstrap-hosts=" + couchbase.getContainerIpAddress(),
"spring.couchbase.env.bootstrap.http-direct-port:" + couchbase.getMappedPort(8091),
"spring.couchbase.username:spring", "spring.couchbase.password:password",
"spring.couchbase.bucket.name:default").applyTo(this.context.getEnvironment());

View File

@ -56,7 +56,8 @@ class CassandraDataAutoConfigurationIntegrationTests {
void setUp() {
this.context = new AnnotationConfigApplicationContext();
TestPropertyValues
.of("spring.data.cassandra.port=" + cassandra.getFirstMappedPort(),
.of("spring.data.cassandra.contact-points=" + cassandra.getContainerIpAddress(),
"spring.data.cassandra.port=" + cassandra.getFirstMappedPort(),
"spring.data.cassandra.read-timeout=24000", "spring.data.cassandra.connect-timeout=10000")
.applyTo(this.context.getEnvironment());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -54,7 +54,8 @@ class RedisRepositoriesAutoConfigurationTests {
@BeforeEach
void setUp() {
TestPropertyValues.of("spring.redis.port=" + redis.getFirstMappedPort()).applyTo(this.context.getEnvironment());
TestPropertyValues.of("spring.redis.host=" + redis.getContainerIpAddress(),
"spring.redis.port=" + redis.getFirstMappedPort()).applyTo(this.context.getEnvironment());
}
@AfterEach

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@ -63,9 +63,8 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
@Test
void defaultConfig() {
this.contextRunner
.withPropertyValues("spring.session.store-type=redis",
"spring.redis.port=" + redis.getFirstMappedPort())
this.contextRunner.withPropertyValues("spring.session.store-type=redis",
"spring.redis.host=" + redis.getContainerIpAddress(), "spring.redis.port=" + redis.getFirstMappedPort())
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE,
SaveMode.ON_SET_ATTRIBUTE, "0 * * * * *"));
@ -77,7 +76,8 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
.withClassLoader(new FilteredClassLoader(HazelcastIndexedSessionRepository.class,
JdbcIndexedSessionRepository.class, MongoIndexedSessionRepository.class))
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
.withPropertyValues("spring.redis.port=" + redis.getFirstMappedPort())
.withPropertyValues("spring.redis.host=" + redis.getContainerIpAddress(),
"spring.redis.port=" + redis.getFirstMappedPort())
.run(validateSpringSessionUsesRedis("spring:session:event:0:created:", FlushMode.ON_SAVE,
SaveMode.ON_SET_ATTRIBUTE, "0 * * * * *"));
}
@ -88,6 +88,7 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
.withPropertyValues("spring.session.store-type=redis", "spring.session.redis.namespace=foo",
"spring.session.redis.flush-mode=immediate", "spring.session.redis.save-mode=on-get-attribute",
"spring.session.redis.cleanup-cron=0 0 12 * * *",
"spring.redis.host=" + redis.getContainerIpAddress(),
"spring.redis.port=" + redis.getFirstMappedPort())
.run(validateSpringSessionUsesRedis("foo:event:0:created:", FlushMode.IMMEDIATE,
SaveMode.ON_GET_ATTRIBUTE, "0 0 12 * * *"));
@ -97,6 +98,7 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
void redisSessionWithConfigureActionNone() {
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
.withPropertyValues("spring.session.store-type=redis", "spring.session.redis.configure-action=none",
"spring.redis.host=" + redis.getContainerIpAddress(),
"spring.redis.port=" + redis.getFirstMappedPort())
.run(validateStrategy(ConfigureRedisAction.NO_OP.getClass()));
}
@ -105,6 +107,7 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
void redisSessionWithDefaultConfigureActionNone() {
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
.withPropertyValues("spring.session.store-type=redis",
"spring.redis.host=" + redis.getContainerIpAddress(),
"spring.redis.port=" + redis.getFirstMappedPort())
.run(validateStrategy(ConfigureNotifyKeyspaceEventsAction.class,
entry("notify-keyspace-events", "gxE")));
@ -115,6 +118,7 @@ class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfiguratio
this.contextRunner.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class))
.withUserConfiguration(MaxEntriesRedisAction.class)
.withPropertyValues("spring.session.store-type=redis",
"spring.redis.host=" + redis.getContainerIpAddress(),
"spring.redis.port=" + redis.getFirstMappedPort())
.run(validateStrategy(MaxEntriesRedisAction.class, entry("set-max-intset-entries", "1024")));

View File

@ -60,6 +60,7 @@ class DataRedisTestIntegrationTests {
@DynamicPropertySource
static void redisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.host", redis::getContainerIpAddress);
registry.add("spring.redis.port", redis::getFirstMappedPort);
}

View File

@ -46,6 +46,7 @@ class DataRedisTestPropertiesIntegrationTests {
@DynamicPropertySource
static void redisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.host", redis::getContainerIpAddress);
registry.add("spring.redis.port", redis::getFirstMappedPort);
}

View File

@ -49,6 +49,7 @@ class DataRedisTestWithIncludeFilterIntegrationTests {
@DynamicPropertySource
static void redisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.host", redis::getContainerIpAddress);
registry.add("spring.redis.port", redis::getFirstMappedPort);
}