2023-03-04 12:19:01 +00:00
|
|
|
package nu.marginalia.loader;
|
2022-05-19 15:45:26 +00:00
|
|
|
|
|
|
|
import com.zaxxer.hikari.HikariConfig;
|
|
|
|
import com.zaxxer.hikari.HikariDataSource;
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2023-03-04 12:19:01 +00:00
|
|
|
public class DbTestUtil {
|
2022-05-19 15:45:26 +00:00
|
|
|
private static final int TEST_PORT_BASE = 6000;
|
|
|
|
private static final int TEST_PORT_RANGE = 2000;
|
|
|
|
|
2023-03-04 12:19:01 +00:00
|
|
|
private final static Logger logger = LoggerFactory.getLogger(DbTestUtil.class);
|
2023-01-08 10:11:44 +00:00
|
|
|
|
2022-05-19 15:45:26 +00:00
|
|
|
public static int getPort() {
|
|
|
|
return TEST_PORT_BASE + (int)(TEST_PORT_RANGE * Math.random());
|
|
|
|
}
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
|
|
public static HikariDataSource getConnection() {
|
2022-05-25 16:02:19 +00:00
|
|
|
return getConnection("jdbc:mysql://localhost:3306/WMSA_test");
|
|
|
|
}
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
|
|
public static HikariDataSource getConnection(String connString) {
|
2022-05-19 15:45:26 +00:00
|
|
|
HikariConfig config = new HikariConfig();
|
2022-05-25 16:02:19 +00:00
|
|
|
config.setJdbcUrl(connString);
|
2022-05-19 15:45:26 +00:00
|
|
|
config.setUsername("wmsa");
|
|
|
|
config.setPassword("wmsa");
|
|
|
|
config.setMaximumPoolSize(16);
|
|
|
|
config.addDataSourceProperty("cachePrepStmts", "true");
|
|
|
|
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
|
|
|
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
|
|
|
|
|
|
|
return new HikariDataSource(config);
|
|
|
|
}
|
2022-05-25 16:02:19 +00:00
|
|
|
|
2022-05-19 15:45:26 +00:00
|
|
|
}
|