]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6912 Use System2 in BaseIndexer
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 15 Nov 2016 09:42:49 +0000 (10:42 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 16 Nov 2016 12:59:29 +0000 (13:59 +0100)
in order to wrap call to System.currentTimeMillis().
That is needed to bypass the condition
"if (requestedAt > lastUpdatedAt)" in tests.

38 files changed:
server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresIndexer.java
server/sonar-server/src/main/java/org/sonar/server/es/BaseIndexer.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndexer.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
server/sonar-server/src/main/java/org/sonar/server/test/index/TestIndexer.java
server/sonar-server/src/main/java/org/sonar/server/user/index/UserIndexer.java
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexer.java
server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentCleanerServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java
server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/component/es/ProjectMeasuresIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/BulkUpdateKeyActionTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/IndexTestsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexDebtTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/startup/ClearRulesOverloadedDebtTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/user/UserUpdaterTest.java
server/sonar-server/src/test/java/org/sonar/server/user/index/UserIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/ChangePasswordActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java

index a7b32d9cccf7895151ac095346269a62f8d7d73b..15d44c7d64a172ee595f0e77f2b7f51725a481a7 100644 (file)
@@ -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;
   }
 
index 629f08cbe931147fe9001f3ee904e2bf8cef0f63..94fcec7bafaf9d05946a508f008af34c52193ba7 100644 (file)
@@ -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);
index b91af14dc7430a2eaba6c985f16786f55d0276f2..7cf8322d315a4edad7528535a08877bc699e34a3 100644 (file)
@@ -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;
   }
 
index 29d1f9a5901e0fffc28930a428179886b0433549..24af390ae53df349908317e55b3a333198a997d2 100644 (file)
@@ -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;
   }
 
index e8689201e07a067058ac2863e1d47b5d9455a83e..1a88a0eeeec9346ef5a1358d2a27a2688d0ae399 100644 (file)
@@ -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;
   }
 
index 2b20ffdac67ee8c8a12659455aad7ed1b119d0ff..6ac3d86d8f21684076ff6090ab1d473ef2cc1d4c 100644 (file)
  */
 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;
   }
 
index cdb8a3b78eeb692857252597a777f56486735857..970b9a8a3216395a133bdff554717ca5af6c8e8c 100644 (file)
@@ -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;
   }
 
index aaf546137e23885e908464e034d444aa9c28160a..d825e79fb2710e05f925e301d17cd31519a64058 100644 (file)
@@ -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;
   }
 
index 9e0ef04b2421e215756a4976892887ebf6e21dc9..01f12089f7906e7a7f7a89ca40ccf7b0716a0592 100644 (file)
@@ -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));
index 3a1a7d2f35cd6258e99ecaccfa806625dc66032c..e43ef097329cec3b852198ad72342c22d0700811 100644 (file)
@@ -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
index 9e38c293e7233fdf64cb6ecd4c656d38734d7ada..0c94ab9fdedf0ce8b95366c9aed8726c27002fc8 100644 (file)
@@ -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
index 1b8b843e24ddcc7c3d5cc1ca17bfe4cb2dad3f35..1fe3e9dbee1d064ca98544ba38b4b9eb5c4d84d2 100644 (file)
@@ -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
index 3b7adea5518112eca0de96453bf05a8c83d47563..2955d6d959b8013bd8d2595006116e3714325b42 100644 (file)
@@ -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);
 
index 0ee1c4935df9f7a2ed64b33c98a1e830c3f3338c..26ebdbc96b55f731d4d712c24aebc5a38d765ab0 100644 (file)
@@ -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() {
index dc3e49866b0526f611e43a3787b96715870afca7..bd7441442ed167e9da19a9fb72c9c623e22b4564 100644 (file)
@@ -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() {
index fcfb197ab149350a078dc2e08385b0c0a911d0dc..c16a1a506ba7e946eafda896e3ccabee1f6a44ae 100644 (file)
@@ -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);
   }
 
