Skip to content

Commit

Permalink
Merge branch '2.4.x' into 2.5.x
Browse files Browse the repository at this point in the history
Closes gh-27525
  • Loading branch information
wilkinsona committed Jul 29, 2021
2 parents 8505472 + ad2d9c0 commit 533bb24
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@

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.config.DriverConfigLoader;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.autoconfigure.AutoConfigurations;
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.Configuration;

Expand All @@ -46,8 +43,7 @@
class CassandraAutoConfigurationIntegrationTests {

@Container
static final CassandraContainer<?> cassandra = new CassandraContainer<>(DockerImageNames.cassandra())
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
static final CassandraContainer cassandra = new CassandraContainer();

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class)).withPropertyValues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.junit.jupiter.api.Test;
import org.rnorth.ducttape.TimeoutException;
import org.rnorth.ducttape.unreliables.Unreliables;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.containers.ContainerLaunchException;
import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;
import org.testcontainers.images.builder.Transferable;
Expand All @@ -37,7 +36,7 @@

import org.springframework.boot.autoconfigure.AutoConfigurations;
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 static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -52,7 +51,7 @@
class CassandraAutoConfigurationWithPasswordAuthenticationIntegrationTests {

@Container
static final CassandraContainer<?> cassandra = new PasswordAuthenticatorCassandraContainer().withStartupAttempts(5)
static final CassandraContainer cassandra = new PasswordAuthenticatorCassandraContainer().withStartupAttempts(5)
.withStartupTimeout(Duration.ofMinutes(10)).waitingFor(new CassandraWaitStrategy());

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
Expand Down Expand Up @@ -81,12 +80,7 @@ void authenticationWithInvalidCredentials() {
.hasMessageContaining("Authentication error"));
}

static final class PasswordAuthenticatorCassandraContainer
extends CassandraContainer<PasswordAuthenticatorCassandraContainer> {

PasswordAuthenticatorCassandraContainer() {
super(DockerImageNames.cassandra());
}
static final class PasswordAuthenticatorCassandraContainer extends CassandraContainer {

@Override
protected void containerIsCreated(String containerId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

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.CqlSessionBuilder;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

Expand All @@ -31,7 +28,7 @@
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
import org.springframework.boot.autoconfigure.data.cassandra.city.City;
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.Configuration;
import org.springframework.data.cassandra.config.SchemaAction;
Expand All @@ -49,8 +46,7 @@
class CassandraDataAutoConfigurationIntegrationTests {

@Container
static final CassandraContainer<?> cassandra = new CassandraContainer<>(DockerImageNames.cassandra())
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
static final CassandraContainer cassandra = new CassandraContainer();

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand All @@ -16,21 +16,19 @@

package org.springframework.boot.test.autoconfigure.data.cassandra;

import java.time.Duration;
import java.util.UUID;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.redis.ExampleService;
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.annotation.Bean;
import org.springframework.data.cassandra.core.CassandraTemplate;
Expand All @@ -53,8 +51,7 @@
class DataCassandraTestIntegrationTests {

@Container
static final CassandraContainer<?> cassandra = new CassandraContainer<>(DockerImageNames.cassandra())
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
static final CassandraContainer cassandra = new CassandraContainer();

@DynamicPropertySource
static void cassandraProperties(DynamicPropertyRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand All @@ -16,19 +16,17 @@

package org.springframework.boot.test.autoconfigure.data.cassandra;

import java.time.Duration;
import java.util.UUID;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import org.springframework.beans.factory.annotation.Autowired;
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.ComponentScan.Filter;
import org.springframework.stereotype.Service;
Expand All @@ -53,8 +51,7 @@
class DataCassandraTestWithIncludeFilterIntegrationTests {

@Container
static final CassandraContainer<?> cassandra = new CassandraContainer<>(DockerImageNames.cassandra())
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
static final CassandraContainer cassandra = new CassandraContainer();

@DynamicPropertySource
static void cassandraProperties(DynamicPropertyRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
compileOnly("org.mockito:mockito-core")
compileOnly("org.springframework:spring-context")
compileOnly("org.springframework.data:spring-data-redis")
compileOnly("org.testcontainers:cassandra")
compileOnly("org.testcontainers:testcontainers")

implementation("org.apache.maven.resolver:maven-resolver-connector-basic")
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}

}

0 comments on commit 533bb24

Please sign in to comment.