aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-11-15 10:42:49 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-11-16 13:59:29 +0100
commita4b766dbe29c82b726c54a0ef77afe3b1241608d (patch)
tree3b7f24da0c314b8d550f0d98725704bc768f0033
parent3d4c362f1d95f5d093fb2c99ad999cc3f93cef05 (diff)
downloadsonarqube-a4b766dbe29c82b726c54a0ef77afe3b1241608d.tar.gz
sonarqube-a4b766dbe29c82b726c54a0ef77afe3b1241608d.zip
SONAR-6912 Use System2 in BaseIndexer
in order to wrap call to System.currentTimeMillis(). That is needed to bypass the condition "if (requestedAt > lastUpdatedAt)" in tests.
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexer.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/es/BaseIndexer.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexer.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java15
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexer.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexer.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java26
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java22
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java18
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java8
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/es/ProjectMeasuresIndexerTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/BulkUpdateKeyActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/IndexTestsStepTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java16
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java21
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java13
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java12
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java24
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java15
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java12
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java23
38 files changed, 197 insertions, 168 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexer.java
index a7b32d9cccf..15d44c7d64a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexer.java
@@ -24,6 +24,7 @@ import java.util.Date;
import java.util.Iterator;
import javax.annotation.Nullable;
import org.elasticsearch.action.index.IndexRequest;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.measure.ProjectMeasuresIndexerIterator;
@@ -41,8 +42,8 @@ public class ProjectMeasuresIndexer extends BaseIndexer {
private final DbClient dbClient;
- public ProjectMeasuresIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES, FIELD_ANALYSED_AT);
+ public ProjectMeasuresIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, INDEX_PROJECT_MEASURES, TYPE_PROJECT_MEASURES, FIELD_ANALYSED_AT);
this.dbClient = dbClient;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/BaseIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/es/BaseIndexer.java
index 629f08cbe93..94fcec7bafa 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/es/BaseIndexer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/es/BaseIndexer.java
@@ -27,18 +27,21 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.picocontainer.Startable;
+import org.sonar.api.utils.System2;
public abstract class BaseIndexer implements Startable {
+ private final System2 system2;
private final ThreadPoolExecutor executor;
private final String indexName;
private final String typeName;
- private final String dateFieldName;
protected final EsClient esClient;
+ private final String dateFieldName;
private volatile long lastUpdatedAt = -1L;
- protected BaseIndexer(EsClient client, long threadKeepAliveSeconds, String indexName, String typeName,
+ protected BaseIndexer(System2 system2, EsClient client, long threadKeepAliveSeconds, String indexName, String typeName,
String dateFieldName) {
+ this.system2 = system2;
this.indexName = indexName;
this.typeName = typeName;
this.dateFieldName = dateFieldName;
@@ -48,7 +51,7 @@ public abstract class BaseIndexer implements Startable {
}
public void index(final IndexerTask task) {
- final long requestedAt = System.currentTimeMillis();
+ final long requestedAt = system2.now();
Future submit = executor.submit(() -> {
if (lastUpdatedAt == -1L) {
lastUpdatedAt = esClient.getMaxFieldValue(indexName, typeName, dateFieldName);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexer.java
index b91af14dc74..7cf8322d315 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexer.java
@@ -25,6 +25,7 @@ import javax.annotation.Nullable;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.es.BaseIndexer;
@@ -47,8 +48,8 @@ public class IssueIndexer extends BaseIndexer {
private final DbClient dbClient;
- public IssueIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, INDEX, TYPE_ISSUE, FIELD_ISSUE_TECHNICAL_UPDATED_AT);
+ public IssueIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, INDEX, TYPE_ISSUE, FIELD_ISSUE_TECHNICAL_UPDATED_AT);
this.dbClient = dbClient;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
index 29d1f9a5901..24af390ae53 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
@@ -28,6 +28,7 @@ import javax.annotation.Nonnull;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.index.query.QueryBuilders;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleKey;
@@ -47,8 +48,8 @@ public class ActiveRuleIndexer extends BaseIndexer {
private final DbClient dbClient;
- public ActiveRuleIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, INDEX, TYPE_ACTIVE_RULE, FIELD_ACTIVE_RULE_UPDATED_AT);
+ public ActiveRuleIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, INDEX, TYPE_ACTIVE_RULE, FIELD_ACTIVE_RULE_UPDATED_AT);
this.dbClient = dbClient;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
index e8689201e07..1a88a0eeeec 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
@@ -21,6 +21,7 @@ package org.sonar.server.rule.index;
import java.util.Iterator;
import org.elasticsearch.action.index.IndexRequest;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.es.BaseIndexer;
@@ -35,8 +36,8 @@ public class RuleIndexer extends BaseIndexer {
private final DbClient dbClient;
- public RuleIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, INDEX, TYPE_RULE, FIELD_RULE_UPDATED_AT);
+ public RuleIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, INDEX, TYPE_RULE, FIELD_RULE_UPDATED_AT);
this.dbClient = dbClient;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java
index 2b20ffdac67..6ac3d86d8f2 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java
@@ -19,15 +19,11 @@
*/
package org.sonar.server.test.index;
-import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID;
-import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT;
-import static org.sonar.server.test.index.TestIndexDefinition.INDEX;
-import static org.sonar.server.test.index.TestIndexDefinition.TYPE;
-
import java.util.Iterator;
import javax.annotation.Nullable;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.index.query.QueryBuilders;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.es.BaseIndexer;
@@ -35,6 +31,11 @@ import org.sonar.server.es.BulkIndexer;
import org.sonar.server.es.EsClient;
import org.sonar.server.source.index.FileSourcesUpdaterHelper;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID;
+import static org.sonar.server.test.index.TestIndexDefinition.FIELD_UPDATED_AT;
+import static org.sonar.server.test.index.TestIndexDefinition.INDEX;
+import static org.sonar.server.test.index.TestIndexDefinition.TYPE;
+
/**
* Add to Elasticsearch index {@link TestIndexDefinition} the rows of
* db table FILE_SOURCES of type TEST that are not indexed yet
@@ -43,8 +44,8 @@ public class TestIndexer extends BaseIndexer {
private final DbClient dbClient;
- public TestIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 0L, INDEX, TYPE, FIELD_UPDATED_AT);
+ public TestIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 0L, INDEX, TYPE, FIELD_UPDATED_AT);
this.dbClient = dbClient;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexer.java
index cdb8a3b78ee..970b9a8a321 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexer.java
@@ -21,6 +21,7 @@ package org.sonar.server.user.index;
import java.util.Iterator;
import org.elasticsearch.action.index.IndexRequest;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.es.BaseIndexer;
@@ -31,8 +32,8 @@ public class UserIndexer extends BaseIndexer {
private final DbClient dbClient;
- public UserIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, UserIndexDefinition.FIELD_UPDATED_AT);
+ public UserIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER, UserIndexDefinition.FIELD_UPDATED_AT);
this.dbClient = dbClient;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexer.java b/server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexer.java
index aaf546137e2..d825e79fb27 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexer.java
@@ -22,6 +22,7 @@ package org.sonar.server.view.index;
import java.util.List;
import java.util.Map;
import org.elasticsearch.action.index.IndexRequest;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
@@ -36,8 +37,8 @@ public class ViewIndexer extends BaseIndexer {
private final DbClient dbClient;
- public ViewIndexer(DbClient dbClient, EsClient esClient) {
- super(esClient, 300, ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, "updatedAt");
+ public ViewIndexer(System2 system2, DbClient dbClient, EsClient esClient) {
+ super(system2, esClient, 300, ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, "updatedAt");
this.dbClient = dbClient;
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
index 9e0ef04b242..01f12089f79 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
@@ -54,20 +54,20 @@ import static org.mockito.Mockito.mock;
public class IssuesActionTest {
- final static String PROJECT_KEY = "struts";
- static final String PROJECT_UUID = "ABCD";
+ private static final String PROJECT_KEY = "struts";
+ private static final String PROJECT_UUID = "ABCD";
+ private static final String MODULE_KEY = "struts-core";
+ private static final String MODULE_UUID = "BCDE";
+ private final static String FILE_KEY = "Action.java";
+ private static final String FILE_UUID = "CDEF";
- final static String MODULE_KEY = "struts-core";
- static final String MODULE_UUID = "BCDE";
-
- final static String FILE_KEY = "Action.java";
- static final String FILE_UUID = "CDEF";
+ private System2 system2 = System2.INSTANCE;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings()));
@@ -79,15 +79,13 @@ public class IssuesActionTest {
private IssueIndexer issueIndexer;
private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es);
private ServerFileSystem fs = mock(ServerFileSystem.class);
-
- WsTester tester;
-
- IssuesAction issuesAction;
+ private WsTester tester;
+ private IssuesAction issuesAction;
@Before
public void before() {
- issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSessionRule);
- issueIndexer = new IssueIndexer(null, es.client());
+ issueIndex = new IssueIndex(es.client(), system2, userSessionRule);
+ issueIndexer = new IssueIndexer(system2, null, es.client());
issuesAction = new IssuesAction(db.getDbClient(), issueIndex, userSessionRule, new ComponentFinder(db.getDbClient()));
tester = new WsTester(new BatchWs(new BatchIndex(fs), issuesAction));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java
index 3a1a7d2f35c..e43ef097329 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java
@@ -61,8 +61,10 @@ import static org.sonar.server.issue.index.IssueIndexDefinition.TYPE_ISSUE;
public class ComponentCleanerServiceTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester es = new EsTester(
@@ -73,17 +75,15 @@ public class ComponentCleanerServiceTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- DbClient dbClient = db.getDbClient();
- DbSession dbSession = db.getSession();
-
- PermissionIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client());
- IssueIndexer issueIndexer = new IssueIndexer(dbClient, es.client());
- TestIndexer testIndexer = new TestIndexer(dbClient, es.client());
- ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(dbClient, es.client());
-
- ResourceTypes mockResourceTypes = mock(ResourceTypes.class);
+ private DbClient dbClient = db.getDbClient();
+ private DbSession dbSession = db.getSession();
+ private PermissionIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client());
+ private IssueIndexer issueIndexer = new IssueIndexer(system2, dbClient, es.client());
+ private TestIndexer testIndexer = new TestIndexer(system2, dbClient, es.client());
+ private ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(system2, dbClient, es.client());
+ private ResourceTypes mockResourceTypes = mock(ResourceTypes.class);
- ComponentCleanerService underTest = new ComponentCleanerService(dbClient, issueIndexer, testIndexer, projectMeasuresIndexer, mockResourceTypes,
+ private ComponentCleanerService underTest = new ComponentCleanerService(dbClient, issueIndexer, testIndexer, projectMeasuresIndexer, mockResourceTypes,
new ComponentFinder(dbClient));
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java
index 9e38c293e72..0c94ab9fded 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java
@@ -63,6 +63,8 @@ import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.TYPE_
public class ComponentServiceTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@@ -75,21 +77,19 @@ public class ComponentServiceTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- ComponentDbTester componentDb = new ComponentDbTester(dbTester);
- DbClient dbClient = dbTester.getDbClient();
- DbSession dbSession = dbTester.getSession();
-
- I18nRule i18n = new I18nRule();
+ private ComponentDbTester componentDb = new ComponentDbTester(dbTester);
+ private DbClient dbClient = dbTester.getDbClient();
+ private DbSession dbSession = dbTester.getSession();
+ private I18nRule i18n = new I18nRule();
+ private ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(system2, dbClient, es.client());
- ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(dbClient, es.client());
-
- ComponentService underTest;
+ private ComponentService underTest;
@Before
public void setUp() {
i18n.put("qualifier.TRK", "Project");
- underTest = new ComponentService(dbClient, i18n, userSession, System2.INSTANCE, new ComponentFinder(dbClient), projectMeasuresIndexer);
+ underTest = new ComponentService(dbClient, i18n, userSession, system2, new ComponentFinder(dbClient), projectMeasuresIndexer);
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java
index 1b8b843e24d..1fe3e9dbee1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java
@@ -56,6 +56,8 @@ import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.TYPE_
public class ComponentServiceUpdateKeyTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@@ -66,7 +68,7 @@ public class ComponentServiceUpdateKeyTest {
public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
ComponentDbTester componentDb = new ComponentDbTester(db);
DbClient dbClient = db.getDbClient();
@@ -74,7 +76,7 @@ public class ComponentServiceUpdateKeyTest {
I18nRule i18n = new I18nRule();
- ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(dbClient, es.client());
+ ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(system2, dbClient, es.client());
ComponentService underTest;
@@ -82,7 +84,7 @@ public class ComponentServiceUpdateKeyTest {
public void setUp() {
i18n.put("qualifier.TRK", "Project");
- underTest = new ComponentService(dbClient, i18n, userSession, System2.INSTANCE, new ComponentFinder(dbClient), projectMeasuresIndexer);
+ underTest = new ComponentService(dbClient, i18n, userSession, system2, new ComponentFinder(dbClient), projectMeasuresIndexer);
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java
index 3b7adea5518..2955d6d959b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java
@@ -52,8 +52,10 @@ import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
public class DefaultRubyComponentServiceTest {
+ private System2 system2 = mock(System2.class);
+
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@@ -67,8 +69,8 @@ public class DefaultRubyComponentServiceTest {
private DbSession dbSession = db.getSession();
private ResourceDao resourceDao = dbClient.resourceDao();
- private ComponentService componentService = new ComponentService(dbClient, i18n, userSession, System2.INSTANCE, new ComponentFinder(dbClient),
- new ProjectMeasuresIndexer(dbClient, es.client()));
+ private ComponentService componentService = new ComponentService(dbClient, i18n, userSession, system2, new ComponentFinder(dbClient),
+ new ProjectMeasuresIndexer(system2, dbClient, es.client()));
private PermissionTemplateService permissionTemplateService = mock(PermissionTemplateService.class);
private FavoriteService favoriteService = mock(FavoriteService.class);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/es/ProjectMeasuresIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/es/ProjectMeasuresIndexerTest.java
index 0ee1c4935df..26ebdbc96b5 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/es/ProjectMeasuresIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/es/ProjectMeasuresIndexerTest.java
@@ -45,16 +45,18 @@ import static org.sonar.server.component.es.ProjectMeasuresIndexDefinition.TYPE_
public class ProjectMeasuresIndexerTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester esTester = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
ComponentDbTester componentDbTester = new ComponentDbTester(dbTester);
PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(esTester);
- ProjectMeasuresIndexer underTest = new ProjectMeasuresIndexer(dbTester.getDbClient(), esTester.client());
+ ProjectMeasuresIndexer underTest = new ProjectMeasuresIndexer(system2, dbTester.getDbClient(), esTester.client());
@Test
public void index_nothing() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/BulkUpdateKeyActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/BulkUpdateKeyActionTest.java
index dc3e49866b0..bd7441442ed 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/BulkUpdateKeyActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/BulkUpdateKeyActionTest.java
@@ -70,6 +70,8 @@ public class BulkUpdateKeyActionTest {
static final String FROM = "my_";
static final String TO = "your_";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -80,7 +82,7 @@ public class BulkUpdateKeyActionTest {
public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
ComponentDbTester componentDb = new ComponentDbTester(db);
DbClient dbClient = db.getDbClient();
@@ -89,7 +91,7 @@ public class BulkUpdateKeyActionTest {
ComponentFinder componentFinder = new ComponentFinder(dbClient);
WsActionTester ws = new WsActionTester(
- new BulkUpdateKeyAction(dbClient, componentFinder, new ComponentService(dbClient, null, null, null, null, new ProjectMeasuresIndexer(dbClient, es.client())), userSession));
+ new BulkUpdateKeyAction(dbClient, componentFinder, new ComponentService(dbClient, null, null, null, null, new ProjectMeasuresIndexer(system2, dbClient, es.client())), userSession));
@Before
public void setUp() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/IndexTestsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/IndexTestsStepTest.java
index fcfb197ab14..c16a1a506ba 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/IndexTestsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/IndexTestsStepTest.java
@@ -41,8 +41,10 @@ import static org.assertj.core.api.Assertions.assertThat;
public class IndexTestsStepTest extends BaseStepTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new TestIndexDefinition(new MapSettings()));
@@ -54,7 +56,7 @@ public class IndexTestsStepTest extends BaseStepTest {
@Override
protected ComputationStep step() {
- TestIndexer testIndexer = new TestIndexer(dbClient, esTester.client());
+ TestIndexer testIndexer = new TestIndexer(system2, dbClient, esTester.client());
return new IndexTestsStep(testIndexer, treeRootHolder);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
index 39fe0c470dd..672242c1ed1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
@@ -63,6 +63,7 @@ public class IssueIndexDebtTest {
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
+ private System2 system2 = System2.INSTANCE;
IssueIndex index;
IssueIndexer issueIndexer;
@@ -71,8 +72,8 @@ public class IssueIndexDebtTest {
@Before
public void setUp() {
- issueIndexer = new IssueIndexer(null, tester.client());
- viewIndexer = new ViewIndexer(null, tester.client());
+ issueIndexer = new IssueIndexer(system2, null, tester.client());
+ viewIndexer = new ViewIndexer(system2, null, tester.client());
System2 system = mock(System2.class);
when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("+01:00"));
when(system.now()).thenReturn(System.currentTimeMillis());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
index cc94a4d7901..8c24d9f92f4 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
@@ -68,6 +68,8 @@ import static org.sonar.api.utils.DateUtils.parseDateTime;
public class IssueIndexTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester tester = new EsTester(new IssueIndexDefinition(new MapSettings()), new ViewIndexDefinition(new MapSettings()));
@@ -84,8 +86,8 @@ public class IssueIndexTest {
@Before
public void setUp() {
- issueIndexer = new IssueIndexer(null, tester.client());
- viewIndexer = new ViewIndexer(null, tester.client());
+ issueIndexer = new IssueIndexer(system2, null, tester.client());
+ viewIndexer = new ViewIndexer(system2, null, tester.client());
System2 system = mock(System2.class);
when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("GMT-1:00"));
when(system.now()).thenReturn(System.currentTimeMillis());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
index be6d55fe3c8..ed8b1356f0c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
@@ -44,11 +44,13 @@ public class IssueIndexerTest {
private static final String A_PROJECT_UUID = "P1";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()));
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Test
public void index_nothing() {
@@ -156,7 +158,7 @@ public class IssueIndexerTest {
}
private IssueIndexer createIndexer() {
- return new IssueIndexer(new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
+ return new IssueIndexer(system2, new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
}
private void addIssue(String projectUuid, String issueKey) throws Exception {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
index 65fc6fc7fd5..16d1218414c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
@@ -70,8 +70,10 @@ public class BulkDeleteActionTest {
private static final String ACTION = "bulk_delete";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings()),
@@ -83,10 +85,10 @@ public class BulkDeleteActionTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- WsTester ws;
- DbClient dbClient = db.getDbClient();
+ private WsTester ws;
+ private DbClient dbClient = db.getDbClient();
final DbSession dbSession = db.getSession();
- ResourceType resourceType;
+ private ResourceType resourceType;
@Before
public void setUp() {
@@ -97,9 +99,9 @@ public class BulkDeleteActionTest {
ws = new WsTester(new ProjectsWs(
new BulkDeleteAction(
new ComponentCleanerService(dbClient,
- new IssueIndexer(dbClient, es.client()),
- new TestIndexer(dbClient, es.client()),
- new ProjectMeasuresIndexer(dbClient, es.client()),
+ new IssueIndexer(system2, dbClient, es.client()),
+ new TestIndexer(system2, dbClient, es.client()),
+ new ProjectMeasuresIndexer(system2, dbClient, es.client()),
mockResourceTypes,
new ComponentFinder(dbClient)),
dbClient,
diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
index bed24ac4e3a..dc3d17de695 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
@@ -67,8 +67,10 @@ public class DeleteActionTest {
private static final String ACTION = "delete";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester es = new EsTester(
@@ -81,13 +83,10 @@ public class DeleteActionTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- WsTester ws;
-
- DbClient dbClient = db.getDbClient();
-
- final DbSession dbSession = db.getSession();
-
- ResourceType resourceType;
+ private WsTester ws;
+ private DbClient dbClient = db.getDbClient();
+ private final DbSession dbSession = db.getSession();
+ private ResourceType resourceType;
@Before
public void setUp() {
@@ -99,9 +98,9 @@ public class DeleteActionTest {
new DeleteAction(
new ComponentCleanerService(
dbClient,
- new IssueIndexer(dbClient, es.client()),
- new TestIndexer(dbClient, es.client()),
- new ProjectMeasuresIndexer(dbClient, es.client()),
+ new IssueIndexer(system2, dbClient, es.client()),
+ new TestIndexer(system2, dbClient, es.client()),
+ new ProjectMeasuresIndexer(system2, dbClient, es.client()),
mockResourceTypes,
new ComponentFinder(dbClient)),
new ComponentFinder(dbClient),
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexTest.java
index 520130d4013..b0fa3fe7752 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexTest.java
@@ -29,6 +29,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.MapSettings;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.System2;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsTester;
@@ -57,6 +58,8 @@ public class ActiveRuleIndexTest {
private static final String QUALITY_PROFILE_KEY1 = "qp1";
private static final String QUALITY_PROFILE_KEY2 = "qp2";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester tester = new EsTester(new RuleIndexDefinition(new MapSettings()));
@@ -66,8 +69,8 @@ public class ActiveRuleIndexTest {
@Before
public void setUp() {
- activeRuleIndexer = new ActiveRuleIndexer(null, tester.client());
- ruleIndexer = new RuleIndexer(null, tester.client());
+ activeRuleIndexer = new ActiveRuleIndexer(system2, null, tester.client());
+ ruleIndexer = new RuleIndexer(system2, null, tester.client());
index = new ActiveRuleIndex(tester.client());
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
index 611bf999d87..ba38647e968 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
@@ -48,12 +48,13 @@ import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_ACTIVE_RULE;
public class ActiveRuleIndexerTest {
- static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
- static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
- static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
+ private static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
+ private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
+ private static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
+ private static final String QUALITY_PROFILE_KEY1 = "qp1";
+ private static final String QUALITY_PROFILE_KEY2 = "qp2";
- static final String QUALITY_PROFILE_KEY1 = "qp1";
- static final String QUALITY_PROFILE_KEY2 = "qp2";
+ private System2 system2 = System2.INSTANCE;
@Rule
public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
@@ -61,7 +62,7 @@ public class ActiveRuleIndexerTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- private ActiveRuleIndexer indexer = new ActiveRuleIndexer(dbTester.getDbClient(), esTester.client());
+ private ActiveRuleIndexer indexer = new ActiveRuleIndexer(system2, dbTester.getDbClient(), esTester.client());
@Test
public void index_nothing() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
index ffab7f58616..8cb9f4f1d63 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
@@ -55,8 +55,10 @@ public class AddProjectActionTest {
static final String LANGUAGE_1 = "xoo";
static final String LANGUAGE_2 = "foo";
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
@@ -77,7 +79,7 @@ public class AddProjectActionTest {
WsActionTester ws = new WsActionTester(new AddProjectAction(projectAssociationParameters,
qProfileProjectOperations, new ProjectAssociationFinder(new QProfileLookup(dbClient),
- new ComponentService(dbClient, null, userSession, null, new ComponentFinder(dbClient), new ProjectMeasuresIndexer(dbClient, es.client()))),
+ new ComponentService(dbClient, null, userSession, null, new ComponentFinder(dbClient), new ProjectMeasuresIndexer(system2, dbClient, es.client()))),
userSession));
@Before
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
index ae22a92b04c..f566c107edd 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
@@ -69,15 +69,15 @@ import static org.sonarqube.ws.QualityProfiles.CreateWsResponse.parseFrom;
public class CreateActionTest {
- static final String XOO_LANGUAGE = "xoo";
-
- static final RuleDto RULE = RuleTesting.newXooX1().setSeverity("MINOR").setLanguage(XOO_LANGUAGE);
+ private static final String XOO_LANGUAGE = "xoo";
+ private static final RuleDto RULE = RuleTesting.newXooX1().setSeverity("MINOR").setLanguage(XOO_LANGUAGE);
+ private System2 system2 = System2.INSTANCE;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
@@ -89,10 +89,10 @@ public class CreateActionTest {
DbSession dbSession = dbTester.getSession();
RuleIndex ruleIndex = new RuleIndex(esTester.client());
- RuleIndexer ruleIndexer = new RuleIndexer(dbClient, esTester.client());
+ RuleIndexer ruleIndexer = new RuleIndexer(system2, dbClient, esTester.client());
ActiveRuleIndex activeRuleIndex = new ActiveRuleIndex(esTester.client());
- ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(dbClient, esTester.client());
+ ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(system2, dbClient, esTester.client());
ProfileImporter[] profileImporters = createImporters();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
index f1236bd115d..e4ee1a7d374 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
@@ -66,7 +66,7 @@ public class RegisterRulesTest {
private static final RuleKey RULE_KEY2 = RuleKey.of("fake", "rule2");
private static final RuleKey RULE_KEY3 = RuleKey.of("fake", "rule3");
- private System2 system = mock(System2.class);;
+ private System2 system = mock(System2.class);
@org.junit.Rule
public DbTester dbTester = DbTester.create(system);
@@ -83,9 +83,9 @@ public class RegisterRulesTest {
@Before
public void before() {
when(system.now()).thenReturn(DATE1.getTime());
- ruleIndexer = new RuleIndexer(dbClient, esTester.client());
+ ruleIndexer = new RuleIndexer(system, dbClient, esTester.client());
ruleIndex = new RuleIndex(esTester.client());
- activeRuleIndexer = new ActiveRuleIndexer(dbClient, esTester.client());
+ activeRuleIndexer = new ActiveRuleIndexer(system, dbClient, esTester.client());
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
index 6dac4f86493..4d44e20c9e8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
@@ -32,6 +32,7 @@ import org.sonar.api.config.MapSettings;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rules.RuleType;
+import org.sonar.api.utils.System2;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsTester;
@@ -67,25 +68,26 @@ import static org.sonar.server.rule.index.RuleIndexDefinition.TYPE_ACTIVE_RULE;
public class RuleIndexTest {
- static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
- static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
- static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
- static final RuleKey RULE_KEY_4 = RuleKey.of("xoo", "x4");
+ private static final RuleKey RULE_KEY_1 = RuleTesting.XOO_X1;
+ private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
+ private static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
+ private static final RuleKey RULE_KEY_4 = RuleKey.of("xoo", "x4");
+ private static final String QUALITY_PROFILE_KEY1 = "qp1";
+ private static final String QUALITY_PROFILE_KEY2 = "qp2";
- static final String QUALITY_PROFILE_KEY1 = "qp1";
- static final String QUALITY_PROFILE_KEY2 = "qp2";
+ private System2 system2 = System2.INSTANCE;
@Rule
public EsTester tester = new EsTester(new RuleIndexDefinition(new MapSettings()));
- RuleIndex index;
- RuleIndexer ruleIndexer;
- ActiveRuleIndexer activeRuleIndexer;
+ private RuleIndex index;
+ private RuleIndexer ruleIndexer;
+ private ActiveRuleIndexer activeRuleIndexer;
@Before
public void setUp() {
- ruleIndexer = new RuleIndexer(null, tester.client());
- activeRuleIndexer = new ActiveRuleIndexer(null, tester.client());
+ ruleIndexer = new RuleIndexer(system2, null, tester.client());
+ activeRuleIndexer = new ActiveRuleIndexer(system2, null, tester.client());
index = new RuleIndex(tester.client());
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
index a4beda7ad8f..636563bdc48 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
@@ -36,20 +36,19 @@ import org.sonar.server.es.EsTester;
import static com.google.common.collect.Sets.newHashSet;
import static org.assertj.core.api.Assertions.assertThat;
-
public class RuleIndexerTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester esTester = new EsTester(new RuleIndexDefinition(new MapSettings()));
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
- DbClient dbClient = dbTester.getDbClient();
-
- DbSession dbSession = dbTester.getSession();
+ public DbTester dbTester = DbTester.create(system2);
- RuleDto rule = new RuleDto()
+ private DbClient dbClient = dbTester.getDbClient();
+ private DbSession dbSession = dbTester.getSession();
+ private RuleDto rule = new RuleDto()
.setRuleKey("S001")
.setRepositoryKey("xoo")
.setConfigKey("S1")
@@ -103,7 +102,7 @@ public class RuleIndexerTest {
}
private RuleIndexer createIndexer() {
- return new RuleIndexer(dbTester.getDbClient(), esTester.client());
+ return new RuleIndexer(system2, dbTester.getDbClient(), esTester.client());
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java
index 64531b1483c..32c6d3a46f0 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java
@@ -48,7 +48,7 @@ public class ClearRulesOverloadedDebtTest {
private static final RuleKey RULE_KEY_2 = RuleTesting.XOO_X2;
private static final RuleKey RULE_KEY_3 = RuleTesting.XOO_X3;
- System2 system2 = mock(System2.class);
+ private System2 system2 = mock(System2.class);
@Rule
public DbTester tester = DbTester.create(system2);
@@ -59,12 +59,12 @@ public class ClearRulesOverloadedDebtTest {
@Rule
public LogTester logTester = new LogTester();
- DbClient dbClient = tester.getDbClient();
- DbSession dbSession = tester.getSession();
- RuleDao ruleDao = new RuleDao();
- RuleIndexer ruleIndexer = new RuleIndexer(dbClient, esTester.client());
+ private DbClient dbClient = tester.getDbClient();
+ private DbSession dbSession = tester.getSession();
+ private RuleDao ruleDao = new RuleDao();
+ private RuleIndexer ruleIndexer = new RuleIndexer(system2, dbClient, esTester.client());
- ClearRulesOverloadedDebt underTest = new ClearRulesOverloadedDebt(system2, dbClient, ruleIndexer);
+ private ClearRulesOverloadedDebt underTest = new ClearRulesOverloadedDebt(system2, dbClient, ruleIndexer);
@Test
public void remove_overridden_debt() throws Exception {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
index 08289f2964d..622471ecf5c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
@@ -57,13 +57,15 @@ import static org.sonar.server.test.index.TestIndexDefinition.TYPE;
public class TestIndexerTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings()));
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
- private TestIndexer underTest = new TestIndexer(db.getDbClient(), es.client());
+ private TestIndexer underTest = new TestIndexer(system2, db.getDbClient(), es.client());
@Test
public void index_tests() throws Exception {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
index a6e8e01259e..8c18a0b9af3 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
@@ -88,7 +88,7 @@ public class UserUpdaterTest {
@Before
public void setUp() {
- userIndexer = new UserIndexer(dbClient, es.client());
+ userIndexer = new UserIndexer(system2, dbClient, es.client());
DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
underTest = new UserUpdater(newUserNotifier, settings, dbClient,
userIndexer, system2, defaultOrganizationProvider);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java
index 79bf8a06162..f229e8e295f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java
@@ -32,8 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
public class UserIndexerTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings()));
@@ -65,6 +67,6 @@ public class UserIndexerTest {
}
private UserIndexer createIndexer() {
- return new UserIndexer(new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
+ return new UserIndexer(system2, new DbClient(dbTester.database(), dbTester.myBatis()), esTester.client());
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java
index 4327d235e60..065e5ba001e 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java
@@ -57,10 +57,11 @@ import static org.mockito.Mockito.when;
public class ChangePasswordActionTest {
+ private System2 system2 = System2.INSTANCE;
private Settings settings = new MapSettings();
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
@@ -86,7 +87,7 @@ public class ChangePasswordActionTest {
groupDao.insert(session, GroupTesting.newGroupDto().setName("sonar-users"));
session.commit();
- UserIndexer userIndexer = new UserIndexer(dbClient, esTester.client());
+ UserIndexer userIndexer = new UserIndexer(system2, dbClient, esTester.client());
userUpdater = new UserUpdater(mock(NewUserNotifier.class), settings, dbClient, userIndexer, system2, defaultOrganizationProvider);
tester = new WsTester(new UsersWs(new ChangePasswordAction(userUpdater, userSessionRule)));
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
index 3143115bb4e..35dd5e673ce 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
@@ -58,9 +58,10 @@ public class CreateActionTest {
private static final String DEFAULT_GROUP_NAME = "sonar-users";
private Settings settings = new MapSettings().setProperty("sonar.defaultGroup", DEFAULT_GROUP_NAME);
+ private System2 system2 = new AlwaysIncreasingSystem2();
@Rule
- public DbTester db = DbTester.create(new AlwaysIncreasingSystem2());
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
@Rule
@@ -76,9 +77,8 @@ public class CreateActionTest {
@Before
public void setUp() {
- System2 system2 = new System2();
defaultGroupInDefaultOrg = db.users().insertGroup(db.getDefaultOrganization(), DEFAULT_GROUP_NAME);
- userIndexer = new UserIndexer(db.getDbClient(), esTester.client());
+ userIndexer = new UserIndexer(system2, db.getDbClient(), esTester.client());
index = new UserIndex(esTester.client());
DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
tester = new WsTester(new UsersWs(new CreateAction(db.getDbClient(),
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
index edc21892003..304a38bd1f6 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
@@ -55,10 +55,11 @@ import static org.sonar.db.user.UserTokenTesting.newUserToken;
public class DeactivateActionTest {
+ private System2 system2 = System2.INSTANCE;
private Settings settings = new MapSettings();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
@@ -74,13 +75,12 @@ public class DeactivateActionTest {
@Before
public void setUp() {
- System2 system2 = new System2();
UserDao userDao = new UserDao(db.myBatis(), system2);
dbClient = new DbClient(db.database(), db.myBatis(), userDao, new GroupMembershipDao(), new UserTokenDao());
dbSession = db.getSession();
dbSession.commit();
- userIndexer = new UserIndexer(dbClient, esTester.client());
+ userIndexer = new UserIndexer(system2, dbClient, esTester.client());
index = new UserIndex(esTester.client());
DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
ws = new WsTester(new UsersWs(new DeactivateAction(
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
index 28529be7f66..ae4d0681bc7 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
@@ -53,6 +53,8 @@ import static org.sonar.test.JsonAssert.assertJson;
public class SearchActionTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(new MapSettings()));
@@ -60,12 +62,12 @@ public class SearchActionTest {
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(system2);
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();
private UserIndex index = new UserIndex(esTester.client());
- private UserIndexer userIndexer = new UserIndexer(dbClient, esTester.client());
+ private UserIndexer userIndexer = new UserIndexer(system2, dbClient, esTester.client());
private WsTester ws = new WsTester(new UsersWs(new SearchAction(index, dbClient, new UserJsonWriter(userSession))));
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
index 5f06a025150..f375c0de446 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
@@ -73,7 +73,7 @@ public class UpdateActionTest {
dbClient.groupDao().insert(session, newGroupDto().setName("sonar-users"));
session.commit();
- userIndexer = new UserIndexer(dbClient, esTester.client());
+ userIndexer = new UserIndexer(system2, dbClient, esTester.client());
tester = new WsTester(new UsersWs(new UpdateAction(
new UserUpdater(mock(NewUserNotifier.class), settings, dbClient, userIndexer, system2, defaultOrganizationProvider), userSessionRule,
new UserJsonWriter(userSessionRule), dbClient)));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
index cb1d153ebcc..0124acb3b7c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.view.index;
-import com.google.common.base.Function;
import com.google.common.collect.Maps;
import java.util.List;
import java.util.Map;
@@ -53,8 +52,10 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ViewIndexerTest {
+ private System2 system2 = System2.INSTANCE;
+
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(system2);
@Rule
public EsTester esTester = new EsTester(new IssueIndexDefinition(new MapSettings()), new ViewIndexDefinition(new MapSettings()));
@@ -64,7 +65,7 @@ public class ViewIndexerTest {
private DbClient dbClient = dbTester.getDbClient();
private DbSession dbSession = dbTester.getSession();
- private ViewIndexer indexer = (ViewIndexer) new ViewIndexer(dbClient, esTester.client());
+ private ViewIndexer indexer = (ViewIndexer) new ViewIndexer(system2, dbClient, esTester.client());
@Test
public void index_nothing() {
@@ -81,12 +82,7 @@ public class ViewIndexerTest {
List<ViewDoc> docs = esTester.getDocuments("views", "view", ViewDoc.class);
assertThat(docs).hasSize(4);
- Map<String, ViewDoc> viewsByUuid = Maps.uniqueIndex(docs, new Function<ViewDoc, String>() {
- @Override
- public String apply(ViewDoc doc) {
- return doc.uuid();
- }
- });
+ Map<String, ViewDoc> viewsByUuid = Maps.uniqueIndex(docs, ViewDoc::uuid);
assertThat(viewsByUuid.get("ABCD").projects()).containsOnly("JKLM");
assertThat(viewsByUuid.get("EFGH").projects()).containsOnly("KLMN", "JKLM");
@@ -116,12 +112,7 @@ public class ViewIndexerTest {
List<ViewDoc> docs = esTester.getDocuments("views", "view", ViewDoc.class);
assertThat(docs).hasSize(2);
- Map<String, ViewDoc> viewsByUuid = Maps.uniqueIndex(docs, new Function<ViewDoc, String>() {
- @Override
- public String apply(ViewDoc doc) {
- return doc.uuid();
- }
- });
+ Map<String, ViewDoc> viewsByUuid = Maps.uniqueIndex(docs, ViewDoc::uuid);
assertThat(viewsByUuid.get("EFGH").projects()).containsOnly("KLMN", "JKLM");
assertThat(viewsByUuid.get("FGHI").projects()).containsOnly("JKLM");
@@ -142,7 +133,7 @@ public class ViewIndexerTest {
@Test
public void clear_views_lookup_cache_on_index_view_uuid() {
IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule);
- IssueIndexer issueIndexer = new IssueIndexer(dbClient, esTester.client());
+ IssueIndexer issueIndexer = new IssueIndexer(system2, dbClient, esTester.client());
PermissionIndexer permissionIndexer = new PermissionIndexer(dbClient, esTester.client());
String viewUuid = "ABCD";