index 39fe0c470dda5e3d1e67165f06fbab80ad895f1b..672242c1ed1cff5d4915e3457f482d72e2335164 100644 (file)
@@ -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());
index cc94a4d7901b914c815afd208dc740a35d1f9455..8c24d9f92f45e8e8a017147462f8ce0ced442bc0 100644 (file)
@@ -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());
index be6d55fe3c888f050261a753d50099ec0c3ceb9f..ed8b1356f0cb4482aecaea6f3ab05118437582f6 100644 (file)
@@ -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 {
index 65fc6fc7fd54ba9bc3eebaf242b31001d4d873c4..16d1218414c360677862a3bcda07bb2f51c71c72 100644 (file)
@@ -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,
index bed24ac4e3a611f5271151fe475ebf7e40d34683..dc3d17de695d48a8ed0ab7001cd90e8d495ff3d8 100644 (file)
@@ -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),
index 520130d4013b9d32df597772cf69982aa40b66c3..b0fa3fe77525e1d7031902b392dac012986e1616 100644 (file)
@@ -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());
   }
 
index 611bf999d87795735577ea1f3bc0776381f2eff2..ba38647e968659f9201bba908a5ea259a9c94d22 100644 (file)
@@ -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() {
index ffab7f58616a974e116b387e115e8efec9cfe8c2..8cb9f4f1d6319892fd8e0ac8110ec67c5792b120 100644 (file)
@@ -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
index ae22a92b04cc9aef0f66d8fa72837246da824559..f566c107edde1ef2965f893cf3f0d47b9dc61fb9 100644 (file)
@@ -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();
 
index f1236bd115df3b704cad49a567ad04f336f98a8a..e4ee1a7d374f209485d24eb42ae468fc9bc5bead 100644 (file)
@@ -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
index 6dac4f8649354db5ad550b387fdc2283859bc91c..4d44e20c9e8588f792090b95cf568c4c33fdf4e6 100644 (file)
@@ -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());
   }
 
index a4beda7ad8f53cd67ceb41a0edd859f55037bc9d..636563bdc484a24be80ca8267d0125d0cff796d6 100644 (file)
@@ -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());
   }
 
 }
index 64531b1483ce5c85c01cb6b73aae8febc563689f..32c6d3a46f0f2a53640f3486b52c56e135b1f596 100644 (file)
@@ -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 {
index 08289f2964de23abb4bdbc0720e3ea34ef2ec419..622471ecf5cc8d6a334e80866ea7a8eb82ac7b6e 100644 (file)
@@ -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 {
index a6e8e01259eb6146cb694a4a67d4371311246e0d..8c18a0b9af354209421976622e5763a656e3b6ca 100644 (file)
@@ -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);
index 79bf8a06162b5815cf127cc7f02387cfe49d946f..f229e8e295fd0314b16c96a34d7ac757e34ace14 100644 (file)
@@ -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());
   }
 }
index 4327d235e60062e08396a5b7530ec214c7f72dbb..065e5ba001ea687f97e465c1efd322f1b699e953 100644 (file)
@@ -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)));
   }
index 3143115bb4e4545e59bccbe4ea77337bb61eec6d..35dd5e673ce6e1d12d2b206af14440097b22b257 100644 (file)
@@ -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(),
index edc218920035ae57e8f9827b3508e7c3e937fe20..304a38bd1f6b48a46b04df76f1fd61056e803efe 100644 (file)
@@ -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(
index 28529be7f66072cdd3395a1a40ffcb5958bcb318..ae4d0681bc773f42409fc771799312b02037fca6 100644 (file)
@@ -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
index 5f06a02515024cc8015cbb57eb33ec4f6189946f..f375c0de446f3d0b29c8bf1e15862cc0ae55e011 100644 (file)
@@ -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)));
index cb1d153ebccf0cfe78093e71d9ff9298c20fb6a5..0124acb3b7cd9a390e43ccfb8ffebdab9f64c661 100644 (file)
@@ -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";