From d5cd1c456680bc1c8efc6db11c118b356b418aff Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Wed, 24 Aug 2016 13:37:09 +0200 Subject: [PATCH] SONAR-7844 re-enable some UTs disabled for H2 --- .../test/java/org/sonar/server/ce/ws/TaskActionTest.java | 8 -------- .../src/main/java/org/sonar/db/ce/CeTaskInputDao.java | 5 ++++- .../org/sonar/db/scannercontext/ScannerContextDao.java | 7 +++++-- .../src/test/java/org/sonar/db/ce/CeActivityDaoTest.java | 1 - .../v60/PopulateUserUpdatedAtOfRulesProfilesTest.java | 7 +++++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java index 269f6209913..cb06586a61a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java @@ -32,7 +32,6 @@ import org.sonar.db.ce.CeQueueDto; import org.sonar.db.ce.CeTaskTypes; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.dialect.H2; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; @@ -43,7 +42,6 @@ import org.sonarqube.ws.WsCe; import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assume.assumeTrue; import static org.sonar.core.permission.GlobalPermissions.PROVISIONING; import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION; import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN; @@ -173,9 +171,6 @@ public class TaskActionTest { @Test public void return_scannerContext_of_activity_with_scannerContext_when_additionalField_is_set() { - // H2 version we use (1.3.176) has lock bugs when table has CLOB columns which makes this test fail - assumeTrue(!dbTester.database().getDialect().getId().equals(H2.ID)); - userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN); String scannerContext = "this is some scanner context, yeah!"; @@ -196,9 +191,6 @@ public class TaskActionTest { @Test public void do_not_return_scannerContext_of_activity_with_scannerContext_when_additionalField_is_not_set() { - // H2 version we use (1.3.176) has lock bugs when table has CLOB columns which makes this test fail - assumeTrue(!dbTester.database().getDialect().getId().equals(H2.ID)); - userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN); String scannerContext = "this is some scanner context, yeah!"; diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeTaskInputDao.java b/sonar-db/src/main/java/org/sonar/db/ce/CeTaskInputDao.java index 4192be9028a..ed418eed5f7 100644 --- a/sonar-db/src/main/java/org/sonar/db/ce/CeTaskInputDao.java +++ b/sonar-db/src/main/java/org/sonar/db/ce/CeTaskInputDao.java @@ -20,6 +20,7 @@ package org.sonar.db.ce; import java.io.InputStream; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -42,13 +43,15 @@ public class CeTaskInputDao implements Dao { public void insert(DbSession dbSession, String taskUuid, InputStream data) { long now = system.now(); - try (PreparedStatement stmt = dbSession.getConnection().prepareStatement( + Connection connection = dbSession.getConnection(); + try (PreparedStatement stmt = connection.prepareStatement( "INSERT INTO ce_task_input (task_uuid, created_at, updated_at, data) VALUES (?, ?, ?, ?)")) { stmt.setString(1, taskUuid); stmt.setLong(2, now); stmt.setLong(3, now); stmt.setBinaryStream(4, data); stmt.executeUpdate(); + connection.commit(); } catch (SQLException e) { throw new IllegalStateException("Fail to insert data of CE task " + taskUuid, e); } diff --git a/sonar-db/src/main/java/org/sonar/db/scannercontext/ScannerContextDao.java b/sonar-db/src/main/java/org/sonar/db/scannercontext/ScannerContextDao.java index c294922548c..7d81688094d 100644 --- a/sonar-db/src/main/java/org/sonar/db/scannercontext/ScannerContextDao.java +++ b/sonar-db/src/main/java/org/sonar/db/scannercontext/ScannerContextDao.java @@ -22,6 +22,7 @@ package org.sonar.db.scannercontext; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -50,14 +51,16 @@ public class ScannerContextDao implements Dao { public void insert(DbSession dbSession, String analysisUuid, CloseableIterator scannerContextLines) { checkArgument(scannerContextLines.hasNext(), "Scanner context can not be empty"); long now = system.now(); - try (PreparedStatement stmt = dbSession.getConnection().prepareStatement( - "INSERT INTO scanner_context (analysis_uuid, created_at, updated_at, data) VALUES (?, ?, ?, ?)"); + Connection connection = dbSession.getConnection(); + try (PreparedStatement stmt = connection.prepareStatement( + "INSERT INTO scanner_context (analysis_uuid, created_at, updated_at, data) VALUES (?, ?, ?, ?)"); InputStream inputStream = new LogsIteratorInputStream(scannerContextLines, UTF_8)) { stmt.setString(1, analysisUuid); stmt.setLong(2, now); stmt.setLong(3, now); stmt.setBinaryStream(4, inputStream); stmt.executeUpdate(); + connection.commit(); } catch (SQLException | IOException e) { throw new IllegalStateException("Fail to insert scanner context for analysis " + analysisUuid, e); } diff --git a/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java b/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java index 147d5d76fb6..7b49b1d5a11 100644 --- a/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java @@ -371,7 +371,6 @@ public class CeActivityDaoTest { private void insertScannerContext(String analysisUuid) { db.getDbClient().scannerContextDao().insert(dbSession, analysisUuid, CloseableIterator.from(singletonList("scanner context of " + analysisUuid).iterator())); - dbSession.commit(); } private List selectPageOfUuids(int offset, int pageSize) { diff --git a/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateUserUpdatedAtOfRulesProfilesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateUserUpdatedAtOfRulesProfilesTest.java index bf9da85b2b1..ac8c1d67823 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateUserUpdatedAtOfRulesProfilesTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/v60/PopulateUserUpdatedAtOfRulesProfilesTest.java @@ -21,6 +21,7 @@ package org.sonar.db.version.v60; import com.google.common.base.Throwables; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Timestamp; @@ -99,12 +100,14 @@ public class PopulateUserUpdatedAtOfRulesProfilesTest { private void insertActivity(String profileKey, @Nullable String login, @Nullable Long createdAt) { final String sqlInsertActivity = "insert into activities (profile_key, user_login, created_at) values (?, ?, ?) "; - try (PreparedStatement ps = db.getSession().getConnection().prepareStatement(sqlInsertActivity)) { + + Connection connection = db.getSession().getConnection(); + try (PreparedStatement ps = connection.prepareStatement(sqlInsertActivity)) { ps.setString(1, profileKey); ps.setString(2, login); ps.setTimestamp(3, createdAt == null ? null : new Timestamp(createdAt)); ps.executeUpdate(); - db.getSession().commit(); + connection.commit(); } catch (SQLException e) { throw Throwables.propagate(e); } -- 2.39.5