Polish related to testcontainers

* Use getHost instead of getContainerIpAddress
* Rely on OracleContainer and it's improvements which involve the log
wait strategy
This commit is contained in:
Eddú Meléndez
2022-05-14 19:12:39 -05:00
committed by Marcus Hert Da Coregio
parent 7c927c7f38
commit 0dfc97289f
21 changed files with 45 additions and 78 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2016 the original author or authors. * Copyright 2014-2022 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.
@@ -399,8 +399,8 @@ public abstract class AbstractMongoRepositoryITest extends AbstractITest {
@Bean @Bean
public MongoOperations mongoOperations(MongoDBContainer mongoContainer) { public MongoOperations mongoOperations(MongoDBContainer mongoContainer) {
MongoClient mongo = MongoClients.create( MongoClient mongo = MongoClients
"mongodb://" + mongoContainer.getContainerIpAddress() + ":" + mongoContainer.getFirstMappedPort()); .create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort());
return new MongoTemplate(mongo, "test"); return new MongoTemplate(mongo, "test");
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019 the original author or authors. * Copyright 2014-2022 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.
@@ -185,8 +185,8 @@ public class MongoDbDeleteJacksonSessionVerificationTest {
@Bean @Bean
ReactiveMongoOperations mongoOperations(MongoDBContainer mongoContainer) { ReactiveMongoOperations mongoOperations(MongoDBContainer mongoContainer) {
MongoClient mongo = MongoClients.create( MongoClient mongo = MongoClients
"mongodb://" + mongoContainer.getContainerIpAddress() + ":" + mongoContainer.getFirstMappedPort()); .create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort());
return new ReactiveMongoTemplate(mongo, "DB_Name_DeleteJacksonSessionVerificationTest"); return new ReactiveMongoTemplate(mongo, "DB_Name_DeleteJacksonSessionVerificationTest");
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2019 the original author or authors. * Copyright 2014-2022 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.
@@ -180,8 +180,8 @@ public class MongoDbLogoutVerificationTest {
@Bean @Bean
ReactiveMongoOperations mongoOperations(MongoDBContainer mongoContainer) { ReactiveMongoOperations mongoOperations(MongoDBContainer mongoContainer) {
MongoClient mongo = MongoClients.create( MongoClient mongo = MongoClients
"mongodb://" + mongoContainer.getContainerIpAddress() + ":" + mongoContainer.getFirstMappedPort()); .create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort());
return new ReactiveMongoTemplate(mongo, "test"); return new ReactiveMongoTemplate(mongo, "test");
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -42,8 +42,8 @@ public abstract class AbstractRedisITests {
@Bean @Bean
public LettuceConnectionFactory redisConnectionFactory() { public LettuceConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration( RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(redisContainer().getHost(),
redisContainer().getContainerIpAddress(), redisContainer().getFirstMappedPort()); redisContainer().getFirstMappedPort());
return new LettuceConnectionFactory(configuration); return new LettuceConnectionFactory(configuration);
} }

View File

@@ -66,8 +66,7 @@ class ClientServerHazelcast4IndexedSessionRepositoryITests extends AbstractHazel
@Bean @Bean
HazelcastInstance hazelcastInstance() { HazelcastInstance hazelcastInstance() {
ClientConfig clientConfig = new ClientConfig(); ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig() clientConfig.getNetworkConfig().addAddress(container.getHost() + ":" + container.getFirstMappedPort());
.addAddress(container.getContainerIpAddress() + ":" + container.getFirstMappedPort());
clientConfig.getUserCodeDeploymentConfig().setEnabled(true).addClass(Session.class) clientConfig.getUserCodeDeploymentConfig().setEnabled(true).addClass(Session.class)
.addClass(MapSession.class).addClass(Hazelcast4SessionUpdateEntryProcessor.class); .addClass(MapSession.class).addClass(Hazelcast4SessionUpdateEntryProcessor.class);
return HazelcastClient.newHazelcastClient(clientConfig); return HazelcastClient.newHazelcastClient(clientConfig);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -67,8 +67,7 @@ class ClientServerHazelcastIndexedSessionRepositoryITests extends AbstractHazelc
@Bean @Bean
HazelcastInstance hazelcastInstance() { HazelcastInstance hazelcastInstance() {
ClientConfig clientConfig = new ClientConfig(); ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig() clientConfig.getNetworkConfig().addAddress(container.getHost() + ":" + container.getFirstMappedPort());
.addAddress(container.getContainerIpAddress() + ":" + container.getFirstMappedPort());
clientConfig.getUserCodeDeploymentConfig().setEnabled(true).addClass(Session.class) clientConfig.getUserCodeDeploymentConfig().setEnabled(true).addClass(Session.class)
.addClass(MapSession.class).addClass(SessionUpdateEntryProcessor.class); .addClass(MapSession.class).addClass(SessionUpdateEntryProcessor.class);
return HazelcastClient.newHazelcastClient(clientConfig); return HazelcastClient.newHazelcastClient(clientConfig);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2021 the original author or authors. * Copyright 2014-2022 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,8 +16,6 @@
package org.springframework.session.jdbc; package org.springframework.session.jdbc;
import java.time.Duration;
import org.testcontainers.containers.Db2Container; import org.testcontainers.containers.Db2Container;
import org.testcontainers.containers.JdbcDatabaseContainer; import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MSSQLServerContainer; import org.testcontainers.containers.MSSQLServerContainer;
@@ -25,7 +23,6 @@ import org.testcontainers.containers.MariaDBContainer;
import org.testcontainers.containers.MySQLContainer; import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.OracleContainer; import org.testcontainers.containers.OracleContainer;
import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
/** /**
* Factories for various {@link JdbcDatabaseContainer}s. * Factories for various {@link JdbcDatabaseContainer}s.
@@ -50,21 +47,7 @@ final class DatabaseContainers {
} }
static OracleContainer oracle() { static OracleContainer oracle() {
return new OracleContainer() { return new OracleContainer("gvenzl/oracle-xe:18.4.0-slim");
@Override
protected void configure() {
this.waitStrategy = new LogMessageWaitStrategy().withRegEx(".*DATABASE IS READY TO USE!.*\\s")
.withStartupTimeout(Duration.ofMinutes(10));
addEnv("ORACLE_PWD", getPassword());
}
@Override
protected void waitUntilContainerStarted() {
getWaitStrategy().waitUntilReady(this);
}
};
} }
static PostgreSQLContainer<?> postgreSql() { static PostgreSQLContainer<?> postgreSql() {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -115,8 +115,7 @@ class FindByUsernameTests {
@Bean @Bean
LettuceConnectionFactory redisConnectionFactory() { LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -115,8 +115,7 @@ class HttpRedisJsonTest {
@Bean @Bean
LettuceConnectionFactory redisConnectionFactory() { LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -64,8 +64,7 @@ class RedisSerializerTest {
@Bean @Bean
LettuceConnectionFactory redisConnectionFactory() { LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -93,8 +93,7 @@ class BootTests {
@Bean @Bean
LettuceConnectionFactory redisConnectionFactory() { LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -97,8 +97,7 @@ class BootTests {
@Bean @Bean
LettuceConnectionFactory redisConnectionFactory() { LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2020 the original author or authors. * Copyright 2014-2022 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.
@@ -103,8 +103,7 @@ class AttributeTests {
@Bean @Bean
LettuceConnectionFactory redisConnectionFactory() { LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -105,8 +105,7 @@ class AttributeTests {
@Bean @Bean
LettuceConnectionFactory redisConnectionFactory() { LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -86,8 +86,7 @@ class ApplicationTests {
@Bean @Bean
LettuceConnectionFactory redisConnectionFactory() { LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -40,8 +40,7 @@ public class EmbeddedRedisConfig {
@Bean @Bean
@Primary @Primary
public LettuceConnectionFactory redisConnectionFactory() { public LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -40,8 +40,7 @@ public class EmbeddedRedisConfig {
@Bean @Bean
@Primary @Primary
public LettuceConnectionFactory redisConnectionFactory() { public LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -99,8 +99,7 @@ class RestMockMvcTests {
@Bean @Bean
LettuceConnectionFactory redisConnectionFactory() { LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
@Bean @Bean

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -40,8 +40,7 @@ public class EmbeddedRedisConfig {
@Bean @Bean
@Primary @Primary
public LettuceConnectionFactory redisConnectionFactory() { public LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -40,8 +40,7 @@ public class EmbeddedRedisConfig {
@Bean @Bean
@Primary @Primary
public LettuceConnectionFactory redisConnectionFactory() { public LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014-2019 the original author or authors. * Copyright 2014-2022 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.
@@ -40,8 +40,7 @@ public class EmbeddedRedisConfig {
@Bean @Bean
@Primary @Primary
public LettuceConnectionFactory redisConnectionFactory() { public LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisContainer().getContainerIpAddress(), return new LettuceConnectionFactory(redisContainer().getHost(), redisContainer().getFirstMappedPort());
redisContainer().getFirstMappedPort());
} }
} }