From d943f470c8c2fec84580cb790ad4629a24c8a673 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Fri, 19 Jul 2024 16:05:34 +0300 Subject: [PATCH] [0.12.0-SNAPSHOT] ClickHouse module in progress --- .../extensions/jdbc/ClickhouseContext.java | 3 ++- .../ClickhouseLiquibaseJdbcMigrationEngine.java | 13 ++++++------- .../extensions/jdbc/JdbcConnectionImpl.java | 13 ++++++++++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/clickhouse/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/ClickhouseContext.java b/clickhouse/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/ClickhouseContext.java index b5912ad..c717cde 100644 --- a/clickhouse/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/ClickhouseContext.java +++ b/clickhouse/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/ClickhouseContext.java @@ -81,7 +81,8 @@ private static Optional getConnectionExternal() { var db = Optional.ofNullable(System.getenv(EXTERNAL_TEST_CLICKHOUSE_DATABASE)).orElse("default"); if (url != null) { if (host != null && port != null) { - return Optional.of(ClickhouseConnectionImpl.forJDBC(url, host, Integer.parseInt(port), null, null, db, user, password)); + return Optional + .of(ClickhouseConnectionImpl.forJDBC(url, host, Integer.parseInt(port), null, null, db, user, password)); } else { return Optional.of(ClickhouseConnectionImpl.forExternal(url, user, password)); } diff --git a/clickhouse/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/ClickhouseLiquibaseJdbcMigrationEngine.java b/clickhouse/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/ClickhouseLiquibaseJdbcMigrationEngine.java index 71fc5da..602a456 100644 --- a/clickhouse/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/ClickhouseLiquibaseJdbcMigrationEngine.java +++ b/clickhouse/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/ClickhouseLiquibaseJdbcMigrationEngine.java @@ -1,5 +1,11 @@ package io.goodforgod.testcontainers.extensions.jdbc; +import java.io.FileWriter; +import java.io.Writer; +import java.nio.file.Files; +import java.sql.Connection; +import java.util.List; +import java.util.Optional; import liquibase.Contexts; import liquibase.LabelExpression; import liquibase.Liquibase; @@ -13,13 +19,6 @@ import org.slf4j.LoggerFactory; import org.slf4j.bridge.SLF4JBridgeHandler; -import java.io.FileWriter; -import java.io.Writer; -import java.nio.file.Files; -import java.sql.Connection; -import java.util.List; -import java.util.Optional; - public final class ClickhouseLiquibaseJdbcMigrationEngine implements JdbcMigrationEngine, AutoCloseable { private static final Logger logger = LoggerFactory.getLogger(ClickhouseLiquibaseJdbcMigrationEngine.class); diff --git a/jdbc/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/JdbcConnectionImpl.java b/jdbc/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/JdbcConnectionImpl.java index 9eaadc9..bf65af3 100644 --- a/jdbc/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/JdbcConnectionImpl.java +++ b/jdbc/src/main/java/io/goodforgod/testcontainers/extensions/jdbc/JdbcConnectionImpl.java @@ -423,12 +423,23 @@ protected HikariDataSource createDataSource() { hikariConfig.setMaximumPoolSize(25); hikariConfig.setPoolName("jdbc-connection"); hikariConfig.setLeakDetectionThreshold(10000); + hikariConfig.setConnectionTimeout(10000); + hikariConfig.setInitializationFailTimeout(10000); return new HikariDataSource(hikariConfig); } final HikariDataSource dataSource() { if (dataSource == null) { - this.dataSource = createDataSource(); + try { + this.dataSource = createDataSource(); + } catch (Exception e) { + try { + Thread.sleep(1000); + this.dataSource = createDataSource(); + } catch (InterruptedException ex) { + throw new RuntimeException(ex); + } + } } return this.dataSource;