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;
@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);
@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;
@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;
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;
IssueTesting.newDto(rule, file1, project1),
IssueTesting.newDto(rule, file2, project2),
IssueTesting.newDto(rule, file2, project3)
- );
+ );
session.commit();
session.clearCache();
}
@Test
- @Ignore("To be fixed")
public void synchronize_a_lot_of_issues() throws Exception {
ComponentDto project = new ComponentDto()
.setKey("MyProject")
}
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();
// 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);
}
-
}
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;
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() {