summaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-02-05 16:51:05 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-02-10 17:13:16 +0100
commite851411f7fd6a1e9f8e94caf92ef10699acb03a9 (patch)
treeadfa5ee5511d0e4b6c7410279d302b42c9d987ee /sonar-db
parenta1be1bb19a200cf6cc2e2685972623df96e553fd (diff)
downloadsonarqube-e851411f7fd6a1e9f8e94caf92ef10699acb03a9.tar.gz
sonarqube-e851411f7fd6a1e9f8e94caf92ef10699acb03a9.zip
Enable QA pipeline at SonarSource
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/pom.xml65
-rw-r--r--sonar-db/src/test/java/org/sonar/db/DatabaseCommands.java42
-rw-r--r--sonar-db/src/test/java/org/sonar/db/version/v50/FeedFileSourcesTest.java22
3 files changed, 97 insertions, 32 deletions
diff --git a/sonar-db/pom.xml b/sonar-db/pom.xml
index 0715efa447c..86339eed76d 100644
--- a/sonar-db/pom.xml
+++ b/sonar-db/pom.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -140,11 +141,59 @@
<profiles>
<profile>
+ <id>create-db</id>
+ <activation>
+ <property>
+ <name>env.SONARSOURCE_QA</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>download-sq</id>
+ <goals>
+ <goal>get</goal>
+ </goals>
+ <phase>generate-test-resources</phase>
+ <configuration>
+ <artifact>${project.groupId}:sonar-application:${project.version}:zip</artifact>
+ <transitive>false</transitive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.sonarsource.orchestrator</groupId>
+ <artifactId>orchestrator-maven-plugin</artifactId>
+ <version>${orchestrator.version}</version>
+ <executions>
+ <execution>
+ <id>create-db</id>
+ <goals>
+ <goal>create-db</goal>
+ </goals>
+ <phase>generate-test-resources</phase>
+ <configuration>
+ <sqVersion>${project.version}</sqVersion>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
<!-- SonarSource internal use -->
- <id>dbTests</id>
+ <id>with-db-drivers</id>
<activation>
<property>
- <name>dbTests</name>
+ <name>with-db-drivers</name>
</property>
</activation>
<properties>
@@ -160,18 +209,16 @@
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
- <!-- this artifact is located in the SonarSource internal repository -->
- <groupId>com.oracle</groupId>
- <artifactId>ojdbc6</artifactId>
- <version>11.2.0.3.0</version>
- <scope>test</scope>
+ <groupId>com.oracle</groupId>
+ <artifactId>ojdbc6</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqljdbc</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
<scope>system</scope>
- <systemPath>${project.basedir}/../sonar-application/src/main/assembly/lib/jdbc/mssql/sqljdbc41.jar</systemPath>
+ <systemPath>${project.basedir}/../sonar-application/src/main/assembly/lib/jdbc/mssql/sqljdbc41.jar
+ </systemPath>
</dependency>
</dependencies>
</profile>
diff --git a/sonar-db/src/test/java/org/sonar/db/DatabaseCommands.java b/sonar-db/src/test/java/org/sonar/db/DatabaseCommands.java
index a26a9b70322..b4c129d8af7 100644
--- a/sonar-db/src/test/java/org/sonar/db/DatabaseCommands.java
+++ b/sonar-db/src/test/java/org/sonar/db/DatabaseCommands.java
@@ -185,27 +185,31 @@ public abstract class DatabaseCommands {
}
public void resetPrimaryKeys(DataSource dataSource) throws SQLException {
- Connection connection = dataSource.getConnection();
- connection.setAutoCommit(false);
-
- Statement statement = connection.createStatement();
- for (String table : DatabaseVersion.TABLES) {
- try {
- ResultSet result = statement.executeQuery("SELECT CASE WHEN MAX(ID) IS NULL THEN 1 ELSE MAX(ID)+1 END FROM " + table);
- result.next();
- int maxId = result.getInt(1);
- result.close();
-
- for (String resetCommand : resetSequenceSql(table, maxId)) {
- statement.executeUpdate(resetCommand);
+ Connection connection = null;
+ Statement statement = null;
+ ResultSet resultSet = null;
+ try {
+ connection = dataSource.getConnection();
+ connection.setAutoCommit(false);
+
+ statement = connection.createStatement();
+ for (String table : DatabaseVersion.TABLES) {
+ try {
+ resultSet = statement.executeQuery("SELECT CASE WHEN MAX(ID) IS NULL THEN 1 ELSE MAX(ID)+1 END FROM " + table);
+ resultSet.next();
+ int maxId = resultSet.getInt(1);
+ resultSet.close();
+
+ for (String resetCommand : resetSequenceSql(table, maxId)) {
+ statement.executeUpdate(resetCommand);
+ }
+ connection.commit();
+ } catch (Exception e) {
+ connection.rollback(); // this table has no primary key
}
- connection.commit();
- } catch (Exception e) {
- connection.rollback(); // this table has no primary key
}
+ } finally {
+ DbUtils.closeQuietly(connection, statement, resultSet);
}
-
- statement.close();
- connection.close();
}
}
diff --git a/sonar-db/src/test/java/org/sonar/db/version/v50/FeedFileSourcesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v50/FeedFileSourcesTest.java
index cb061b21b17..665d31b9023 100644
--- a/sonar-db/src/test/java/org/sonar/db/version/v50/FeedFileSourcesTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/version/v50/FeedFileSourcesTest.java
@@ -120,11 +120,10 @@ public class FeedFileSourcesTest {
try {
connection = db.openConnection();
- connection.prepareStatement("insert into snapshot_sources " +
+ db.executeUpdateSql("insert into snapshot_sources " +
"(snapshot_id, data, updated_at) " +
"values " +
- "(6, 'class Foo {\r\n // Empty\r\n}\r\n', '2014-10-31 16:44:02.000')")
- .executeUpdate();
+ "(6, 'class Foo {\r\n // Empty\r\n}\r\n', '2014-10-31 16:44:02.000')");
db.executeUpdateSql("insert into snapshot_sources " +
"(snapshot_id, data, updated_at) " +
@@ -137,6 +136,7 @@ public class FeedFileSourcesTest {
"(1, 6, ?)");
revisionStmt.setBytes(1, "1=aef12a;2=abe465;3=afb789;4=afb789".getBytes(StandardCharsets.UTF_8));
revisionStmt.executeUpdate();
+ revisionStmt.close();
PreparedStatement authorStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -144,6 +144,7 @@ public class FeedFileSourcesTest {
"(2, 6, ?)");
authorStmt.setBytes(1, "1=alice;2=bob;3=carol;4=carol".getBytes(StandardCharsets.UTF_8));
authorStmt.executeUpdate();
+ authorStmt.close();
PreparedStatement dateStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -151,6 +152,7 @@ public class FeedFileSourcesTest {
"(3, 6, ?)");
dateStmt.setBytes(1, "1=2014-04-25T12:34:56+0100;2=2014-07-25T12:34:56+0100;3=2014-03-23T12:34:56+0100;4=2014-03-23T12:34:56+0100".getBytes(StandardCharsets.UTF_8));
dateStmt.executeUpdate();
+ dateStmt.close();
PreparedStatement utHitsStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -158,6 +160,7 @@ public class FeedFileSourcesTest {
"(4, 6, ?)");
utHitsStmt.setBytes(1, "1=1;3=0".getBytes(StandardCharsets.UTF_8));
utHitsStmt.executeUpdate();
+ utHitsStmt.close();
PreparedStatement utCondStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -165,6 +168,7 @@ public class FeedFileSourcesTest {
"(5, 6, ?)");
utCondStmt.setBytes(1, "1=4".getBytes(StandardCharsets.UTF_8));
utCondStmt.executeUpdate();
+ utCondStmt.close();
PreparedStatement utCoveredCondStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -172,6 +176,7 @@ public class FeedFileSourcesTest {
"(6, 6, ?)");
utCoveredCondStmt.setBytes(1, "1=2".getBytes(StandardCharsets.UTF_8));
utCoveredCondStmt.executeUpdate();
+ utCoveredCondStmt.close();
PreparedStatement itHitsStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -179,6 +184,7 @@ public class FeedFileSourcesTest {
"(7, 6, ?)");
itHitsStmt.setBytes(1, "1=2;3=0".getBytes(StandardCharsets.UTF_8));
itHitsStmt.executeUpdate();
+ itHitsStmt.close();
PreparedStatement itCondStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -186,6 +192,7 @@ public class FeedFileSourcesTest {
"(8, 6, ?)");
itCondStmt.setBytes(1, "1=5".getBytes(StandardCharsets.UTF_8));
itCondStmt.executeUpdate();
+ itCondStmt.close();
PreparedStatement itCoveredCondStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -193,6 +200,7 @@ public class FeedFileSourcesTest {
"(9, 6, ?)");
itCoveredCondStmt.setBytes(1, "1=3".getBytes(StandardCharsets.UTF_8));
itCoveredCondStmt.executeUpdate();
+ itCoveredCondStmt.close();
PreparedStatement overallHitsStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -200,6 +208,7 @@ public class FeedFileSourcesTest {
"(10, 6, ?)");
overallHitsStmt.setBytes(1, "1=3;3=0".getBytes(StandardCharsets.UTF_8));
overallHitsStmt.executeUpdate();
+ overallHitsStmt.close();
PreparedStatement overallCondStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -207,6 +216,7 @@ public class FeedFileSourcesTest {
"(11, 6, ?)");
overallCondStmt.setBytes(1, "1=6".getBytes(StandardCharsets.UTF_8));
overallCondStmt.executeUpdate();
+ overallCondStmt.close();
PreparedStatement overallCoveredCondStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -214,6 +224,7 @@ public class FeedFileSourcesTest {
"(12, 6, ?)");
overallCoveredCondStmt.setBytes(1, "1=4".getBytes(StandardCharsets.UTF_8));
overallCoveredCondStmt.executeUpdate();
+ overallCoveredCondStmt.close();
PreparedStatement duplicationDataStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, " + columnName + ") " +
@@ -225,6 +236,7 @@ public class FeedFileSourcesTest {
"<duplications><g><b s=\"1\" l=\"1\" r=\"MyProject:src/main/xoo/prj/MyFile.xoo\"/><b s=\"2\" l=\"1\" r=\"MyProject:src/main/xoo/prj/MyFile.xoo\"/><b s=\"3\" l=\"1\" r=\"MyProject:src/main/xoo/prj/AnotherFile.xoo\"/></g></duplications>"
.getBytes(StandardCharsets.UTF_8));
duplicationDataStmt.executeUpdate();
+ duplicationDataStmt.close();
} finally {
DbUtils.commitAndCloseQuietly(connection);
}
@@ -259,6 +271,7 @@ public class FeedFileSourcesTest {
db.prepareDbUnit(getClass(), "before.xml");
Connection connection = null;
+ PreparedStatement duplicationDataStmt = null;
try {
connection = db.openConnection();
@@ -273,7 +286,7 @@ public class FeedFileSourcesTest {
"values " +
"(7, '', '2014-10-31 16:44:02.000')");
- PreparedStatement duplicationDataStmt = connection.prepareStatement("insert into project_measures " +
+ duplicationDataStmt = connection.prepareStatement("insert into project_measures " +
"(metric_id, snapshot_id, text_value) " +
"values " +
"(13, 6, ?)");
@@ -284,6 +297,7 @@ public class FeedFileSourcesTest {
.getBytes(StandardCharsets.UTF_8));
duplicationDataStmt.executeUpdate();
} finally {
+ DbUtils.close(duplicationDataStmt);
DbUtils.commitAndCloseQuietly(connection);
}