aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@sonarsource.com>2014-10-08 15:36:31 +0200
committerStephane Gamard <stephane.gamard@sonarsource.com>2014-10-08 17:22:30 +0200
commit97c1b959c3e2c0e6e8cf0686d75777f12171ec1a (patch)
tree74c9dd661b2e19b63f68bcf1a9d9e762182ad110
parenta799ea39801e72ed68595599fd2d1b8a239c69d7 (diff)
downloadsonarqube-97c1b959c3e2c0e6e8cf0686d75777f12171ec1a.tar.gz
sonarqube-97c1b959c3e2c0e6e8cf0686d75777f12171ec1a.zip
added assertion for enqueue without commit in BatchSession
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/BatchSessionTest.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/BatchSessionTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/BatchSessionTest.java
index 8ead5748e1b..c5a72ab5082 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/BatchSessionTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/BatchSessionTest.java
@@ -21,13 +21,11 @@ package org.sonar.core.persistence;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
+import org.sonar.core.cluster.ClusterAction;
import org.sonar.core.cluster.WorkQueue;
import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
public class BatchSessionTest {
@Test
@@ -47,6 +45,28 @@ public class BatchSessionTest {
}
@Test
+ public void shouldCommitWhenReachingBatchSizeWithoutCommits() {
+ SqlSession mybatisSession = mock(SqlSession.class);
+ WorkQueue queue = mock(WorkQueue.class);
+ BatchSession session = new BatchSession(queue, mybatisSession, 10);
+
+ ClusterAction action = new ClusterAction() {
+ @Override
+ public Object call() throws Exception {
+ return null;
+ }
+ };
+
+ for (int i = 0; i < 9; i++) {
+ session.enqueue(action);
+ verify(mybatisSession, never()).commit();
+ verify(mybatisSession, never()).commit(anyBoolean());
+ }
+ session.enqueue(action);
+ verify(mybatisSession).commit();
+ }
+
+ @Test
public void shouldResetCounterAfterCommit() {
SqlSession mybatisSession = mock(SqlSession.class);
WorkQueue queue = mock(WorkQueue.class);