Merge remote-tracking branch 'origin/main' into claude/r9-tx-timeouts
pr / done (pull_request) Canceled after 0s

This commit is contained in:
DongHyeonka
2026-11-13 03:23:02 +09:00
18 changed files with 310 additions and 75 deletions
@@ -5,7 +5,10 @@ import com.zaxxer.hikari.HikariDataSource;
import dev.caskeleton.adapter.outbound.persistence.testkit.postgresql.PostgreSqlContainerFactory;
import dev.caskeleton.adapter.outbound.persistence.testkit.postgresql.PostgreSqlVersion;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.EnumMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -17,9 +20,16 @@ import org.testcontainers.postgresql.PostgreSQLContainer;
/**
* Starts one PostgreSQL per selected Stable version and hands out data sources (design §40).
*
* <p>The containers are shared for the JVM: the contracts verify server behaviour, which does not
* <p>The servers are shared for the JVM: the contracts verify server behaviour, which does not
* change between test classes, and starting a server per class turns a three-version matrix into
* minutes of container startup.
* minutes of container startup. Each support gets a database of its own on that server, created by
* {@code start} and dropped by {@code close}, so tables, schemas and Flyway history do not cross
* classes. What the server holds for every database — roles — does: a contract that creates a role
* owns that name for the whole lane.
*
* <p>Until 2026-11-12 every {@code start} started a server of its own although this comment said
* they were shared: 75 servers in the platform contract lane and 36 in the migration lane, 181 and
* 71 seconds of container start (desktop, 2026-11-12), on the build's one real-server slot.
*
* <p>Docker absence throws rather than skipping. A skipped contract reports success for a database
* nobody tested, and CI inherits that silence.
@@ -30,8 +40,16 @@ public final class JpaPlatformContractSupport implements AutoCloseable {
private static final java.security.SecureRandom PASSWORD_SOURCE =
new java.security.SecureRandom();
/** One server per Stable version, started on first use and stopped when the JVM exits. */
private static final Map<PostgreSqlVersion, PostgreSQLContainer> SERVERS =
new EnumMap<>(PostgreSqlVersion.class);
/** Names each support's database; the server outlives every support, so names never repeat. */
private static final AtomicInteger DATABASES = new AtomicInteger();
private final PostgreSqlVersion version;
private final PostgreSQLContainer container;
private final String database;
/**
* The pools this support owns, closed before the container stops.
@@ -48,9 +66,11 @@ public final class JpaPlatformContractSupport implements AutoCloseable {
private final AtomicInteger poolSequence = new AtomicInteger();
private JpaPlatformContractSupport(PostgreSqlVersion version, PostgreSQLContainer container) {
private JpaPlatformContractSupport(
PostgreSqlVersion version, PostgreSQLContainer container, String database) {
this.version = version;
this.container = container;
this.database = database;
}
/**
@@ -85,12 +105,47 @@ public final class JpaPlatformContractSupport implements AutoCloseable {
return start(selected.get(0));
}
/** Starts one specific Stable version. */
/** A fresh database on the shared server of one specific Stable version. */
public static JpaPlatformContractSupport start(PostgreSqlVersion version) {
Objects.requireNonNull(version, "version");
PostgreSQLContainer container = PostgreSqlContainerFactory.create(version);
container.start();
return new JpaPlatformContractSupport(version, container);
PostgreSQLContainer server = server(version);
String database = "contract_" + DATABASES.incrementAndGet();
administer(server, "create database " + database);
return new JpaPlatformContractSupport(version, server, database);
}
private static synchronized PostgreSQLContainer server(PostgreSqlVersion version) {
PostgreSQLContainer server = SERVERS.get(version);
if (server == null) {
if (SERVERS.isEmpty()) {
// Testcontainers' reaper would remove the containers too, but it is the part a remote
// Docker host cannot always reach; stopping them here does not depend on it.
Runtime.getRuntime()
.addShutdownHook(
new Thread(JpaPlatformContractSupport::stopServers, "jpa-contract-servers"));
}
server = PostgreSqlContainerFactory.create(version);
server.start();
SERVERS.put(version, server);
}
return server;
}
private static synchronized void stopServers() {
SERVERS.values().forEach(PostgreSQLContainer::stop);
SERVERS.clear();
}
/** Runs one statement as the server's owning role, connected to the server's own database. */
private static void administer(PostgreSQLContainer server, String sql) {
try (Connection connection =
DriverManager.getConnection(
server.getJdbcUrl(), server.getUsername(), server.getPassword());
Statement statement = connection.createStatement()) {
statement.execute(sql);
} catch (SQLException failure) {
throw new IllegalStateException("PostgreSQL contract server refused: " + sql, failure);
}
}
/** The versions this run was asked to cover. */
@@ -132,7 +187,7 @@ public final class JpaPlatformContractSupport implements AutoCloseable {
private HikariDataSource pool(String role, String username, String password, int maximumSize) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(container.getJdbcUrl());
config.setJdbcUrl(jdbcUrl());
config.setUsername(username);
config.setPassword(password);
config.setMaximumPoolSize(maximumSize);
@@ -148,9 +203,14 @@ public final class JpaPlatformContractSupport implements AutoCloseable {
return dataSource().getConnection();
}
/** The running server's JDBC URL, for contracts that build their own pools. */
/** This support's database on the running server, for contracts that build their own pools. */
public String jdbcUrl() {
return container.getJdbcUrl();
return "jdbc:postgresql://"
+ container.getHost()
+ ":"
+ container.getMappedPort(PostgreSQLContainer.POSTGRESQL_PORT)
+ "/"
+ database;
}
/** The container's owning role. */
@@ -192,9 +252,10 @@ public final class JpaPlatformContractSupport implements AutoCloseable {
@Override
public synchronized void close() {
// Pools first, container last. Stopping the server while a pool is still open leaves that
// pool retrying against an address nobody is listening on, and its housekeeping thread outlives
// the test that created it.
// Pools first, database last. Dropping the database under an open pool leaves that pool
// retrying against a database that is gone, and its housekeeping thread outlives the test that
// created it. `with (force)` ends a connection a contract opened outside the pools. The server
// stays for the next class.
RuntimeException firstFailure = null;
for (HikariDataSource pool : pools.values()) {
try {
@@ -208,7 +269,15 @@ public final class JpaPlatformContractSupport implements AutoCloseable {
}
}
pools.clear();
container.stop();
try {
administer(container, "drop database if exists " + database + " with (force)");
} catch (RuntimeException failure) {
if (firstFailure == null) {
firstFailure = failure;
} else {
firstFailure.addSuppressed(failure);
}
}
if (firstFailure != null) {
throw firstFailure;
}
@@ -4,6 +4,10 @@ import static org.assertj.core.api.Assertions.assertThat;
import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.sql.DataSource;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
@@ -66,8 +70,7 @@ class JpaPlatformContractSupportOwnershipTest {
}
@Test
@DisplayName("close shuts every pool before the container stops")
void closeShutsEveryPoolBeforeTheContainerStops() {
void closeShutsEveryPoolBeforeItsDatabaseIsDropped() {
HikariDataSource owned;
try (JpaPlatformContractSupport support = JpaPlatformContractSupport.start()) {
owned = (HikariDataSource) support.dataSource();
@@ -75,10 +78,65 @@ class JpaPlatformContractSupportOwnershipTest {
}
assertThat(owned.isClosed())
.as("stopping the container first leaves a live pool retrying against nothing")
.as("dropping the database first leaves a live pool retrying against nothing")
.isTrue();
}
@Test
void aSecondSupportSharesTheServerButNotTheDatabase() {
// given
String first;
try (JpaPlatformContractSupport support = JpaPlatformContractSupport.start()) {
first = support.jdbcUrl();
}
// when
String second;
try (JpaPlatformContractSupport support = JpaPlatformContractSupport.start()) {
second = support.jdbcUrl();
}
// then
assertThat(List.of(serverOf(second), databaseOf(second).equals(databaseOf(first))))
.as("one server per version for the JVM, a database of its own per support")
.containsExactly(serverOf(first), false);
}
@Test
void closeDropsTheSupportsDatabase() throws SQLException {
// given
String closed;
try (JpaPlatformContractSupport support = JpaPlatformContractSupport.start()) {
closed = databaseOf(support.jdbcUrl());
}
// when
Boolean exists;
try (JpaPlatformContractSupport support = JpaPlatformContractSupport.start();
Connection connection = support.connection();
PreparedStatement statement =
connection.prepareStatement(
"select exists(select 1 from pg_database where datname = ?)")) {
statement.setString(1, closed);
try (ResultSet row = statement.executeQuery()) {
exists = row.next() ? row.getBoolean(1) : null;
}
}
// then
assertThat(exists)
.as("a database left behind is one class's tables in the next class's server")
.isFalse();
}
private static String serverOf(String jdbcUrl) {
return jdbcUrl.substring(0, jdbcUrl.lastIndexOf('/'));
}
private static String databaseOf(String jdbcUrl) {
return jdbcUrl.substring(jdbcUrl.lastIndexOf('/') + 1);
}
@Test
@DisplayName("pools carry an identifiable name")
void poolsCarryAnIdentifiableName() {
@@ -6,7 +6,7 @@
넷 모두 Redis 7.4에서 돌았고 증거는 `docs/redis/support-matrix.md`에 적혀 있다.
`.gitea/workflows/main.yml`의 nightly `redis-topology` job이 매일 밤(그리고 손으로 실행할 때) 지원 버전 × topology 표
전체를 행마다 `scripts/ci/redis-topology.sh <topology> <version>`으로 돌린다. 같은 줄을 Docker가 있는 머신에서
전체를 job 하나 안에서 행마다 step 하나(`scripts/ci/redis-topology.sh <topology> <version>`)로 돌린다. 같은 줄을 Docker가 있는 머신에서
손으로 돌릴 수 있다. pull request마다 돌던 standalone lane은 2026-11-08에 nightly로 옮겼다(어댑터 컨테이너 lane은
main 단계, 소유자 결정 2026-11-07).
@@ -91,9 +91,9 @@ leaf마다 자기 시험이 검증하는 lane을 가지고, lane마다 돌아야
| lane | `redis-runtime` | `redis-sdk` | `cache-redis` |
| --- | --- | --- | --- |
| standalone | `LiveRedisCompositionTest` | `RedisTopologyContractTest`, `LiveRedisGuardrailTest` | `LiveRedisSemanticPortsTest`, `LiveRedisSemanticScriptAclProbeTest` |
| standalone | `LiveRedisCompositionTest` | `RedisTopologyContractTest`, `LiveRedisGuardrailTest` | `LiveRedisSemanticPortsTest`, `LiveRedisSemanticScriptAclProbeTest`, `LiveRedisDistributedLeaseContractTest`, `LiveRedisCacheRegionContractTest`, `LiveRedisIdempotencyStoreContractTest` |
| sentinel | `LiveRedisCompositionTest` | `RedisTopologyContractTest`, `LiveRedisSentinelPromotionTest` | — |
| cluster | `LiveRedisCompositionTest` | `LiveRedisClusterTest`, `LiveRedisClusterTransactionTest` | `LiveRedisSemanticPortsTest`, `LiveRedisSemanticScriptAclProbeTest` |
| cluster | `LiveRedisCompositionTest` | `LiveRedisClusterTest`, `LiveRedisClusterTransactionTest` | `LiveRedisSemanticPortsTest`, `LiveRedisSemanticScriptAclProbeTest`, `LiveRedisDistributedLeaseContractTest`, `LiveRedisCacheRegionContractTest`, `LiveRedisIdempotencyStoreContractTest` |
| tls | `LiveRedisTlsTest` | — | — |
lane은 `docker compose -f src/adapter/outbound/redis-sdk/compose/<lane>/compose.yml down -v`로 내린다.
@@ -181,7 +181,7 @@ class DeveloperExperienceContractTest {
"README.md",
"docs/build.md",
"src/**/README.md",
"src/**/CLAUDE.md",
"src/**/AGENTS.md",
"docs/**/*.md",
".github/**/*.md");
}