import static com.google.common.base.Preconditions.checkState;
import static java.lang.String.format;
import static org.sonar.process.ProcessProperties.Property.JDBC_EMBEDDED_PORT;
+import static org.sonar.process.ProcessProperties.Property.JDBC_MAX_IDLE_TIMEOUT;
+import static org.sonar.process.ProcessProperties.Property.JDBC_MAX_KEEP_ALIVE_TIME;
+import static org.sonar.process.ProcessProperties.Property.JDBC_MAX_LIFETIME;
import static org.sonar.process.ProcessProperties.Property.JDBC_MIN_IDLE;
import static org.sonar.process.ProcessProperties.Property.JDBC_PASSWORD;
import static org.sonar.process.ProcessProperties.Property.JDBC_URL;
import static org.sonar.process.ProcessProperties.Property.JDBC_USERNAME;
+import static org.sonar.process.ProcessProperties.Property.JDBC_VALIDATION_TIMEOUT;
/**
* @since 2.12
SONAR_JDBC_MAX_WAIT,
SONAR_JDBC_MAX_ACTIVE,
// allowed hikari cp direct properties
+ // see: https://github.com/brettwooldridge/HikariCP#frequently-used
SONAR_JDBC_DRIVER,
"sonar.jdbc.dataSource.user",
"sonar.jdbc.dataSource.password",
"sonar.jdbc.jdbcUrl",
"sonar.jdbc.connectionTimeout",
"sonar.jdbc.maximumPoolSize",
- "sonar.jdbc.minimumIdle");
+ "sonar.jdbc.minimumIdle",
+ "sonar.jdbc.schema",
+ JDBC_VALIDATION_TIMEOUT.getKey(),
+ "sonar.jdbc.catalog",
+ "sonar.jdbc.initializationFailTimeout",
+ JDBC_MAX_LIFETIME.getKey(),
+ "sonar.jdbc.leakDetectionThreshold",
+ JDBC_MAX_KEEP_ALIVE_TIME.getKey(),
+ JDBC_MAX_IDLE_TIMEOUT.getKey()
+ );
private static final Map<String, String> SONAR_JDBC_TO_HIKARI_PROPERTY_MAPPINGS = Map.of(
JDBC_USERNAME.getKey(), "dataSource.user",
Properties props = new Properties();
props.setProperty("sonar.jdbc.driverClassName", "my.Driver");
props.setProperty("sonar.jdbc.username", "me");
- props.setProperty("sonar.jdbc.maximumPoolSize", "5");
- props.setProperty("sonar.jdbc.connectionTimeout", "5000");
+ props.setProperty("sonar.jdbc.dataSource.password", "my_password");
+ props.setProperty("sonar.jdbc.dataSource.portNumber", "9999");
+ props.setProperty("sonar.jdbc.connectionTimeout", "8000");
+ props.setProperty("sonar.jdbc.maximumPoolSize", "80");
+ props.setProperty("sonar.jdbc.minimumIdle", "10");
+ props.setProperty("sonar.jdbc.schema", "db-schema");
+ props.setProperty("sonar.jdbc.validationTimeout", "5000");
+ props.setProperty("sonar.jdbc.catalog", "db-catalog");
+ props.setProperty("sonar.jdbc.initializationFailTimeout", "5000");
+ props.setProperty("sonar.jdbc.maxLifetime", "1800000");
+ props.setProperty("sonar.jdbc.leakDetectionThreshold", "0");
+ props.setProperty("sonar.jdbc.keepaliveTime", "30000");
+ props.setProperty("sonar.jdbc.idleTimeout", "600000");
Properties hikariProps = DefaultDatabase.extractCommonsHikariProperties(props);
- assertThat(hikariProps.getProperty("dataSource.user")).isEqualTo("me");
+ assertThat(hikariProps).hasSize(15);
assertThat(hikariProps.getProperty("driverClassName")).isEqualTo("my.Driver");
- assertThat(hikariProps.getProperty("maximumPoolSize")).isEqualTo("5");
- assertThat(hikariProps.getProperty("connectionTimeout")).isEqualTo("5000");
+ assertThat(hikariProps.getProperty("dataSource.user")).isEqualTo("me");
+ assertThat(hikariProps.getProperty("dataSource.password")).isEqualTo("my_password");
+ assertThat(hikariProps.getProperty("dataSource.portNumber")).isEqualTo("9999");
+ assertThat(hikariProps.getProperty("connectionTimeout")).isEqualTo("8000");
+ assertThat(hikariProps.getProperty("maximumPoolSize")).isEqualTo("80");
+ assertThat(hikariProps.getProperty("minimumIdle")).isEqualTo("10");
+ assertThat(hikariProps.getProperty("schema")).isEqualTo("db-schema");
+ assertThat(hikariProps.getProperty("validationTimeout")).isEqualTo("5000");
+ assertThat(hikariProps.getProperty("catalog")).isEqualTo("db-catalog");
+ assertThat(hikariProps.getProperty("initializationFailTimeout")).isEqualTo("5000");
+ assertThat(hikariProps.getProperty("maxLifetime")).isEqualTo("1800000");
+ assertThat(hikariProps.getProperty("leakDetectionThreshold")).isEqualTo("0");
+ assertThat(hikariProps.getProperty("keepaliveTime")).isEqualTo("30000");
+ assertThat(hikariProps.getProperty("idleTimeout")).isEqualTo("600000");
+
}
@Test
}
@Test
- @UseDataProvider("sonarJdbcAndDbcpProperties")
+ @UseDataProvider("sonarJdbcAndHikariProperties")
public void shouldExtractCommonsDbcpPropertiesIfDuplicatedPropertiesWithSameValue(String jdbcProperty, String dbcpProperty) {
Properties props = new Properties();
props.setProperty(jdbcProperty, "100");
}
@Test
- @UseDataProvider("sonarJdbcAndDbcpProperties")
+ @UseDataProvider("sonarJdbcAndHikariProperties")
public void shouldThrowISEIfDuplicatedResolvedPropertiesWithDifferentValue(String jdbcProperty, String hikariProperty) {
Properties props = new Properties();
props.setProperty(jdbcProperty, "100");
}
@DataProvider
- public static Object[][] sonarJdbcAndDbcpProperties() {
+ public static Object[][] sonarJdbcAndHikariProperties() {
return new Object[][] {
{"sonar.jdbc.maxWait", "sonar.jdbc.connectionTimeout"},
{"sonar.jdbc.maxActive", "sonar.jdbc.maximumPoolSize"}
JDBC_MAX_ACTIVE("sonar.jdbc.maxActive", "60"),
JDBC_MIN_IDLE("sonar.jdbc.minIdle", "10"),
JDBC_MAX_WAIT("sonar.jdbc.maxWait", "8000"),
+ JDBC_MAX_IDLE_TIMEOUT("sonar.jdbc.idleTimeout", "600000"),
+ JDBC_MAX_KEEP_ALIVE_TIME("sonar.jdbc.keepaliveTime", "300000"),
+ JDBC_MAX_LIFETIME("sonar.jdbc.maxLifetime", "1800000"),
+ JDBC_VALIDATION_TIMEOUT("sonar.jdbc.validationTimeout", "5000"),
+
JDBC_EMBEDDED_PORT("sonar.embeddedDatabase.port"),
PATH_DATA("sonar.path.data", "data"),