]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5329 - Fixing Test isolation
authorStephane Gamard <stephane.gamard@searchbox.com>
Wed, 18 Jun 2014 14:10:07 +0000 (16:10 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Wed, 18 Jun 2014 14:10:07 +0000 (16:10 +0200)
sonar-server/src/main/java/org/sonar/server/component/persistence/ComponentDao.java
sonar-server/src/main/java/org/sonar/server/db/migrations/v44/ChangeLogMigration.java
sonar-server/src/test/java/org/sonar/server/component/persistence/ComponentDaoTest.java

index cf64e3f423b2b4c253df42fd4ae86d6368e91c6d..d6618173c35ebea777f27902b8300ea7e89f1991 100644 (file)
@@ -29,6 +29,8 @@ import org.sonar.core.persistence.DaoComponent;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.server.db.BaseDao;
 
+import java.util.Date;
+
 /**
  * @since 4.3
  */
@@ -77,7 +79,7 @@ public class ComponentDao extends BaseDao<ComponentMapper, ComponentDto, String>
   }
 
   @Override
-  public void synchronizeAfter(DbSession session, long timestamp) {
+  public void synchronizeAfter(DbSession session, Date timestamp) {
     throw notImplemented();
   }
 
index 395d504daea0af8824399c2ea50b11c1ef77d957..968069623241c434f69e281c35242f74f3b694c5 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.db.migrations.v44;
 
+import org.apache.commons.dbutils.DbUtils;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.core.activity.Activity;
@@ -135,17 +136,21 @@ public class ChangeLogMigration implements DatabaseMigration {
 
   @Override
   public void execute() {
-    this.session = db.openSession(false);
-    executeUpsert(ActiveRuleChange.Type.ACTIVATED, allActivation);
-    executeUpsert(ActiveRuleChange.Type.UPDATED, allUpdates);
-    executeUpsert(ActiveRuleChange.Type.DEACTIVATED, allDeactivation);
-    session.commit();
-    session.close();
+    try {
+      this.session = db.openSession(false);
+      executeUpsert(ActiveRuleChange.Type.ACTIVATED, allActivation);
+      executeUpsert(ActiveRuleChange.Type.UPDATED, allUpdates);
+      executeUpsert(ActiveRuleChange.Type.DEACTIVATED, allDeactivation);
+      session.commit();
+    } finally {
+      session.close();
+    }
   }
 
   private void executeUpsert(ActiveRuleChange.Type type, String sql) {
+    Connection connection = null;
     try {
-      Connection connection = db.database().getDataSource().getConnection();
+      connection = db.database().getDataSource().getConnection();
       ResultSet result = connection.createStatement().executeQuery(sql);
 
       //startCase
@@ -172,6 +177,8 @@ public class ChangeLogMigration implements DatabaseMigration {
 
     } catch (Exception e) {
       e.printStackTrace();
+    } finally {
+      DbUtils.closeQuietly(connection);
     }
   }
 
index e05ac4ca6b0bc8f125ba8b868dac340d472b574e..4d794a8c9ad1e75fedcbc955da4cff1c2dfb989f 100644 (file)
@@ -28,6 +28,8 @@ import org.sonar.core.component.ComponentDto;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 import org.sonar.core.persistence.DbSession;
 
+import java.util.Date;
+
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -146,6 +148,6 @@ public class ComponentDaoTest extends AbstractDaoTestCase {
 
   @Test(expected = IllegalStateException.class)
   public void synchronize_after() {
-    dao.synchronizeAfter(session, 1L);
+    dao.synchronizeAfter(session, new Date(0L));
   }
 }