diff options
5 files changed, 61 insertions, 77 deletions
diff --git a/server/sonar-db-core/build.gradle b/server/sonar-db-core/build.gradle index 58f26e01f0d..c5de4301b8e 100644 --- a/server/sonar-db-core/build.gradle +++ b/server/sonar-db-core/build.gradle @@ -52,6 +52,7 @@ dependencies { } test { + useJUnitPlatform() if (System.hasProperty('orchestrator.configUrl')) systemProperty 'orchestrator.configUrl', System.getProperty('orchestrator.configUrl') } diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java index 8f38e7e1f6d..ac08e6abf4f 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java @@ -29,7 +29,7 @@ import org.sonar.api.utils.Version; public class Oracle extends AbstractDialect { public static final String ID = "oracle"; private static final List<String> INIT_STATEMENTS = List.of("ALTER SESSION SET NLS_SORT='BINARY'"); - private static final Version MIN_SUPPORTED_VERSION = Version.create(11, 0, 0); + private static final Version MIN_SUPPORTED_VERSION = Version.create(19, 0, 0); public Oracle() { super(ID, "oracle.jdbc.OracleDriver", "1", "0", "SELECT 1 FROM DUAL"); diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java index 1d5568abc0b..f05bd3b7cca 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java @@ -23,7 +23,6 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.List; import org.apache.commons.lang3.StringUtils; -import org.slf4j.LoggerFactory; import org.sonar.api.utils.Version; import static com.google.common.base.Preconditions.checkState; @@ -31,12 +30,10 @@ import static com.google.common.base.Preconditions.checkState; public class PostgreSql extends AbstractDialect { public static final String ID = "postgresql"; static final List<String> INIT_STATEMENTS = List.of("SET standard_conforming_strings=on", "SET backslash_quote=off"); - private static final Version MIN_SUPPORTED_VERSION = Version.create(9, 3, 0); - private static final Version MIN_UPSERT_VERSION = Version.create(9, 5, 0); + private static final Version MIN_SUPPORTED_VERSION = Version.create(11, 0, 0); private static final Version MIN_NULL_NOT_DISTINCT_VERSION = Version.create(15, 0, 0); private boolean initialized = false; - private boolean supportsUpsert = false; private boolean supportsNullNotDistinct = false; public PostgreSql() { @@ -60,8 +57,7 @@ public class PostgreSql extends AbstractDialect { @Override public boolean supportsUpsert() { - checkState(initialized, "onInit() must be called before calling supportsUpsert()"); - return supportsUpsert; + return true; } @Override @@ -76,11 +72,7 @@ public class PostgreSql extends AbstractDialect { Version version = checkDbVersion(metaData, MIN_SUPPORTED_VERSION); - supportsUpsert = version.compareTo(MIN_UPSERT_VERSION) >= 0; supportsNullNotDistinct = version.compareTo(MIN_NULL_NOT_DISTINCT_VERSION) >= 0; - if (!supportsUpsert) { - LoggerFactory.getLogger(getClass()).warn("Upgrading PostgreSQL to {} or greater is recommended for better performances", MIN_UPSERT_VERSION); - } initialized = true; } diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/OracleTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/OracleTest.java index 90ee6a44763..31b138ba298 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/OracleTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/OracleTest.java @@ -21,7 +21,7 @@ package org.sonar.db.dialect; import java.sql.DatabaseMetaData; import java.sql.SQLException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.sonar.api.utils.MessageException; @@ -32,96 +32,92 @@ import static org.mockito.Mockito.when; public class OracleTest { - private Oracle underTest = new Oracle(); + private final Oracle underTest = new Oracle(); @Test - public void matchesJdbcURL() { + void matchesJdbcURL() { assertThat(underTest.matchesJdbcUrl("jdbc:oracle:thin:@localhost/XE")).isTrue(); assertThat(underTest.matchesJdbcUrl("jdbc:hsql:foo")).isFalse(); } @Test - public void testBooleanSqlValues() { + void testBooleanSqlValues() { assertThat(underTest.getTrueSqlValue()).isEqualTo("1"); assertThat(underTest.getFalseSqlValue()).isEqualTo("0"); } @Test - public void should_configure() { + void should_configure() { assertThat(underTest.getId()).isEqualTo("oracle"); assertThat(underTest.getDefaultDriverClassName()).isEqualTo("oracle.jdbc.OracleDriver"); assertThat(underTest.getValidationQuery()).isEqualTo("SELECT 1 FROM DUAL"); } @Test - public void testFetchSizeForScrolling() { + void testFetchSizeForScrolling() { assertThat(underTest.getScrollDefaultFetchSize()).isEqualTo(200); } @Test - public void oracle_does_supportMigration() { + void oracle_does_supportMigration() { assertThat(underTest.supportsMigration()).isTrue(); } @Test - public void getSqlFromDual() { + void getSqlFromDual() { assertThat(underTest.getSqlFromDual()).isEqualTo("from dual"); } @Test - public void test_db_versions() throws Exception { + void test_db_versions() throws Exception { // oracle 11.0 is ok - DatabaseMetaData metadata = newMetadata( 11, 0, "12.1.0.1.0"); + DatabaseMetaData metadata = newMetadata( 19, 0, "12.1.0.1.0"); underTest.init(metadata); - // oracle 11.1 is noit - metadata = newMetadata(11, 1, "12.1.0.1.0"); + // oracle 11.1 is ok + metadata = newMetadata(19, 1, "12.1.0.1.0"); underTest.init(metadata); // oracle 11.2 is ok - metadata = newMetadata(11, 2, "12.1.0.1.0"); + metadata = newMetadata(19, 2, "12.1.0.1.0"); underTest.init(metadata); - // oracle 12 is ok - metadata = newMetadata(12, 0, "12.1.0.1.0"); + // oracle 21 is ok + metadata = newMetadata(21, 1, "12.1.0.1.0"); underTest.init(metadata); - // oracle 18 is ok - metadata = newMetadata(18, 0, "18.3.0.0.0"); - underTest.init(metadata); - - // oracle 10 is not supported - metadata = newMetadata(10, 2, "12.1.0.1.0"); + // oracle 18 is not supported + metadata = newMetadata(18, 17, "12.1.0.1.0"); try { underTest.init(metadata); fail(); } catch (MessageException e) { - assertThat(e).hasMessage("Unsupported oracle version: 10.2. Minimal supported version is 11.0."); + assertThat(e).hasMessage("Unsupported oracle version: 18.17. Minimal supported version is 19.0."); } } @Test - public void test_driver_versions() throws Exception { - DatabaseMetaData metadata = newMetadata( 11, 2, "18.3.0.0.0"); + void test_driver_versions() throws Exception { + DatabaseMetaData metadata = newMetadata( 19, 2, "18.3.0.0.0"); underTest.init(metadata); - metadata = newMetadata(11, 2, "12.2.0.1.0"); + metadata = newMetadata(19, 2, "12.2.0.1.0"); underTest.init(metadata); // no error - metadata = newMetadata(11, 2, "12.1.0.2.0"); + metadata = newMetadata(19, 2, "12.1.0.2.0"); underTest.init(metadata); // no error - metadata = newMetadata(11, 2, "12.1.0.1.0"); + metadata = newMetadata(19, 2, "12.1.0.1.0"); underTest.init(metadata); // no error - metadata = newMetadata(11, 2, "12.0.2"); + metadata = newMetadata(19, 2, "12.0.2"); underTest.init(metadata); // no error - metadata = newMetadata(11, 2, "11.1.0.2"); + metadata = newMetadata(19, 2, "11.1.0.2"); try { underTest.init(metadata); fail(); @@ -131,7 +127,7 @@ public class OracleTest { } @Test - public void supportsUpsert_returns_false() { + void supportsUpsert_returns_false() { assertThat(underTest.supportsUpsert()).isFalse(); } diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java index 6fc7ec2f61a..0e63f68ee2d 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java @@ -21,86 +21,83 @@ package org.sonar.db.dialect; import java.sql.DatabaseMetaData; import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Mockito; import org.slf4j.event.Level; -import org.sonar.api.testfixtures.log.LogTester; +import org.sonar.api.testfixtures.log.LogTesterJUnit5; import org.sonar.api.utils.MessageException; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class PostgreSqlTest { - @Rule - public LogTester logs = new LogTester(); + @RegisterExtension + public final LogTesterJUnit5 logs = new LogTesterJUnit5(); - private PostgreSql underTest = new PostgreSql(); + private final PostgreSql underTest = new PostgreSql(); @Test - public void matchesJdbcURL() { + void matchesJdbcURL() { assertThat(underTest.matchesJdbcUrl("jdbc:postgresql://localhost/sonar")).isTrue(); assertThat(underTest.matchesJdbcUrl("jdbc:hsql:foo")).isFalse(); } @Test - public void should_set_connection_properties() { + void should_set_connection_properties() { assertThat(underTest.getConnectionInitStatements()).isEqualTo(PostgreSql.INIT_STATEMENTS); } @Test - public void testBooleanSqlValues() { + void testBooleanSqlValues() { assertThat(underTest.getTrueSqlValue()).isEqualTo("true"); assertThat(underTest.getFalseSqlValue()).isEqualTo("false"); } @Test - public void should_configure() { + void should_configure() { assertThat(underTest.getId()).isEqualTo("postgresql"); assertThat(underTest.getDefaultDriverClassName()).isEqualTo("org.postgresql.Driver"); assertThat(underTest.getValidationQuery()).isEqualTo("SELECT 1"); } @Test - public void testFetchSizeForScrolling() { + void testFetchSizeForScrolling() { assertThat(underTest.getScrollDefaultFetchSize()).isEqualTo(200); } @Test - public void postgres_does_supportMigration() { + void postgres_does_supportMigration() { assertThat(underTest.supportsMigration()).isTrue(); } @Test - public void getSqlFromDual() { + void postgres_does_supportUpsert() { + assertThat(underTest.supportsUpsert()).isTrue(); + } + + @Test + void getSqlFromDual() { assertThat(underTest.getSqlFromDual()).isEmpty(); } @Test - public void postgresql_9_2_is_not_supported() throws Exception { + void postgresql_9_2_is_not_supported() { assertThatThrownBy(() -> { DatabaseMetaData metadata = newMetadata(9, 2); underTest.init(metadata); }) .isInstanceOf(MessageException.class) - .hasMessage("Unsupported postgresql version: 9.2. Minimal supported version is 9.3."); - } - - @Test - public void postgresql_9_3_is_supported_without_upsert() throws Exception { - DatabaseMetaData metadata = newMetadata(9, 3); - underTest.init(metadata); - - assertThat(underTest.supportsUpsert()).isFalse(); - assertThat(logs.logs(Level.WARN)).contains("Upgrading PostgreSQL to 9.5 or greater is recommended for better performances"); + .hasMessage("Unsupported postgresql version: 9.2. Minimal supported version is 11.0."); } @Test - public void postgresql_9_5_is_supported_with_upsert() throws Exception { - DatabaseMetaData metadata = newMetadata(9, 5); + void postgresql_11_0_is_supported_with_upsert() throws Exception { + DatabaseMetaData metadata = newMetadata(11, 0); underTest.init(metadata); assertThat(underTest.supportsUpsert()).isTrue(); @@ -108,8 +105,8 @@ public class PostgreSqlTest { } @Test - public void init_throws_ISE_if_called_twice() throws Exception { - DatabaseMetaData metaData = newMetadata(9, 5); + void init_throws_ISE_if_called_twice() throws Exception { + DatabaseMetaData metaData = newMetadata(11, 0); underTest.init(metaData); assertThatThrownBy(() -> underTest.init(metaData)) @@ -118,28 +115,26 @@ public class PostgreSqlTest { } @Test - public void supportsUpsert_throws_ISE_if_not_initialized() { - assertThatThrownBy(() -> underTest.supportsUpsert()) - .isInstanceOf(IllegalStateException.class) - .hasMessage("onInit() must be called before calling supportsUpsert()"); + void supportsUpsert_returns_true_even_if_not_initialized() { + assertTrue(underTest.supportsUpsert()); } @Test - public void supportsNullNotDistinct_throws_ISE_if_not_initialized() { - assertThatThrownBy(() -> underTest.supportsNullNotDistinct()) + void supportsNullNotDistinct_throws_ISE_if_not_initialized() { + assertThatThrownBy(underTest::supportsNullNotDistinct) .isInstanceOf(IllegalStateException.class) .hasMessage("onInit() must be called before calling supportsNullNotDistinct()"); } @Test - public void supportsNullNotDistinct_shouldReturnTrue_WhenPostgres15OrGreater() throws SQLException { + void supportsNullNotDistinct_shouldReturnTrue_WhenPostgres15OrGreater() throws SQLException { DatabaseMetaData metadata = newMetadata(15, 0); underTest.init(metadata); assertThat(underTest.supportsNullNotDistinct()).isTrue(); } @Test - public void supportsNullNotDistinct_shouldReturnFalse_WhenPostgres14OrLesser() throws SQLException { + void supportsNullNotDistinct_shouldReturnFalse_WhenPostgres14OrLesser() throws SQLException { DatabaseMetaData metadata = newMetadata(14, 0); underTest.init(metadata); assertThat(underTest.supportsNullNotDistinct()).isFalse(); |