Merge branch '2.4.x' into 2.5.x

Closes gh-27525
pull/28375/head
Andy Wilkinson 3 years ago
commit 533bb24b55

@ -16,12 +16,9 @@
package org.springframework.boot.autoconfigure.cassandra; package org.springframework.boot.autoconfigure.cassandra;
import java.time.Duration;
import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader; import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Testcontainers;
@ -29,7 +26,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; import org.springframework.boot.testsupport.testcontainers.CassandraContainer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -46,8 +43,7 @@ import static org.mockito.Mockito.verify;
class CassandraAutoConfigurationIntegrationTests { class CassandraAutoConfigurationIntegrationTests {
@Container @Container
static final CassandraContainer<?> cassandra = new CassandraContainer<>(DockerImageNames.cassandra()) static final CassandraContainer cassandra = new CassandraContainer();
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class)).withPropertyValues( .withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class)).withPropertyValues(

@ -28,7 +28,6 @@ import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.rnorth.ducttape.TimeoutException; import org.rnorth.ducttape.TimeoutException;
import org.rnorth.ducttape.unreliables.Unreliables; import org.rnorth.ducttape.unreliables.Unreliables;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.containers.ContainerLaunchException; import org.testcontainers.containers.ContainerLaunchException;
import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy; import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;
import org.testcontainers.images.builder.Transferable; import org.testcontainers.images.builder.Transferable;
@ -37,7 +36,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; import org.springframework.boot.testsupport.testcontainers.CassandraContainer;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -52,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
class CassandraAutoConfigurationWithPasswordAuthenticationIntegrationTests { class CassandraAutoConfigurationWithPasswordAuthenticationIntegrationTests {
@Container @Container
static final CassandraContainer<?> cassandra = new PasswordAuthenticatorCassandraContainer().withStartupAttempts(5) static final CassandraContainer cassandra = new PasswordAuthenticatorCassandraContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10)).waitingFor(new CassandraWaitStrategy()); .withStartupTimeout(Duration.ofMinutes(10)).waitingFor(new CassandraWaitStrategy());
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
@ -81,12 +80,7 @@ class CassandraAutoConfigurationWithPasswordAuthenticationIntegrationTests {
.hasMessageContaining("Authentication error")); .hasMessageContaining("Authentication error"));
} }
static final class PasswordAuthenticatorCassandraContainer static final class PasswordAuthenticatorCassandraContainer extends CassandraContainer {
extends CassandraContainer<PasswordAuthenticatorCassandraContainer> {
PasswordAuthenticatorCassandraContainer() {
super(DockerImageNames.cassandra());
}
@Override @Override
protected void containerIsCreated(String containerId) { protected void containerIsCreated(String containerId) {

@ -16,12 +16,9 @@
package org.springframework.boot.autoconfigure.data.cassandra; package org.springframework.boot.autoconfigure.data.cassandra;
import java.time.Duration;
import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder; import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Testcontainers;
@ -31,7 +28,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
import org.springframework.boot.autoconfigure.data.cassandra.city.City; import org.springframework.boot.autoconfigure.data.cassandra.city.City;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; import org.springframework.boot.testsupport.testcontainers.CassandraContainer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.SchemaAction; import org.springframework.data.cassandra.config.SchemaAction;
@ -49,8 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class CassandraDataAutoConfigurationIntegrationTests { class CassandraDataAutoConfigurationIntegrationTests {
@Container @Container
static final CassandraContainer<?> cassandra = new CassandraContainer<>(DockerImageNames.cassandra()) static final CassandraContainer cassandra = new CassandraContainer();
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration( .withConfiguration(

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,13 +16,11 @@
package org.springframework.boot.test.autoconfigure.data.cassandra; package org.springframework.boot.test.autoconfigure.data.cassandra;
import java.time.Duration;
import java.util.UUID; import java.util.UUID;
import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder; import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Testcontainers;
@ -30,7 +28,7 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.redis.ExampleService; import org.springframework.boot.test.autoconfigure.data.redis.ExampleService;
import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; import org.springframework.boot.testsupport.testcontainers.CassandraContainer;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.data.cassandra.core.CassandraTemplate; import org.springframework.data.cassandra.core.CassandraTemplate;
@ -53,8 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
class DataCassandraTestIntegrationTests { class DataCassandraTestIntegrationTests {
@Container @Container
static final CassandraContainer<?> cassandra = new CassandraContainer<>(DockerImageNames.cassandra()) static final CassandraContainer cassandra = new CassandraContainer();
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
@DynamicPropertySource @DynamicPropertySource
static void cassandraProperties(DynamicPropertyRegistry registry) { static void cassandraProperties(DynamicPropertyRegistry registry) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,19 +16,17 @@
package org.springframework.boot.test.autoconfigure.data.cassandra; package org.springframework.boot.test.autoconfigure.data.cassandra;
import java.time.Duration;
import java.util.UUID; import java.util.UUID;
import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder; import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames; import org.springframework.boot.testsupport.testcontainers.CassandraContainer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -53,8 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class DataCassandraTestWithIncludeFilterIntegrationTests { class DataCassandraTestWithIncludeFilterIntegrationTests {
@Container @Container
static final CassandraContainer<?> cassandra = new CassandraContainer<>(DockerImageNames.cassandra()) static final CassandraContainer cassandra = new CassandraContainer();
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
@DynamicPropertySource @DynamicPropertySource
static void cassandraProperties(DynamicPropertyRegistry registry) { static void cassandraProperties(DynamicPropertyRegistry registry) {

@ -18,6 +18,7 @@ dependencies {
compileOnly("org.mockito:mockito-core") compileOnly("org.mockito:mockito-core")
compileOnly("org.springframework:spring-context") compileOnly("org.springframework:spring-context")
compileOnly("org.springframework.data:spring-data-redis") compileOnly("org.springframework.data:spring-data-redis")
compileOnly("org.testcontainers:cassandra")
compileOnly("org.testcontainers:testcontainers") compileOnly("org.testcontainers:testcontainers")
implementation("org.apache.maven.resolver:maven-resolver-connector-basic") implementation("org.apache.maven.resolver:maven-resolver-connector-basic")

@ -0,0 +1,39 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.testsupport.testcontainers;
import java.time.Duration;
/**
* Custom {@link org.testcontainers.containers.CassandraContainer} tuned to improve
* startup time.
*
* @author Andy Wilkinson
* @since 2.4.10
*/
public class CassandraContainer extends org.testcontainers.containers.CassandraContainer<CassandraContainer> {
public CassandraContainer() {
super(DockerImageNames.cassandra());
withEnv("CASSANDRA_SNITCH", "GossipingPropertyFileSnitch");
withEnv("JVM_OPTS", "-Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0");
withEnv("HEAP_NEWSIZE", "128M");
withEnv("MAX_HEAP_SIZE", "1024M");
withStartupTimeout(Duration.ofMinutes(10));
}
}
Loading…
Cancel
Save