]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5614 - Removed implicit-commit in session in Favor of BatchSession for synchron...
authorStephane Gamard <stephane.gamard@sonarsource.com>
Mon, 29 Sep 2014 14:17:15 +0000 (16:17 +0200)
committerStephane Gamard <stephane.gamard@sonarsource.com>
Mon, 29 Sep 2014 14:17:15 +0000 (16:17 +0200)
server/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java
server/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java
sonar-core/src/main/java/org/sonar/core/persistence/DbSession.java

index 097601a7326e82a860f5ef33b1146104f73becc5..f584ab9efd124906e841c28919b0e2e0632a166c 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.ibatis.session.ResultContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.BatchSession;
 import org.sonar.core.persistence.DaoComponent;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.persistence.Dto;
@@ -360,6 +361,10 @@ public abstract class BaseDao<MAPPER, DTO extends Dto<KEY>, KEY extends Serializ
 
   @Override
   public void synchronizeAfter(final DbSession session, Date date, Map<String, String> params) {
+    if (!session.getClass().isAssignableFrom(BatchSession.class)) {
+      LOGGER.warn("Synchronizer should only be used with BatchSession!");
+    }
+
     try {
       DbSynchronizationHandler handler = getSynchronizationResultHandler(session, params);
       session.select(getSynchronizeStatementFQN(), getSynchronizationParams(date, params), handler);
index 2d1c4725ec985735478ffc4c67d3328741151f42..0ee7cb9247908ae637ad454a77f2d43fe6c017d0 100644 (file)
@@ -115,9 +115,6 @@ public class ActivityBackendMediumTest {
   @Test
   public void massive_insert() {
 
-    // Set qeue's implicit commit size to 10
-    dbSession.setImplicitCommitSize(10);
-
     // 0 Assert no logs in DB
     assertThat(dao.findAll(dbSession)).hasSize(0);
     int max = 35;
@@ -159,9 +156,6 @@ public class ActivityBackendMediumTest {
   @Test
   public void massive_log_insert() {
 
-    // Set qeue's implicit commit size to 10
-    dbSession.setImplicitCommitSize(10);
-
     // 0 Assert no logs in DB
     assertThat(dao.findAll(dbSession)).hasSize(0);
     int max = 40;
index 9c29f6ed39c24ce44780a2f0870dc7e0a7e83e8d..81f6ba1ddf45a0e86de87817011720982dcc00df 100644 (file)
 package org.sonar.server.issue.index;
 
 import com.google.common.collect.ImmutableMap;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.issue.IssueQuery;
 import org.sonar.api.rule.RuleKey;
@@ -568,7 +571,7 @@ public class IssueIndexMediumTest {
       IssueTesting.newDto(rule, file1, project1),
       IssueTesting.newDto(rule, file2, project2),
       IssueTesting.newDto(rule, file2, project3)
-      );
+    );
 
     session.commit();
     session.clearCache();
@@ -620,7 +623,6 @@ public class IssueIndexMediumTest {
   }
 
   @Test
-  @Ignore("To be fixed")
   public void synchronize_a_lot_of_issues() throws Exception {
     ComponentDto project = new ComponentDto()
       .setKey("MyProject")
@@ -645,14 +647,20 @@ public class IssueIndexMediumTest {
     }
     session.commit();
 
+    // 0 Assert that all issues are both in ES and DB
+    assertThat(db.issueDao().findAfterDate(session, new Date(0))).hasSize(11);
+    assertThat(index.countAll()).isEqualTo(11);
+
+
     // Clear issue index in order to simulate these issues have been inserted without being indexed in E/S (from a previous version of SQ or from batch)
     tester.get(BackendCleanup.class).clearIndex(IndexDefinition.ISSUES);
     tester.clearIndexes();
-    session.commit();
-    session.clearCache();
+
 
     DbSession newSession = db.openSession(true);
-    newSession.setImplicitCommitSize(10);
+    //newSession.setImplicitCommitSize(10);
+
+    System.out.println("index.getLastSynchronization() = " + index.getLastSynchronization());
     try {
       db.issueDao().synchronizeAfter(newSession, index.getLastSynchronization());
       newSession.commit();
@@ -666,8 +674,7 @@ public class IssueIndexMediumTest {
 
     // This test is working with executeStartupTasks !
 //    tester.get(Platform.class).executeStartupTasks();
+    assertThat(index.countAll()).isEqualTo(11);
 
-    assertThat(index.search(IssueQuery.builder().build(), new QueryContext().setMaxLimit()).getHits()).hasSize(11);
   }
-
 }
index 2bca0acee02b4df2e6455581af0529455d266f8e..503d302112fb7dee496f8ad8e0b2777651f5af0a 100644 (file)
@@ -34,15 +34,12 @@ import java.util.Map;
 
 public class DbSession implements SqlSession {
 
-  private static final Integer IMPLICIT_COMMIT_SIZE = 2000;
   private List<ClusterAction> actions;
 
   private WorkQueue queue;
   private SqlSession session;
   private int actionCount;
 
-  private Integer implicitCommitSize = IMPLICIT_COMMIT_SIZE;
-
   DbSession(WorkQueue queue, SqlSession session) {
     this.actionCount = 0;
     this.session = session;
@@ -50,20 +47,9 @@ public class DbSession implements SqlSession {
     this.actions = new ArrayList<ClusterAction>();
   }
 
-  public Integer getImplicitCommitSize() {
-    return implicitCommitSize;
-  }
-
-  public void setImplicitCommitSize(Integer implicitCommitSize) {
-    this.implicitCommitSize = implicitCommitSize;
-  }
-
   public void enqueue(ClusterAction action) {
     actionCount++;
     this.actions.add(action);
-    if (this.actions.size() > getImplicitCommitSize()) {
-      this.commit();
-    }
   }
 
   public int getActionCount() {