From 20b6656ba7451558180b3f016d8ad1ac52b02fc1 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 2 Sep 2019 12:19:09 +0100 Subject: [PATCH] Protect autoconfigure module against slow starting test containers --- .../CassandraDataAutoConfigurationIntegrationTests.java | 5 ++++- .../elasticsearch/ElasticsearchAutoConfigurationTests.java | 4 +++- .../ElasticsearchDataAutoConfigurationTests.java | 5 ++++- .../ElasticsearchRepositoriesAutoConfigurationTests.java | 5 ++++- ...ctiveElasticsearchRepositoriesAutoConfigurationTests.java | 5 ++++- .../ReactiveRestClientAutoConfigurationTests.java | 4 +++- .../data/redis/RedisRepositoriesAutoConfigurationTests.java | 5 ++++- .../elasticsearch/jest/JestAutoConfigurationTests.java | 4 +++- .../elasticsearch/rest/RestClientAutoConfigurationTests.java | 3 ++- .../session/SessionAutoConfigurationRedisTests.java | 4 +++- 10 files changed, 34 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java index 3b62c3c070..f1e37e5e96 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationIntegrationTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.data.cassandra; +import java.time.Duration; + import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Session; import org.junit.jupiter.api.AfterEach; @@ -45,7 +47,8 @@ import static org.assertj.core.api.Assertions.assertThat; class CassandraDataAutoConfigurationIntegrationTests { @Container - static final CassandraContainer cassandra = new CassandraContainer<>(); + static final CassandraContainer cassandra = new CassandraContainer<>().withStartupAttempts(5) + .withStartupTimeout(Duration.ofMinutes(2)); private AnnotationConfigApplicationContext context; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java index 9ba688496d..7b3f1a9306 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java @@ -15,6 +15,7 @@ */ package org.springframework.boot.autoconfigure.data.elasticsearch; +import java.time.Duration; import java.util.List; import org.elasticsearch.client.Client; @@ -46,7 +47,8 @@ import static org.mockito.Mockito.mock; class ElasticsearchAutoConfigurationTests { @Container - public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer(); + public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) + .withStartupTimeout(Duration.ofMinutes(2)); private AnnotationConfigApplicationContext context; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java index bcdf84dfc6..4bf315d6d9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.data.elasticsearch; +import java.time.Duration; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -51,7 +53,8 @@ import static org.mockito.Mockito.mock; class ElasticsearchDataAutoConfigurationTests { @Container - static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer(); + static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) + .withStartupTimeout(Duration.ofMinutes(2)); private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration( AutoConfigurations.of(ElasticsearchAutoConfiguration.class, RestClientAutoConfiguration.class, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java index 244800766c..2b791eee47 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.data.elasticsearch; +import java.time.Duration; + import org.junit.jupiter.api.Test; import org.testcontainers.elasticsearch.ElasticsearchContainer; import org.testcontainers.junit.jupiter.Container; @@ -46,7 +48,8 @@ import static org.assertj.core.api.Assertions.assertThat; class ElasticsearchRepositoriesAutoConfigurationTests { @Container - static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer(); + static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) + .withStartupTimeout(Duration.ofMinutes(2)); private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration( diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticsearchRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticsearchRepositoriesAutoConfigurationTests.java index b15d2d8aab..26dbfaa617 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticsearchRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticsearchRepositoriesAutoConfigurationTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.data.elasticsearch; +import java.time.Duration; + import org.junit.jupiter.api.Test; import org.testcontainers.elasticsearch.ElasticsearchContainer; import org.testcontainers.junit.jupiter.Container; @@ -45,7 +47,8 @@ import static org.assertj.core.api.Assertions.assertThat; public class ReactiveElasticsearchRepositoriesAutoConfigurationTests { @Container - static ElasticsearchContainer elasticsearch = new ElasticsearchContainer(); + static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) + .withStartupTimeout(Duration.ofMinutes(2)); private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(ReactiveRestClientAutoConfiguration.class, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfigurationTests.java index 82d489a22a..754423fbd7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfigurationTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.data.elasticsearch; +import java.time.Duration; import java.util.HashMap; import java.util.Map; @@ -46,7 +47,8 @@ import static org.mockito.Mockito.mock; public class ReactiveRestClientAutoConfigurationTests { @Container - static ElasticsearchContainer elasticsearch = new ElasticsearchContainer(); + static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) + .withStartupTimeout(Duration.ofMinutes(2)); private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(ReactiveRestClientAutoConfiguration.class)); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java index 566792170e..8403fe3936 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisRepositoriesAutoConfigurationTests.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.data.redis; +import java.time.Duration; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -45,7 +47,8 @@ import static org.assertj.core.api.Assertions.assertThat; class RedisRepositoriesAutoConfigurationTests { @Container - public static RedisContainer redis = new RedisContainer(); + public static RedisContainer redis = new RedisContainer().withStartupAttempts(5) + .withStartupTimeout(Duration.ofMinutes(2)); private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfigurationTests.java index 7eaa365218..c94e6c8010 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfigurationTests.java @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.elasticsearch.jest; import java.io.IOException; +import java.time.Duration; import java.util.HashMap; import java.util.Map; @@ -54,7 +55,8 @@ import static org.mockito.Mockito.mock; class JestAutoConfigurationTests { @Container - static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer(); + static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) + .withStartupTimeout(Duration.ofMinutes(2)); private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(GsonAutoConfiguration.class, JestAutoConfiguration.class)); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java index 8e75a97094..a19144656e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfigurationTests.java @@ -50,7 +50,8 @@ import static org.mockito.Mockito.mock; class RestClientAutoConfigurationTests { @Container - static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer(); + static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5) + .withStartupTimeout(Duration.ofMinutes(2)); private ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class)); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java index 161e1365b1..2e50a246e8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationRedisTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.session; +import java.time.Duration; import java.util.Map; import org.junit.jupiter.api.Test; @@ -54,7 +55,8 @@ import static org.assertj.core.api.Assertions.entry; class SessionAutoConfigurationRedisTests extends AbstractSessionAutoConfigurationTests { @Container - public static RedisContainer redis = new RedisContainer(); + public static RedisContainer redis = new RedisContainer().withStartupAttempts(5) + .withStartupTimeout(Duration.ofMinutes(2)); protected final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() .withConfiguration(AutoConfigurations.of(SessionAutoConfiguration.class));