]> source.dussan.org Git - sonarqube.git/commitdiff
Speed up unit tests by improving indexing in unit tests
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 27 Nov 2020 02:34:42 +0000 (20:34 -0600)
committersonartech <sonartech@sonarsource.com>
Mon, 30 Nov 2020 20:07:06 +0000 (20:07 +0000)
* Unit tests no longer use the LargeSizeHandler for indexing. This handler is designed for indexing large amounts of data and is slower for the data sets used in unit tests.
* Insert all data in DB before indexing in unit tests (there is a huge overhead in each call to index)

37 files changed:
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/ScmAccountToUserLoaderTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/TestDbImpl.java
server/sonar-server-common/src/main/java/org/sonar/server/component/index/ComponentIndexer.java
server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIndexer.java
server/sonar-server-common/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndexer.java
server/sonar-server-common/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java
server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserIndexer.java
server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewIndexer.java
server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java
server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java
server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java
server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java
server/sonar-server-common/src/test/java/org/sonar/server/user/index/UserIndexerTest.java
server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDataLoaderImplTest.java
server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexer.java
server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexSearchTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionFacetsTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SearchActionTest.java

index 0783f3eaae907771ebc2417e2bd705eb5c585e24..91477dfed9561a2e89905cb524dc4c1457dba393 100644 (file)
@@ -51,7 +51,7 @@ public class ScmAccountToUserLoaderTest {
   @Test
   public void load_login_for_scm_account() {
     UserDto user = db.users().insertUser(u -> u.setScmAccounts(asList("charlie", "jesuis@charlie.com")));
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     UserIndex index = new UserIndex(es.client(), System2.INSTANCE);
     ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index);
@@ -64,7 +64,7 @@ public class ScmAccountToUserLoaderTest {
   public void warn_if_multiple_users_share_the_same_scm_account() {
     db.users().insertUser(u -> u.setLogin("charlie").setScmAccounts(asList("charlie", "jesuis@charlie.com")));
     db.users().insertUser(u -> u.setLogin("another.charlie").setScmAccounts(asList("charlie")));
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     UserIndex index = new UserIndex(es.client(), System2.INSTANCE);
     ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index);
index 1f7f2e082aeef5be04e95ff8cc7c034357c31f1f..b5b2a2cfd96ba39a874b3ca4a15121944fed62b9 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.function.BiConsumer;
 import java.util.function.Consumer;
 import java.util.function.Function;
@@ -38,7 +39,7 @@ import org.sonar.process.logging.LogbackHelper;
 class TestDbImpl extends CoreTestDb {
   private static TestDbImpl defaultSchemaBaseTestDb;
   // instantiating MyBatis objects is costly => we cache them for default schema
-  private static final Map<List<String>, TestDbImpl> defaultSchemaTestDbsWithExtensions = new HashMap<>();
+  private static final Map<Set<String>, TestDbImpl> defaultSchemaTestDbsWithExtensions = new HashMap<>();
 
   private boolean isDefault;
   private MyBatis myBatis;
@@ -94,11 +95,10 @@ class TestDbImpl extends CoreTestDb {
         defaultSchemaBaseTestDb = new TestDbImpl(null);
       }
       if (confExtensions.length > 0) {
-        List<String> key = Arrays.stream(confExtensions)
+        Set<String> key = Arrays.stream(confExtensions)
           .flatMap(MyBatisConfExtension::getMapperClasses)
           .map(Class::getName)
-          .sorted()
-          .collect(Collectors.toList());
+          .collect(Collectors.toSet());
         return defaultSchemaTestDbsWithExtensions.computeIfAbsent(
           key,
           k -> new TestDbImpl(defaultSchemaBaseTestDb, newMyBatis(defaultSchemaBaseTestDb.getDatabase(), confExtensions)));
index a24c8e335bd93d8bd90ba812b4e134c610304957..4a0334b9a65fa9644d365e7f97d4f33c0f1c618d 100644 (file)
@@ -73,6 +73,10 @@ public class ComponentIndexer implements ProjectIndexer, NeedAuthorizationIndexe
     doIndexByProjectUuid(null, Size.LARGE);
   }
 
+  public void indexAll() {
+    doIndexByProjectUuid(null, Size.REGULAR);
+  }
+
   @Override
   public void indexOnAnalysis(String branchUuid) {
     doIndexByProjectUuid(branchUuid, Size.REGULAR);
index 69233bf3c1cf6ba7976d3a8a20f3cd6dc54dcddc..6f63c457cbdbdf30da1b4fef661391e4e54128af 100644 (file)
@@ -103,10 +103,9 @@ public class IssueIndexer implements ProjectIndexer, NeedAuthorizationIndexer {
     asyncIssueIndexing.triggerOnIndexCreation();
   }
 
-  @VisibleForTesting
   public void indexAllIssues() {
     try (IssueIterator issues = issueIteratorFactory.createForAll()) {
-      doIndex(issues, Size.LARGE, IndexingListener.FAIL_ON_ERROR);
+      doIndex(issues, Size.REGULAR, IndexingListener.FAIL_ON_ERROR);
     }
   }
 
@@ -249,7 +248,7 @@ public class IssueIndexer implements ProjectIndexer, NeedAuthorizationIndexer {
 
   @VisibleForTesting
   protected void index(Iterator<IssueDoc> issues) {
-    doIndex(issues, Size.LARGE, IndexingListener.FAIL_ON_ERROR);
+    doIndex(issues, Size.REGULAR, IndexingListener.FAIL_ON_ERROR);
   }
 
   private void doIndex(Iterator<IssueDoc> issues, Size size, IndexingListener listener) {
index ce3f21c47ab4d044e1c438a74ab16df2f79f8f89..8739a660286cb3b2eda07ea190ba985635c6aca4 100644 (file)
@@ -73,6 +73,10 @@ public class ProjectMeasuresIndexer implements ProjectIndexer, NeedAuthorization
     doIndex(Size.LARGE, null);
   }
 
+  public void indexAll() {
+    doIndex(Size.REGULAR, null);
+  }
+
   @Override
   public AuthorizationScope getAuthorizationScope() {
     return AUTHORIZATION_SCOPE;
index 02f9f2a1c922f4ca3246aabf8f6307ea9a522a83..1217ff6f2972522efa4e3aedbb2ae0fa10872a7b 100644 (file)
@@ -73,8 +73,16 @@ public class ActiveRuleIndexer implements ResilientIndexer {
 
   @Override
   public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) {
+    indexAll(Size.LARGE);
+  }
+
+  public void indexAll() {
+    indexAll(Size.REGULAR);
+  }
+
+  private void indexAll(Size bulkSize) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      BulkIndexer bulkIndexer = createBulkIndexer(Size.LARGE, IndexingListener.FAIL_ON_ERROR);
+      BulkIndexer bulkIndexer = createBulkIndexer(bulkSize, IndexingListener.FAIL_ON_ERROR);
       bulkIndexer.start();
       dbClient.activeRuleDao().scrollAllForIndexing(dbSession, ar -> bulkIndexer.add(newIndexRequest(ar)));
       bulkIndexer.stop();
index 4a02b3b95aba6878a824115828f703ad0323f0d5..7be18589c35656c16a884d777da3a013842f1687 100644 (file)
@@ -70,15 +70,20 @@ public class RuleIndexer implements ResilientIndexer {
 
   @Override
   public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) {
-    try (DbSession dbSession = dbClient.openSession(false)) {
-      BulkIndexer bulk = createBulkIndexer(Size.LARGE, IndexingListener.FAIL_ON_ERROR);
-      bulk.start();
+    if (uninitializedIndexTypes.contains(TYPE_RULE)) {
+      indexAll(Size.LARGE);
+    }
+  }
 
-      // index all definitions
-      if (uninitializedIndexTypes.contains(TYPE_RULE)) {
-        dbClient.ruleDao().scrollIndexingRules(dbSession, dto -> bulk.add(ruleDocOf(dto).toIndexRequest()));
-      }
+  public void indexAll() {
+    indexAll(Size.REGULAR);
+  }
 
+  private void indexAll(Size bulkSize) {
+    try (DbSession dbSession = dbClient.openSession(false)) {
+      BulkIndexer bulk = createBulkIndexer(bulkSize, IndexingListener.FAIL_ON_ERROR);
+      bulk.start();
+      dbClient.ruleDao().scrollIndexingRules(dbSession, dto -> bulk.add(ruleDocOf(dto).toIndexRequest()));
       bulk.stop();
     }
   }
index c37f2cb4bd393b5427165d338184cd1f520658db..054b9ccc3d91a6371366f21308b6fbc36f6adcc8 100644 (file)
@@ -63,11 +63,19 @@ public class UserIndexer implements ResilientIndexer {
 
   @Override
   public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) {
+    indexAll(Size.LARGE);
+  }
+
+  public void indexAll() {
+    indexAll(Size.REGULAR);
+  }
+
+  private void indexAll(Size bulkSize) {
     try (DbSession dbSession = dbClient.openSession(false)) {
       ListMultimap<String, String> organizationUuidsByUserUuid = ArrayListMultimap.create();
       dbClient.organizationMemberDao().selectAllForUserIndexing(dbSession, organizationUuidsByUserUuid::put);
 
-      BulkIndexer bulkIndexer = newBulkIndexer(Size.LARGE, IndexingListener.FAIL_ON_ERROR);
+      BulkIndexer bulkIndexer = newBulkIndexer(bulkSize, IndexingListener.FAIL_ON_ERROR);
       bulkIndexer.start();
       dbClient.userDao().scrollAll(dbSession,
         // only index requests, no deletion requests.
index 10b119153acdb072b6656eef9b4a2a4f196940a3..1470fad9f283cd37ca2b590fb2ff43bdaf44b121 100644 (file)
@@ -62,12 +62,20 @@ public class ViewIndexer implements ResilientIndexer {
 
   @Override
   public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) {
+    indexAll(Size.LARGE);
+  }
+
+  public void indexAll() {
+    indexAll(Size.REGULAR);
+  }
+
+  private void indexAll(Size bulkSize) {
     try (DbSession dbSession = dbClient.openSession(false)) {
       Map<String, String> viewAndProjectViewUuidMap = new HashMap<>();
       for (UuidWithProjectUuidDto uuidWithProjectUuidDto : dbClient.componentDao().selectAllViewsAndSubViews(dbSession)) {
         viewAndProjectViewUuidMap.put(uuidWithProjectUuidDto.getUuid(), uuidWithProjectUuidDto.getProjectUuid());
       }
-      index(dbSession, viewAndProjectViewUuidMap, false, Size.LARGE);
+      index(dbSession, viewAndProjectViewUuidMap, false, bulkSize);
     }
   }
 
index af3d714d8ce94476aa681d3e73fb449b8e090760..11fe9a7ac0e103516da5e43145801f6b88549874 100644 (file)
@@ -83,6 +83,16 @@ public class ComponentIndexerTest {
     assertThatIndexContainsOnly(project1, project2);
   }
 
+  @Test
+  public void indexOAll_indexes_all_components() {
+    ComponentDto project1 = db.components().insertPrivateProject();
+    ComponentDto project2 = db.components().insertPrivateProject();
+
+    underTest.indexAll();
+
+    assertThatIndexContainsOnly(project1, project2);
+  }
+
   @Test
   public void map_fields() {
     OrganizationDto organization = db.organizations().insert();
index d054d06760dc786fd12121722dbe9059055cea6f..f8a3dbe9dcb011c52859c1c6ed2b3d24b7c8bc9e 100644 (file)
@@ -109,6 +109,19 @@ public class ProjectMeasuresIndexerTest {
     assertThatQualifierIs("TRK", project1, project2, project3);
   }
 
+  @Test
+  public void indexAll_indexes_all_projects() {
+    OrganizationDto organization = db.organizations().insert();
+    SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization));
+    SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization));
+    SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization));
+
+    underTest.indexAll();
+
+    assertThatIndexContainsOnly(project1, project2, project3);
+    assertThatQualifierIs("TRK", project1, project2, project3);
+  }
+
   /**
    * Provisioned projects don't have analysis yet
    */
index a3e706a2308ba9ee99729fb285f27f6f81f67f7f..b159e414d40562f189716da3fe92be00b4660667 100644 (file)
@@ -89,6 +89,18 @@ public class ActiveRuleIndexerTest {
     assertThatEsQueueTableIsEmpty();
   }
 
+  @Test
+  public void indexAll_indexes_all_data() {
+    ActiveRuleDto activeRule = db.qualityProfiles().activateRule(profile1, rule1);
+
+    underTest.indexAll();
+
+    List<ActiveRuleDoc> docs = es.getDocuments(TYPE_ACTIVE_RULE, ActiveRuleDoc.class);
+    assertThat(docs).hasSize(1);
+    verify(docs.get(0), profile1, activeRule);
+    assertThatEsQueueTableIsEmpty();
+  }
+
   @Test
   public void test_commitAndIndex() {
     ActiveRuleDto ar1 = db.qualityProfiles().activateRule(profile1, rule1);
index b44c1e120e5f438b5842e8935ed26efdf5c14f55..58a0429d74858ec74f2717530da33d7f4d609c10 100644 (file)
@@ -29,8 +29,6 @@ import java.util.Set;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
 import javax.annotation.Nullable;
-import org.elasticsearch.action.search.SearchRequest;
-import org.elasticsearch.search.builder.SearchSourceBuilder;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -47,7 +45,6 @@ import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleDto.Scope;
 import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.es.EsClient;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.security.SecurityStandards;
 import org.sonar.server.security.SecurityStandards.SQCategory;
@@ -148,7 +145,6 @@ public class RuleIndexerTest {
       .setType(RuleType.SECURITY_HOTSPOT)
       .setSecurityStandards(standards)
       .setDescription(VALID_HOTSPOT_RULE_DESCRIPTION));
-    OrganizationDto organization = dbTester.organizations().insert();
     underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
 
     assertThat(logTester.getLogs()).hasSize(1);
@@ -184,7 +180,6 @@ public class RuleIndexerTest {
     RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRule()
       .setType(RuleType.SECURITY_HOTSPOT)
       .setDescription(description));
-    OrganizationDto organization = dbTester.organizations().insert();
     underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
 
     assertThat(logTester.getLogs()).hasSize(1);
@@ -207,7 +202,6 @@ public class RuleIndexerTest {
     RuleDefinitionDto rule = dbTester.rules().insert(RuleTesting.newRule()
       .setType(RuleType.SECURITY_HOTSPOT)
       .setDescription(randomAlphabetic(30)));
-    OrganizationDto organization = dbTester.organizations().insert();
     underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
 
     assertThat(logTester.getLogs()).hasSize(1);
@@ -224,7 +218,6 @@ public class RuleIndexerTest {
       .setDescription("bar\n" +
         "<h2>Ask Yourself Whether</h2>\n" +
         "foo"));
-    OrganizationDto organization = dbTester.organizations().insert();
     underTest.commitAndIndex(dbTester.getSession(), rule.getUuid());
 
     assertThat(logTester.getLogs()).hasSize(1);
index 00146988e9c4ca78206d5a58e32e99fbfd0f5f88..79c347017b4906f87b9931e18d2971fcfb4d6b1c 100644 (file)
@@ -72,6 +72,24 @@ public class UserIndexerTest {
     assertThat(doc.organizationUuids()).isEmpty();
   }
 
+  @Test
+  public void indexAll_adds_all_users_to_index() {
+    UserDto user = db.users().insertUser(u -> u.setScmAccounts(asList("user_1", "u1")));
+
+    underTest.indexAll();
+
+    List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
+    assertThat(docs).hasSize(1);
+    UserDoc doc = docs.get(0);
+    assertThat(doc.uuid()).isEqualTo(user.getUuid());
+    assertThat(doc.login()).isEqualTo(user.getLogin());
+    assertThat(doc.name()).isEqualTo(user.getName());
+    assertThat(doc.email()).isEqualTo(user.getEmail());
+    assertThat(doc.active()).isEqualTo(user.isActive());
+    assertThat(doc.scmAccounts()).isEqualTo(user.getScmAccountsAsList());
+    assertThat(doc.organizationUuids()).isEmpty();
+  }
+
   @Test
   public void indexOnStartup_adds_all_users_with_organizations() {
     OrganizationDto organization1 = db.organizations().insert();
index c5174244c67e131e2ba0499f575e3dc1ca841893..2c49c00ba214a2bae9df477f684c74a4d152bc7c 100644 (file)
@@ -166,6 +166,21 @@ public class ViewIndexerTest {
     assertThat(resultApp.projects()).containsExactlyInAnyOrder(project.uuid());
   }
 
+  @Test
+  public void index_application_with_indexAll() {
+    ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization());
+    ComponentDto project = db.components().insertPrivateProject();
+    db.components().insertComponent(newProjectCopy("PC1", project, application));
+
+    underTest.indexAll();
+    List<ViewDoc> result = es.getDocuments(TYPE_VIEW, ViewDoc.class);
+
+    assertThat(result).hasSize(1);
+    ViewDoc resultApp = result.get(0);
+    assertThat(resultApp.uuid()).isEqualTo(application.uuid());
+    assertThat(resultApp.projects()).containsExactlyInAnyOrder(project.uuid());
+  }
+
   @Test
   public void index_application_branch() {
     ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setDbKey("app"));
index f2d9e17033bc6f54d561e8bb4d80164ad0fb8315..b50f53ef7c6851ac44cd0d33b470a40ac93337b0 100644 (file)
@@ -84,7 +84,7 @@ public class UserUpdaterUpdateTest {
     UserDto user = db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@email.com")
       .setScmAccounts(asList("ma", "marius33")));
     createDefaultGroup();
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     underTest.updateAndCommit(session, user, new UpdateUser()
       .setName("Marius2")
@@ -216,7 +216,7 @@ public class UserUpdaterUpdateTest {
   public void update_index_when_updating_user_login() {
     UserDto oldUser = db.users().insertUser();
     createDefaultGroup();
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     underTest.updateAndCommit(session, oldUser, new UpdateUser()
       .setLogin("new_login"), u -> {
@@ -240,7 +240,7 @@ public class UserUpdaterUpdateTest {
       new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project1.uuid()),
       new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project2.uuid()),
       new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setComponentUuid(anotherProject.uuid()));
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     underTest.updateAndCommit(session, oldUser, new UpdateUser()
       .setLogin("new_login"), u -> {
index 6d62af2a617dd7b3c625f813de4ba0005f12f6aa..5e47becce65188c637f4a1287f4567a7f655c99f 100644 (file)
@@ -46,7 +46,6 @@ import org.sonar.server.user.index.UserIndexer;
 import org.sonar.updatecenter.common.Version;
 
 import static java.util.Arrays.asList;
-import static java.util.Collections.emptySet;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -99,7 +98,7 @@ public class TelemetryDataLoaderImplTest {
     int userCount = 3;
     IntStream.range(0, userCount).forEach(i -> db.users().insertUser());
     db.users().insertUser(u -> u.setActive(false));
-    userIndexer.indexOnStartup(emptySet());
+    userIndexer.indexAll();
 
     MetricDto lines = db.measures().insertMetric(m -> m.setKey(LINES_KEY));
     MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(NCLOC_KEY));
@@ -118,7 +117,7 @@ public class TelemetryDataLoaderImplTest {
     db.measures().insertLiveMeasure(project2, ncloc, m -> m.setValue(200d));
     db.measures().insertLiveMeasure(project2, coverage, m -> m.setValue(80d));
     db.measures().insertLiveMeasure(project2, nclocDistrib, m -> m.setValue(null).setData("java=300;kotlin=2500"));
-    projectMeasuresIndexer.indexOnStartup(emptySet());
+    projectMeasuresIndexer.indexAll();
 
     TelemetryData data = communityUnderTest.load();
     assertThat(data.getServerId()).isEqualTo(serverId);
@@ -157,7 +156,7 @@ public class TelemetryDataLoaderImplTest {
     db.measures().insertLiveMeasure(project, ncloc, m -> m.setValue(10d));
     db.measures().insertLiveMeasure(branch1, ncloc, m -> m.setValue(20d));
     db.measures().insertLiveMeasure(pr, ncloc, m -> m.setValue(30d));
-    projectMeasuresIndexer.indexOnStartup(emptySet());
+    projectMeasuresIndexer.indexAll();
 
     TelemetryData data = communityUnderTest.load();
 
index 80b1c7398d4bfa0430fd6b24b5bab9c7dceb2534..5292f13726c0a4c2b861fc91cf7cbd03d5f4f7ea 100644 (file)
@@ -84,6 +84,13 @@ public class PermissionIndexer implements ProjectIndexer {
     index(authorizations, scopes, Size.LARGE);
   }
 
+  public void indexAll(Set<IndexType> uninitializedIndexTypes) {
+    // TODO do not load everything in memory. Db rows should be scrolled.
+    List<IndexPermissions> authorizations = getAllAuthorizations();
+    Stream<AuthorizationScope> scopes = getScopes(uninitializedIndexTypes);
+    index(authorizations, scopes, Size.REGULAR);
+  }
+
   @VisibleForTesting
   void index(List<IndexPermissions> authorizations) {
     index(authorizations, authorizationScopes.stream(), Size.REGULAR);
index 4c65a14116da4fee8356e917714da66e1e5d878b..d7af68df6e379a9701fff0f50619815df076511d 100644 (file)
@@ -38,7 +38,6 @@ import org.sonar.server.permission.index.PermissionIndexerTester;
 import org.sonar.server.permission.index.WebAuthorizationTypeSupport;
 import org.sonar.server.tester.UserSessionRule;
 
-import static java.util.Collections.emptySet;
 import static java.util.Collections.singleton;
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -134,7 +133,7 @@ public class ComponentIndexSearchTest {
     ComponentDto unauthorizedProject = db.components().insertPrivateProject();
     ComponentDto project1 = db.components().insertPrivateProject();
     ComponentDto project2 = db.components().insertPrivateProject();
-    indexer.indexOnStartup(emptySet());
+    indexer.indexAll();
     authorizationIndexerTester.allowOnlyAnyone(project1);
     authorizationIndexerTester.allowOnlyAnyone(project2);
 
@@ -145,7 +144,7 @@ public class ComponentIndexSearchTest {
   }
 
   private void index(ComponentDto... components) {
-    indexer.indexOnStartup(emptySet());
+    indexer.indexAll();
     Arrays.stream(components).forEach(c -> authorizationIndexerTester.allowOnlyAnyone(c));
   }
 }
index 326a75ac709c7f08b2f5929d85f413f246f2d2a2..a975d00151761698ce4ae3cf0f29034d7ded3ba8 100644 (file)
@@ -76,6 +76,19 @@ public class PermissionIndexerTest {
     verifyAuthorized(project, user2);
   }
 
+  @Test
+  public void indexAll_grants_access_to_any_user_and_to_group_Anyone_on_public_projects() {
+    ComponentDto project = createAndIndexPublicProject();
+    UserDto user1 = db.users().insertUser();
+    UserDto user2 = db.users().insertUser();
+
+    underTest.indexAll(underTest.getIndexTypes());
+
+    verifyAnyoneAuthorized(project);
+    verifyAuthorized(project, user1);
+    verifyAuthorized(project, user2);
+  }
+
   @Test
   public void deletion_resilience_will_deindex_projects() {
     ComponentDto project1 = createUnindexedPublicProject();
index 4a1f693bd4635160b10d097349ca486e830b7387..b375cad9dd0c26e74cb47981032fa4e8ce7639b5 100644 (file)
@@ -53,7 +53,6 @@ import org.sonarqube.ws.Components.SearchWsResponse;
 import org.sonarqube.ws.MediaTypes;
 
 import static java.util.Arrays.asList;
-import static java.util.Collections.emptySet;
 import static java.util.Collections.singletonList;
 import static java.util.Optional.ofNullable;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -264,7 +263,7 @@ public class SearchActionTest {
   }
 
   private void index() {
-    indexer.indexOnStartup(emptySet());
+    indexer.indexAll();
   }
 
   private static Language[] javaLanguage() {
index db74e41a864bad34356518b8716dc65f38c9aa6f..230d59b20123e1f370cce9a2491201442cd68444 100644 (file)
@@ -25,8 +25,10 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner;
 import com.tngtech.java.junit.dataprovider.UseDataProvider;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 import java.util.function.Consumer;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
@@ -262,6 +264,7 @@ public class SearchProjectsActionTest {
       p -> p.setTagsString("sales, offshore, java"),
       new Measure(coverage, c -> c.setValue(20d)));
     addFavourite(project1);
+    index();
 
     String jsonResult = ws.newRequest()
       .setParam(FACETS, COVERAGE)
@@ -286,6 +289,7 @@ public class SearchProjectsActionTest {
     insertProject(organization, c -> c.setName("Maven"));
     insertProject(organization, c -> c.setName("Apache"));
     insertProject(organization, c -> c.setName("guava"));
+    index();
 
     SearchProjectsWsResponse result = call(request);
 
@@ -298,6 +302,7 @@ public class SearchProjectsActionTest {
     userSession.logIn();
     OrganizationDto organization = db.organizations().insert();
     IntStream.rangeClosed(1, 9).forEach(i -> insertProject(organization, c -> c.setName("PROJECT-" + i)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setPage(2).setPageSize(3));
 
@@ -338,6 +343,7 @@ public class SearchProjectsActionTest {
     ComponentDto project3 = insertProject(organizationDto,
       new Measure(coverage, c -> c.setValue(80d)),
       new Measure(ncloc, c -> c.setValue(10_001d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("coverage <= 80 and ncloc <= 10000"));
 
@@ -354,6 +360,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organization1, new Measure(coverage, c -> c.setValue(81d)), new Measure(ncloc, c -> c.setValue(10_000d)));
     ComponentDto project2 = insertProject(organization1, new Measure(coverage, c -> c.setValue(80d)), new Measure(ncloc, c -> c.setValue(10_000d)));
     ComponentDto project3 = insertProject(organization2, new Measure(coverage, c -> c.setValue(80d)), new Measure(ncloc, c -> c.setValue(10_000d)));
+    index();
 
     assertThat(call(request.setOrganization(null)).getComponentsList())
       .extracting(Component::getKey)
@@ -374,6 +381,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK")));
     ComponentDto project2 = insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK")));
     ComponentDto project3 = insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setValue(null).setData("ERROR")));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("alert_status = OK"));
 
@@ -391,6 +399,7 @@ public class SearchProjectsActionTest {
     ComponentDto project2 = insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("java=3;xoo=9")));
     ComponentDto project3 = insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("xoo=1")));
     ComponentDto project4 = insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=1;java=5;xoo=13")));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("languages IN (java, js, <null>)"));
 
@@ -406,6 +415,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(1d)));
     ComponentDto project2 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(2d)));
     ComponentDto project3 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(3d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter(metricKey + " = 2"));
 
@@ -421,6 +431,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(1d)));
     ComponentDto project2 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(2d)));
     insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(3d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter(newMetricKey + " = 2"));
 
@@ -434,6 +445,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organizationDto, defaults(), p -> p.setTags(asList("finance", "platform")));
     insertProject(organizationDto, defaults(), p -> p.setTags(singletonList("marketing")));
     ComponentDto project3 = insertProject(organizationDto, defaults(), p -> p.setTags(singletonList("offshore")));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("tags in (finance, offshore)"));
 
@@ -448,6 +460,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(80d)));
     ComponentDto project2 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(85d)));
     ComponentDto project3 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(10d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("coverage <= 80"));
 
@@ -462,6 +475,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(80d)));
     ComponentDto project2 = insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(85d)));
     ComponentDto project3 = insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(10d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("new_coverage <= 80"));
 
@@ -476,6 +490,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organizationDto, new Measure(duplications, c -> c.setValue(80d)));
     ComponentDto project2 = insertProject(organizationDto, new Measure(duplications, c -> c.setValue(85d)));
     ComponentDto project3 = insertProject(organizationDto, new Measure(duplications, c -> c.setValue(10d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("duplicated_lines_density <= 80"));
 
@@ -491,6 +506,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(10d)));
     ComponentDto project2 = insertProject(organizationDto, new Measure(duplications, c -> c.setValue(0d)));
     ComponentDto project3 = insertProject(organizationDto, new Measure(duplications, c -> c.setValue(79d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("duplicated_lines_density = NO_DATA"));
 
@@ -504,6 +520,7 @@ public class SearchProjectsActionTest {
     MetricDto coverage = db.measures().insertMetric(c -> c.setKey(COVERAGE).setValueType("PERCENT"));
     MetricDto duplications = db.measures().insertMetric(c -> c.setKey(DUPLICATED_LINES_DENSITY_KEY).setValueType("PERCENT"));
     insertProject(organizationDto, new Measure(duplications, c -> c.setValue(10d)), new Measure(coverage, c -> c.setValue(50d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("duplicated_lines_density = NO_DATA"));
 
@@ -518,6 +535,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organizationDto, new Measure(newDuplications, c -> c.setVariation(80d)));
     ComponentDto project2 = insertProject(organizationDto, new Measure(newDuplications, c -> c.setVariation(85d)));
     ComponentDto project3 = insertProject(organizationDto, new Measure(newDuplications, c -> c.setVariation(10d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("new_duplicated_lines_density <= 80"));
 
@@ -532,6 +550,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(80d)));
     ComponentDto project2 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(85d)));
     ComponentDto project3 = insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(10d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("ncloc <= 80"));
 
@@ -546,6 +565,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organizationDto, new Measure(newLines, c -> c.setVariation(80d)));
     ComponentDto project2 = insertProject(organizationDto, new Measure(newLines, c -> c.setVariation(85d)));
     ComponentDto project3 = insertProject(organizationDto, new Measure(newLines, c -> c.setVariation(10d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("new_lines <= 80"));
 
@@ -560,6 +580,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, c -> c.setDbKey("sonar-groovy").setName("Sonar Groovy"));
     insertProject(organizationDto, c -> c.setDbKey("sonar-markdown").setName("Sonar Markdown"));
     insertProject(organizationDto, c -> c.setDbKey("sonarqube").setName("Sonar Qube"));
+    index();
 
     assertThat(call(request.setFilter("query = \"Groovy\"")).getComponentsList()).extracting(Component::getName).containsOnly("Sonar Groovy");
     assertThat(call(request.setFilter("query = \"oNar\"")).getComponentsList()).extracting(Component::getName).containsOnly("Sonar Java", "Sonar Groovy", "Sonar Markdown",
@@ -582,7 +603,9 @@ public class SearchProjectsActionTest {
     ComponentDto nonFavourite2 = insertProject(organization2);
     ComponentDto favourite3 = insertProject(organization3);
     ComponentDto nonFavourite4 = insertProject(organization4);
+
     Stream.of(favourite1_1, favourite1_2, favourite2, favourite3).forEach(this::addFavourite);
+    index();
 
     assertThat(call(request.setFilter(null).setOrganization(null)).getComponentsList())
       .extracting(Component::getName)
@@ -621,6 +644,7 @@ public class SearchProjectsActionTest {
     ComponentDto markDownProject = insertProject(organization);
     ComponentDto sonarQubeProject = insertProject(organization);
     Stream.of(javaProject, markDownProject).forEach(this::addFavourite);
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("isFavorite"));
 
@@ -636,6 +660,7 @@ public class SearchProjectsActionTest {
     ComponentDto markDownProject = insertProject(organization);
     ComponentDto sonarQubeProject = insertProject(organization);
     Stream.of(javaProject, markDownProject).forEach(this::addFavourite);
+    index();
 
     addFavourite((String) null);
 
@@ -653,6 +678,7 @@ public class SearchProjectsActionTest {
     ComponentDto markDownProject = insertProject(organization);
     ComponentDto sonarQubeProject = insertProject(organization);
     Stream.of(javaProject, markDownProject).forEach(this::addFavourite);
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("isFavorite"));
 
@@ -675,6 +701,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organization);
     ComponentDto project2 = insertProject(organization);
     ComponentDto project3 = insertProject(organization);
+    index();
 
     SearchProjectsWsResponse result = call(request);
 
@@ -707,6 +734,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organization);
     ComponentDto project2 = insertProject(organization);
     ComponentDto project3 = insertProject(organization);
+    index();
 
     SearchProjectsWsResponse result = call(request);
 
@@ -729,6 +757,7 @@ public class SearchProjectsActionTest {
     insertProject(organization);
     insertProject(organization);
     insertProject(organization);
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("qualifier = APP"));
 
@@ -756,6 +785,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organization);
     ComponentDto project2 = insertProject(organization);
     ComponentDto project3 = insertProject(organization);
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("qualifier = TRK"));
 
@@ -774,7 +804,6 @@ public class SearchProjectsActionTest {
   public void fail_when_qualifier_filter_by_APP_set_when_ce_or_de(Edition edition) {
     when(editionProviderMock.get()).thenReturn(Optional.of(edition));
     userSession.logIn();
-    OrganizationDto organization = db.organizations().insert();
 
     assertThatThrownBy(() -> call(request.setFilter("qualifiers = APP")))
       .isInstanceOf(IllegalArgumentException.class);
@@ -785,7 +814,6 @@ public class SearchProjectsActionTest {
   public void fail_when_qualifier_filter_invalid_when_ee_or_dc(Edition edition) {
     when(editionProviderMock.get()).thenReturn(Optional.of(edition));
     userSession.logIn();
-    OrganizationDto organization = db.organizations().insert();
 
     assertThatThrownBy(() -> call(request.setFilter("qualifiers = BLA")))
       .isInstanceOf(IllegalArgumentException.class);
@@ -796,6 +824,7 @@ public class SearchProjectsActionTest {
     userSession.anonymous();
     OrganizationDto organization = db.organizations().insert();
     insertProject(organization);
+    index();
 
     SearchProjectsWsResponse result = call(request);
 
@@ -811,6 +840,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(5d)));
     insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(10_000d)));
     insertProject(organizationDto, new Measure(ncloc, c -> c.setValue(500_001d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(NCLOC)));
 
@@ -835,6 +865,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(100d)));
     insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(15_000d)));
     insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(50_000d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_LINES_KEY)));
 
@@ -860,6 +891,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("java=5;xoo=19")));
     insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("xoo=1")));
     insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=1;java=3;xoo=8")));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_LANGUAGES)));
 
@@ -881,6 +913,7 @@ public class SearchProjectsActionTest {
     MetricDto languagesDistribution = db.measures().insertMetric(c -> c.setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY).setValueType("DATA"));
     insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=2;java=6")));
     insertProject(organizationDto, new Measure(languagesDistribution, c -> c.setValue(null).setData("java=5")));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("languages = xoo").setFacets(singletonList(FILTER_LANGUAGES)));
 
@@ -902,6 +935,7 @@ public class SearchProjectsActionTest {
     insertProject(organization, defaults(), p -> p.setTags(asList("finance", "platform")));
     insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore")));
     insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore")));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_TAGS)));
 
@@ -923,6 +957,7 @@ public class SearchProjectsActionTest {
     insertProject(organization, defaults(), p -> p.setTags(asList("finance", "platform")));
     insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore")));
     insertProject(organization, defaults(), p -> p.setTags(singletonList("offshore")));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("tags = marketing").setFacets(singletonList(FILTER_TAGS)));
 
@@ -951,6 +986,7 @@ public class SearchProjectsActionTest {
     ComponentDto project1 = insertProject(organization);
     ComponentDto project2 = insertProject(organization);
     ComponentDto project3 = insertProject(organization);
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_QUALIFIER)));
 
@@ -973,6 +1009,7 @@ public class SearchProjectsActionTest {
     ComponentDto application2 = insertApplication(organization);
     ComponentDto application3 = insertApplication(organization);
     ComponentDto application4 = insertApplication(organization);
+    index();
 
     SearchProjectsWsResponse result = call(request.setFilter("qualifier = APP").setFacets(singletonList(FILTER_QUALIFIER)));
 
@@ -996,6 +1033,7 @@ public class SearchProjectsActionTest {
     insertProject(organization, new Measure(ratingMetric, c -> c.setValue(1d)));
     insertProject(organization, new Measure(ratingMetric, c -> c.setValue(3d)));
     insertProject(organization, new Measure(ratingMetric, c -> c.setValue(5d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(ratingMetricKey)));
 
@@ -1022,6 +1060,7 @@ public class SearchProjectsActionTest {
     insertProject(organization, new Measure(newRatingMetric, c -> c.setVariation(1d)));
     insertProject(organization, new Measure(newRatingMetric, c -> c.setVariation(3d)));
     insertProject(organization, new Measure(newRatingMetric, c -> c.setVariation(5d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(newRatingMetricKey)));
 
@@ -1047,6 +1086,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, new Measure(coverage, c -> c.setValue(80d)));
     insertProject(organizationDto, new Measure(coverage, c -> c.setValue(85d)));
     insertProject(organizationDto, new Measure(coverage, c -> c.setValue(10d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(COVERAGE)));
 
@@ -1073,6 +1113,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(80d)));
     insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(85d)));
     insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(10d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_COVERAGE)));
 
@@ -1099,6 +1140,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, new Measure(coverage, c -> c.setValue(15d)));
     insertProject(organizationDto, new Measure(coverage, c -> c.setValue(5d)));
     insertProject(organizationDto);
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(DUPLICATED_LINES_DENSITY_KEY)));
 
@@ -1125,6 +1167,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(10d)));
     insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(15d)));
     insertProject(organizationDto, new Measure(coverage, c -> c.setVariation(5d)));
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(NEW_DUPLICATED_LINES_DENSITY_KEY)));
 
@@ -1152,6 +1195,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setData(Metric.Level.WARN.name()).setValue(null)));
     insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setData(Metric.Level.OK.name()).setValue(null)));
     projectsInWarning.update(1L);
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(ALERT_STATUS_KEY)));
 
@@ -1175,6 +1219,7 @@ public class SearchProjectsActionTest {
     insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setData(Metric.Level.ERROR.name()).setValue(null)));
     insertProject(organizationDto, new Measure(qualityGateStatus, c -> c.setData(Metric.Level.OK.name()).setValue(null)));
     projectsInWarning.update(0L);
+    index();
 
     SearchProjectsWsResponse result = call(request.setFacets(singletonList(ALERT_STATUS_KEY)));
 
@@ -1196,6 +1241,7 @@ public class SearchProjectsActionTest {
     insertProject(organization, c -> c.setName("Sonar Groovy"));
     insertProject(organization, c -> c.setName("Sonar Markdown"));
     insertProject(organization, c -> c.setName("Sonar Qube"));
+    index();
 
     SearchProjectsWsResponse result = call(request);
 
@@ -1210,6 +1256,7 @@ public class SearchProjectsActionTest {
     insertProject(organization, c -> c.setName("Sonar Groovy"));
     insertProject(organization, c -> c.setName("Sonar Markdown"));
     insertProject(organization, c -> c.setName("Sonar Qube"));
+    index();
 
     assertThat(call(request.setSort("name").setAsc(true)).getComponentsList()).extracting(Component::getName)
       .containsExactly("Sonar Groovy", "Sonar Java", "Sonar Markdown", "Sonar Qube");
@@ -1226,6 +1273,7 @@ public class SearchProjectsActionTest {
     ComponentDto project2 = insertProject(organizationDto, c -> c.setName("Sonar Groovy"), new Measure(coverage, c -> c.setValue(81d)));
     ComponentDto project3 = insertProject(organizationDto, c -> c.setName("Sonar Markdown"), new Measure(coverage, c -> c.setValue(80d)));
     ComponentDto project4 = insertProject(organizationDto, c -> c.setName("Sonar Qube"), new Measure(coverage, c -> c.setValue(80d)));
+    index();
 
     assertThat(call(request.setSort(COVERAGE).setAsc(true)).getComponentsList()).extracting(Component::getKey)
       .containsExactly(project3.getDbKey(), project4.getDbKey(), project2.getDbKey(), project1.getDbKey());
@@ -1242,6 +1290,7 @@ public class SearchProjectsActionTest {
     ComponentDto project2 = insertProject(organization, c -> c.setName("Sonar Groovy"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("ERROR")));
     ComponentDto project3 = insertProject(organization, c -> c.setName("Sonar Markdown"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK")));
     ComponentDto project4 = insertProject(organization, c -> c.setName("Sonar Qube"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK")));
+    index();
 
     assertThat(call(request.setSort(QUALITY_GATE_STATUS).setAsc(true)).getComponentsList()).extracting(Component::getKey)
       .containsExactly(project3.getDbKey(), project4.getDbKey(), project2.getDbKey(), project1.getDbKey());
@@ -1265,7 +1314,7 @@ public class SearchProjectsActionTest {
     db.components().insertSnapshot(project4, snapshot -> snapshot.setCreatedAt(10_000_000_000L).setLast(false));
     db.components().insertSnapshot(project4, snapshot -> snapshot.setCreatedAt(30_000_000_000L).setLast(true));
     authorizationIndexerTester.allowOnlyAnyone(project4);
-    projectMeasuresIndexer.indexOnStartup(null);
+    index();
 
     assertThat(call(request.setSort(ANALYSIS_DATE).setAsc(true)).getComponentsList()).extracting(Component::getKey)
       .containsExactly(project3.getDbKey(), project4.getDbKey(), project2.getDbKey(), project1.getDbKey());
@@ -1288,7 +1337,7 @@ public class SearchProjectsActionTest {
     // No snapshot on project 3
     ComponentDto project3 = db.components().insertPublicProject(organization);
     authorizationIndexerTester.allowOnlyAnyone(project3);
-    projectMeasuresIndexer.indexOnStartup(null);
+    index();
 
     SearchProjectsWsResponse result = call(request.setAdditionalFields(singletonList("analysisDate")));
 
@@ -1321,7 +1370,7 @@ public class SearchProjectsActionTest {
     db.components().insertSnapshot(application1);
 
     authorizationIndexerTester.allowOnlyAnyone(application1);
-    projectMeasuresIndexer.indexOnStartup(null);
+    index();
 
     SearchProjectsWsResponse result = call(request.setAdditionalFields(singletonList("leakPeriodDate")));
 
@@ -1341,7 +1390,7 @@ public class SearchProjectsActionTest {
     authorizationIndexerTester.allowOnlyAnyone(privateProject);
     ComponentDto publicProject = db.components().insertPrivateProject(organization);
     authorizationIndexerTester.allowOnlyAnyone(publicProject);
-    projectMeasuresIndexer.indexOnStartup(null);
+    index();
 
     SearchProjectsWsResponse result = call(request);
 
@@ -1356,7 +1405,7 @@ public class SearchProjectsActionTest {
     ComponentDto project = db.components().insertPublicProject();
     authorizationIndexerTester.allowOnlyAnyone(project);
     ComponentDto branch = db.components().insertProjectBranch(project);
-    projectMeasuresIndexer.indexOnStartup(null);
+    index();
 
     SearchProjectsWsResponse result = call(request);
 
@@ -1373,10 +1422,11 @@ public class SearchProjectsActionTest {
     ComponentDto project2 = insertProject(organization, c -> c.setName("Sonar Groovy"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("WARN")));
     ComponentDto project3 = insertProject(organization, c -> c.setName("Sonar Markdown"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("WARN")));
     ComponentDto project4 = insertProject(organization, c -> c.setName("Sonar Qube"), new Measure(qualityGateStatus, c -> c.setValue(null).setData("OK")));
+    index();
 
     List<Component> projects = call(request
       .setFilter("alert_status = WARN"))
-        .getComponentsList();
+      .getComponentsList();
 
     assertThat(projects)
       .extracting(Component::getKey)
@@ -1408,9 +1458,7 @@ public class SearchProjectsActionTest {
   @Test
   public void fail_if_page_size_greater_than_500() {
     userSession.logIn();
-
     expectedException.expect(IllegalArgumentException.class);
-
     call(request.setPageSize(501));
   }
 
@@ -1449,8 +1497,6 @@ public class SearchProjectsActionTest {
     Measure... measures) {
     ComponentDto project = db.components().insertPublicProject(organizationDto, componentConsumer, projectConsumer);
     Arrays.stream(measures).forEach(m -> db.measures().insertLiveMeasure(project, m.metric, m.consumer));
-    authorizationIndexerTester.allowOnlyAnyone(project);
-    projectMeasuresIndexer.indexOnAnalysis(project.uuid());
     return project;
   }
 
@@ -1461,16 +1507,18 @@ public class SearchProjectsActionTest {
   private ComponentDto insertApplication(OrganizationDto organizationDto, Consumer<ComponentDto> componentConsumer, Measure... measures) {
     ComponentDto application = db.components().insertPublicApplication(organizationDto, componentConsumer);
     Arrays.stream(measures).forEach(m -> db.measures().insertLiveMeasure(application, m.metric, m.consumer));
-    authorizationIndexerTester.allowOnlyAnyone(application);
-    projectMeasuresIndexer.indexOnAnalysis(application.uuid());
     return application;
   }
 
+  private void index() {
+    projectMeasuresIndexer.indexAll();
+    Set<ComponentDto> roots = dbClient.componentDao().selectComponentsByQualifiers(db.getSession(),
+      new HashSet<>(asList(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.APP)));
+    authorizationIndexerTester.allowOnlyAnyone(roots.toArray(new ComponentDto[0]));
+  }
+
   private ComponentDto insertPortfolio(OrganizationDto organizationDto) {
-    ComponentDto portfolio = db.components().insertPublicPortfolio(organizationDto);
-    authorizationIndexerTester.allowOnlyAnyone(portfolio);
-    projectMeasuresIndexer.indexOnAnalysis(portfolio.uuid());
-    return portfolio;
+    return db.components().insertPublicPortfolio(organizationDto);
   }
 
   private static class Measure {
index cef814630e8c9f3c401787b932e18d1a5161f5e1..c032d97a75562d4689728a1f54e949aafedb165f 100644 (file)
@@ -141,7 +141,7 @@ public class SuggestionsActionTest {
     OrganizationDto organization = db.organizations().insert(o -> o.setKey("default-organization").setName("Default Organization"));
     ComponentDto project1 = db.components().insertPublicProject(organization, p -> p.setDbKey("org.sonarsource:sonarqube").setName("SonarSource :: SonarQube"));
     ComponentDto project2 = db.components().insertPublicProject(organization, p -> p.setDbKey("org.sonarsource:sonarlint").setName("SonarSource :: SonarLint"));
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     authorizationIndexerTester.allowOnlyAnyone(project1);
     authorizationIndexerTester.allowOnlyAnyone(project2);
 
@@ -159,7 +159,7 @@ public class SuggestionsActionTest {
   public void suggestions_without_query_should_contain_recently_browsed() {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     userSessionRule.addProjectPermission(USER, project);
 
     SuggestionsWsResponse response = ws.newRequest()
@@ -184,7 +184,7 @@ public class SuggestionsActionTest {
   public void suggestions_without_query_should_contain_recently_browsed_public_project() {
     ComponentDto project = db.components().insertComponent(newPublicProjectDto(organization));
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
 
     SuggestionsWsResponse response = ws.newRequest()
       .setMethod("POST")
@@ -208,7 +208,7 @@ public class SuggestionsActionTest {
   public void suggestions_without_query_should_not_contain_recently_browsed_without_permission() {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
 
     SuggestionsWsResponse response = ws.newRequest()
       .setMethod("POST")
@@ -225,7 +225,7 @@ public class SuggestionsActionTest {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
     doReturn(singletonList(project)).when(favoriteFinder).list();
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     userSessionRule.addProjectPermission(USER, project);
 
     SuggestionsWsResponse response = ws.newRequest()
@@ -250,7 +250,7 @@ public class SuggestionsActionTest {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
     doReturn(singletonList(project)).when(favoriteFinder).list();
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
 
     SuggestionsWsResponse response = ws.newRequest()
       .setMethod("POST")
@@ -266,7 +266,7 @@ public class SuggestionsActionTest {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
     doReturn(singletonList(project)).when(favoriteFinder).list();
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     userSessionRule.addProjectPermission(USER, project);
 
     SuggestionsWsResponse response = ws.newRequest()
@@ -291,7 +291,7 @@ public class SuggestionsActionTest {
   public void suggestions_without_query_should_not_contain_matches_that_are_neither_favorites_nor_recently_browsed() {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     userSessionRule.addProjectPermission(USER, project);
 
     SuggestionsWsResponse response = ws.newRequest()
@@ -313,7 +313,7 @@ public class SuggestionsActionTest {
     ComponentDto project4 = db.components().insertComponent(newPrivateProjectDto(organization).setName("Delta"));
     doReturn(asList(project4, project2)).when(favoriteFinder).list();
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     userSessionRule.addProjectPermission(USER, project1);
     userSessionRule.addProjectPermission(USER, project2);
     userSessionRule.addProjectPermission(USER, project3);
@@ -373,7 +373,7 @@ public class SuggestionsActionTest {
   public void exact_match_in_one_qualifier() {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     authorizationIndexerTester.allowOnlyAnyone(project);
 
     SuggestionsWsResponse response = ws.newRequest()
@@ -398,7 +398,7 @@ public class SuggestionsActionTest {
   public void should_not_return_suggestion_on_non_existing_project() {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     authorizationIndexerTester.allowOnlyAnyone(project);
 
     db.getDbClient().componentDao().delete(db.getSession(), project.uuid());
@@ -419,7 +419,7 @@ public class SuggestionsActionTest {
   public void must_not_search_if_no_valid_tokens_are_provided() {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("SonarQube"));
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     authorizationIndexerTester.allowOnlyAnyone(project);
 
     SuggestionsWsResponse response = ws.newRequest()
@@ -445,7 +445,7 @@ public class SuggestionsActionTest {
   public void should_warn_about_short_inputs_but_return_results_based_on_other_terms() {
     ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("SonarQube"));
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     authorizationIndexerTester.allowOnlyAnyone(project);
 
     SuggestionsWsResponse response = ws.newRequest()
@@ -593,7 +593,7 @@ public class SuggestionsActionTest {
     ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setName(query));
     ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query));
     ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query).setQualifier(UNIT_TEST_FILE));
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     authorizationIndexerTester.allowOnlyAnyone(project);
     authorizationIndexerTester.allowOnlyAnyone(view);
     authorizationIndexerTester.allowOnlyAnyone(app);
@@ -617,7 +617,7 @@ public class SuggestionsActionTest {
     ComponentDto project = db.components().insertPublicProject();
     authorizationIndexerTester.allowOnlyAnyone(project);
     ComponentDto branch = db.components().insertProjectBranch(project);
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     authorizationIndexerTester.allowOnlyAnyone(project);
 
     SuggestionsWsResponse response = ws.newRequest()
@@ -736,7 +736,7 @@ public class SuggestionsActionTest {
       .mapToObj(i -> db.components().insertComponent(newPublicProjectDto(organization).setName(namePrefix + i)))
       .collect(Collectors.toList());
 
-    componentIndexer.indexOnStartup(null);
+    componentIndexer.indexAll();
     projects.forEach(authorizationIndexerTester::allowOnlyAnyone);
 
     TestRequest request = ws.newRequest()
index 0ac14278d18e17c98136b15b3fdb95e1177fe518..677acf835808fc2c3350cf30d7bdae5a1d98d2ad 100644 (file)
@@ -1606,7 +1606,7 @@ public class SearchActionTest {
   }
 
   private void indexPermissions() {
-    permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes());
+    permissionIndexer.indexAll(permissionIndexer.getIndexTypes());
   }
 
   private void indexIssues() {
@@ -1614,7 +1614,7 @@ public class SearchActionTest {
   }
 
   private void indexViews() {
-    viewIndexer.indexOnStartup(viewIndexer.getIndexTypes());
+    viewIndexer.indexAll();
   }
 
   private RuleDefinitionDto newRule(RuleType ruleType) {
index 6a9414769a55c2bec737ff658dd60e021405ede8..f177e4df6dc688a2697599fb8374a310c7fd6be8 100644 (file)
@@ -48,7 +48,6 @@ import org.sonar.server.ws.WsActionTester;
 import org.sonarqube.ws.Issues.AuthorsResponse;
 
 import static java.lang.String.format;
-import static java.util.Collections.emptySet;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.groups.Tuple.tuple;
 import static org.mockito.ArgumentMatchers.any;
@@ -200,7 +199,7 @@ public class AuthorsActionTest {
     RuleDefinitionDto rule = db.rules().insertIssueRule();
     db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(leia));
     indexIssues();
-    viewIndexer.indexOnStartup(emptySet());
+    viewIndexer.indexAll();
     userSession.logIn();
 
     assertThat(ws.newRequest()
@@ -220,7 +219,7 @@ public class AuthorsActionTest {
     RuleDefinitionDto rule = db.rules().insertIssueRule();
     db.issues().insertIssue(rule, project, project, issue -> issue.setAuthorLogin(leia));
     indexIssues();
-    viewIndexer.indexOnStartup(emptySet());
+    viewIndexer.indexAll();
     userSession.logIn();
 
     assertThat(ws.newRequest()
index f662d7d4fc5a95d1d8b6bebd9e6798cb801cec59..a64081a1a3caab9a9bbd1fc2c18bf02a0f77af55 100644 (file)
@@ -805,6 +805,6 @@ public class SearchActionComponentsTest {
 
   private void indexIssuesAndViews() {
     indexIssues();
-    viewIndexer.indexOnStartup(null);
+    viewIndexer.indexAll();
   }
 }
index 5e5d68d2375146798741e639875bfc6493f41a7e..de2fdee9dee8a464f574830cb857679b691286de 100644 (file)
@@ -39,7 +39,6 @@ import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.rule.RuleDefinitionDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.es.EsTester;
-import org.sonar.server.es.StartupIndexer;
 import org.sonar.server.issue.AvatarResolverImpl;
 import org.sonar.server.issue.TextRangeResponseFormatter;
 import org.sonar.server.issue.TransitionService;
@@ -89,7 +88,7 @@ public class SearchActionFacetsTest {
 
   private IssueIndex issueIndex = new IssueIndex(es.client(), System2.INSTANCE, userSession, new WebAuthorizationTypeSupport(userSession));
   private IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()), null);
-  private StartupIndexer permissionIndexer = new PermissionIndexer(db.getDbClient(), es.client(), issueIndexer);
+  private PermissionIndexer permissionIndexer = new PermissionIndexer(db.getDbClient(), es.client(), issueIndexer);
   private IssueQueryFactory issueQueryFactory = new IssueQueryFactory(db.getDbClient(), Clock.systemUTC(), userSession);
   private SearchResponseLoader searchResponseLoader = new SearchResponseLoader(userSession, db.getDbClient(), new TransitionService(userSession, null));
   private Languages languages = new Languages();
@@ -592,7 +591,7 @@ public class SearchActionFacetsTest {
   }
 
   private void indexPermissions() {
-    permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes());
+    permissionIndexer.indexAll(permissionIndexer.getIndexTypes());
   }
 
   private void indexIssues() {
index 69a75f86718189b8713f7ae23cc9b00362bf872c..8ce84c15a76c8d1b0387b4e433d6d19df89f368c 100644 (file)
@@ -141,7 +141,7 @@ public class SearchActionTest {
   private IssueIndexSyncProgressChecker issueIndexSyncProgressChecker = new IssueIndexSyncProgressChecker(dbClient);
   private WsActionTester ws = new WsActionTester(
     new SearchAction(userSession, issueIndex, issueQueryFactory, issueIndexSyncProgressChecker, searchResponseLoader, searchResponseFormat, System2.INSTANCE, dbClient));
-  private StartupIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client(), issueIndexer);
+  private PermissionIndexer permissionIndexer = new PermissionIndexer(dbClient, es.client(), issueIndexer);
 
   @Before
   public void setUp() {
@@ -1368,7 +1368,7 @@ public class SearchActionTest {
   }
 
   private void indexPermissions() {
-    permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes());
+    permissionIndexer.indexAll(permissionIndexer.getIndexTypes());
   }
 
   private void indexIssues() {
index 7ddda09df2dcb6790a1242a69e5ce11d575b8207..c12a219754d7d3a4dd57c33240f4417bf561887c 100644 (file)
@@ -49,7 +49,6 @@ import org.sonarqube.ws.Issues.TagsResponse;
 
 import static java.lang.String.format;
 import static java.util.Arrays.asList;
-import static java.util.Collections.emptySet;
 import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.tuple;
@@ -226,7 +225,7 @@ public class TagsActionTest {
     RuleDefinitionDto rule = db.rules().insertIssueRule();
     db.issues().insertIssue(rule, project, project, issue -> issue.setTags(singletonList("cwe")));
     indexIssues();
-    viewIndexer.indexOnStartup(emptySet());
+    viewIndexer.indexAll();
 
     assertThat(tagListOf(ws.newRequest().setParam("project", portfolio.getKey()))).containsExactly("cwe");
   }
@@ -243,7 +242,7 @@ public class TagsActionTest {
     db.issues().insertHotspot(hotspotRule, project, project, issue -> issue.setTags(singletonList("cwe")));
     db.issues().insertIssue(issueRule, project, project, issue -> issue.setTags(singletonList("foo")));
     indexIssues();
-    viewIndexer.indexOnStartup(emptySet());
+    viewIndexer.indexAll();
 
     assertThat(tagListOf(ws.newRequest().setParam("project", portfolio.getKey()))).containsExactly("foo");
   }
@@ -258,7 +257,7 @@ public class TagsActionTest {
     RuleDefinitionDto rule = db.rules().insertIssueRule();
     db.issues().insertIssue(rule, project, project, issue -> issue.setTags(singletonList("cwe")));
     indexIssues();
-    viewIndexer.indexOnStartup(emptySet());
+    viewIndexer.indexAll();
 
     assertThat(tagListOf(ws.newRequest().setParam("project", application.getKey()))).containsExactly("cwe");
   }
@@ -275,7 +274,7 @@ public class TagsActionTest {
     db.issues().insertIssue(issueRule, project, project, issue -> issue.setTags(singletonList("cwe")));
     db.issues().insertHotspot(hotspotRule, project, project, issue -> issue.setTags(singletonList("foo")));
     indexIssues();
-    viewIndexer.indexOnStartup(emptySet());
+    viewIndexer.indexAll();
 
     assertThat(tagListOf(ws.newRequest().setParam("project", application.getKey()))).containsExactly("cwe");
   }
index 8afc5b9adff806019c1715b6f4d255df73e26feb..223e899e7ed1afaf71c22a5682ac5e1789bd2198 100644 (file)
@@ -717,7 +717,7 @@ public class QProfileRuleImplTest {
       i -> rules.add(db.rules().insertRule(r -> r.setLanguage(language).setRepositoryKey(repositoryKey))));
 
     verifyNoActiveRules();
-    ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());
+    ruleIndexer.indexAll();
 
     RuleQuery ruleQuery = new RuleQuery()
       .setRepositories(singletonList(repositoryKey));
@@ -744,7 +744,7 @@ public class QProfileRuleImplTest {
       i -> rules.add(db.rules().insertRule(r -> r.setLanguage(language).setRepositoryKey(repositoryKey))));
 
     verifyNoActiveRules();
-    ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());
+    ruleIndexer.indexAll();
 
     RuleQuery ruleQuery = new RuleQuery()
       .setRepositories(singletonList(repositoryKey));
@@ -777,7 +777,7 @@ public class QProfileRuleImplTest {
     assertThatRuleIsActivated(parentProfile, rule, null, rule.getSeverityString(), null, emptyMap());
     assertThatRuleIsActivated(childProfile, rule, null, rule.getSeverityString(), INHERITED, emptyMap());
 
-    ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());
+    ruleIndexer.indexAll();
 
     RuleQuery ruleQuery = new RuleQuery()
       .setQProfile(childProfile);
@@ -801,7 +801,7 @@ public class QProfileRuleImplTest {
     activate(parentProfile, RuleActivation.create(rule1.getUuid()));
     activate(parentProfile, RuleActivation.create(rule2.getUuid()));
 
-    ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());
+    ruleIndexer.indexAll();
 
     RuleQuery query = new RuleQuery()
       .setRuleKey(rule1.getRuleKey())
index 258571a4a4ad9d9ed807f4c7b4f65f644c2715ae..36824bb6093695506add4e5dd3b6bf6b2de627ec 100644 (file)
@@ -63,7 +63,6 @@ import org.sonar.server.ws.WsActionTester;
 import org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters;
 
 import static java.util.Arrays.asList;
-import static java.util.Collections.emptySet;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES;
@@ -133,7 +132,7 @@ public class ChangeParentActionTest {
     RuleDefinitionDto rule1 = createRule();
     createActiveRule(rule1, parent1);
     ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
-    activeRuleIndexer.indexOnStartup(emptySet());
+    activeRuleIndexer.indexAll();
 
     assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
 
@@ -164,7 +163,7 @@ public class ChangeParentActionTest {
     createActiveRule(rule1, parent1);
     createActiveRule(rule2, parent2);
     ruleIndexer.commitAndIndex(dbSession, asList(rule1.getUuid(), rule2.getUuid()));
-    activeRuleIndexer.indexOnStartup(emptySet());
+    activeRuleIndexer.indexAll();
 
     // Set parent 1
     qProfileTree.setParentAndCommit(dbSession, child, parent1);
@@ -193,7 +192,7 @@ public class ChangeParentActionTest {
     RuleDefinitionDto rule1 = createRule();
     createActiveRule(rule1, parent);
     ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
-    activeRuleIndexer.indexOnStartup(emptySet());
+    activeRuleIndexer.indexAll();
 
     // Set parent
     qProfileTree.setParentAndCommit(dbSession, child, parent);
@@ -222,7 +221,7 @@ public class ChangeParentActionTest {
     createActiveRule(rule1, parent1);
     createActiveRule(rule2, parent2);
     ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
-    activeRuleIndexer.indexOnStartup(emptySet());
+    activeRuleIndexer.indexAll();
 
     assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
 
@@ -275,7 +274,7 @@ public class ChangeParentActionTest {
     RuleDefinitionDto rule1 = createRule();
     createActiveRule(rule1, parent);
     ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
-    activeRuleIndexer.indexOnStartup(emptySet());
+    activeRuleIndexer.indexAll();
 
     assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
 
@@ -306,7 +305,7 @@ public class ChangeParentActionTest {
     createActiveRule(rule1, parent1);
     createActiveRule(rule2, parent2);
     ruleIndexer.commitAndIndex(dbSession, asList(rule1.getUuid(), rule2.getUuid()));
-    activeRuleIndexer.indexOnStartup(emptySet());
+    activeRuleIndexer.indexAll();
     // Set parent 1
     qProfileTree.setParentAndCommit(dbSession, child, parent1);
     UserDto user = db.users().insertUser();
index a533309f3bc2dd3f254450776742ec092b19c5bc..8e47d987fe1dd5f0a5380403d7d72cdfb1acede8 100644 (file)
@@ -106,7 +106,7 @@ public class InheritanceActionTest {
     createActiveRule(rule2, sonarway);
 
     dbSession.commit();
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    activeRuleIndexer.indexAll();
 
     QProfileDto companyWide = createProfile("xoo", "My Company Profile", "xoo-my-company-profile-12345");
     setParent(sonarway, companyWide);
@@ -119,7 +119,7 @@ public class InheritanceActionTest {
     setParent(buWide, forProject1);
     createActiveRule(rule3, forProject1);
     dbSession.commit();
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    activeRuleIndexer.indexAll();
 
     QProfileDto forProject2 = createProfile("xoo", "For Project Two", "xoo-for-project-two-45678");
     setParent(buWide, forProject2);
@@ -150,7 +150,7 @@ public class InheritanceActionTest {
     db.qualityProfiles().activateRule(child, rule3);
     long childRules = 1;
 
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    activeRuleIndexer.indexAll();
 
     InputStream response = ws.newRequest()
       .setMediaType(PROTOBUF)
@@ -177,7 +177,7 @@ public class InheritanceActionTest {
     db.qualityProfiles().activateRule(profile, rule);
     long activeRules = 0;
 
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    activeRuleIndexer.indexAll();
 
     InputStream response = ws.newRequest()
       .setMediaType(PROTOBUF)
index 31658beb136cf95fcf2dd5ad510c9232c127e736..eed8dd286eba424159125e608738871bb573989b 100644 (file)
@@ -109,7 +109,7 @@ public class QProfilesWsMediumTest {
     RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
     createActiveRule(rule, profile);
     ruleIndexer.commitAndIndex(dbSession, rule.getUuid());
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    activeRuleIndexer.indexAll();
 
     // 0. Assert No Active Rule for profile
     assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(1);
@@ -137,7 +137,7 @@ public class QProfilesWsMediumTest {
     createActiveRule(rule3, profile);
     createActiveRule(rule1, profile);
     dbSession.commit();
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    activeRuleIndexer.indexAll();
 
     // 0. Assert No Active Rule for profile
     assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(4);
@@ -163,7 +163,7 @@ public class QProfilesWsMediumTest {
     createActiveRule(rule0, php);
     createActiveRule(rule1, php);
     dbSession.commit();
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    activeRuleIndexer.indexAll();
 
     // 0. Assert No Active Rule for profile
     assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(2);
@@ -187,7 +187,7 @@ public class QProfilesWsMediumTest {
     createActiveRule(rule0, profile);
     createActiveRule(rule1, profile);
     dbSession.commit();
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    activeRuleIndexer.indexAll();
 
     // 0. Assert No Active Rule for profile
     assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(2);
@@ -421,7 +421,7 @@ public class QProfilesWsMediumTest {
     dbClient.activeRuleDao().insert(dbSession, active2);
 
     dbSession.commit();
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    activeRuleIndexer.indexAll();
 
     // 0. assert rule child rule is minor
     Optional<ActiveRuleDto> activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, active2.getKey());
index 600c8a0cf0aa75c815ac24c56f02def11a38000d..bc1ad771512c312b01b37e03023cee40226db35f 100644 (file)
@@ -166,8 +166,8 @@ public class ShowActionTest {
     db.qualityProfiles().activateRule(sonarWayProfile, commonRule);
     db.qualityProfiles().activateRule(sonarWayProfile, sonarWayRule1);
     db.qualityProfiles().activateRule(sonarWayProfile, sonarWayRule2);
-    ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    ruleIndexer.indexAll();
+    activeRuleIndexer.indexAll();
 
     CompareToSonarWay result = call(ws.newRequest()
       .setParam(PARAM_KEY, profile.getKee())
@@ -186,8 +186,8 @@ public class ShowActionTest {
     RuleDefinitionDto commonRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
     db.qualityProfiles().activateRule(profile, commonRule);
     db.qualityProfiles().activateRule(sonarWayProfile, commonRule);
-    ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    ruleIndexer.indexAll();
+    activeRuleIndexer.indexAll();
 
     CompareToSonarWay result = call(ws.newRequest()
       .setParam(PARAM_KEY, profile.getKee())
index 975ecda163998c23b157da5bcab79c30c89d20e7..0dd76c5e6a10becc4218b1c978214d377d7fa615 100644 (file)
@@ -921,11 +921,11 @@ public class SearchActionTest {
   }
 
   private void indexRules() {
-    ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());
+    ruleIndexer.indexAll();
   }
 
   private void indexActiveRules() {
-    activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+    activeRuleIndexer.indexAll();
   }
 
   private String[] get101Tags() {
index cf16f7afe1ade8dcf7b570f0065751d44ec19e7f..4ecf507e70138f59e0cf1d34be660c1dc3bb7ace 100644 (file)
@@ -19,9 +19,7 @@
  */
 package org.sonar.server.user.ws;
 
-import java.util.HashSet;
 import java.util.Optional;
-import org.elasticsearch.action.search.SearchRequest;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
 import org.junit.Before;
 import org.junit.Rule;
@@ -225,7 +223,7 @@ public class CreateActionTest {
     logInAsSystemAdministrator();
 
     db.users().insertUser(newUserDto("john", "John", "john@email.com").setActive(false));
-    userIndexer.indexOnStartup(new HashSet<>());
+    userIndexer.indexAll();
 
     call(CreateRequest.builder()
       .setLogin("john")
index df3b3c2af5b6c49db4bf51aad6114dd7ecb40fdd..f0f010ef957320c51b708e1aa9cdb6539eac68f9 100644 (file)
@@ -65,7 +65,7 @@ public class SearchActionTest {
   public void search_for_all_users() {
     UserDto user1 = db.users().insertUser();
     UserDto user2 = db.users().insertUser();
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
     userSession.logIn();
 
     SearchWsResponse response = ws.newRequest()
@@ -87,7 +87,7 @@ public class SearchActionTest {
       .setEmail("user@mail.com")
       .setLocal(true)
       .setScmAccounts(singletonList("user1")));
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     assertThat(ws.newRequest()
       .setParam("q", "user-%_%-")
@@ -109,7 +109,7 @@ public class SearchActionTest {
   @Test
   public void return_avatar() {
     UserDto user = db.users().insertUser(u -> u.setEmail("john@doe.com"));
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
     userSession.logIn();
 
     SearchWsResponse response = ws.newRequest()
@@ -123,7 +123,7 @@ public class SearchActionTest {
   @Test
   public void return_scm_accounts() {
     UserDto user = db.users().insertUser(u -> u.setScmAccounts(asList("john1", "john2")));
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
     userSession.logIn();
 
     SearchWsResponse response = ws.newRequest()
@@ -139,7 +139,7 @@ public class SearchActionTest {
     UserDto user = db.users().insertUser();
     db.users().insertToken(user);
     db.users().insertToken(user);
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     userSession.logIn().setSystemAdministrator();
     assertThat(ws.newRequest()
@@ -157,7 +157,7 @@ public class SearchActionTest {
   @Test
   public void return_email_only_when_system_administer() {
     UserDto user = db.users().insertUser();
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     userSession.logIn().setSystemAdministrator();
     assertThat(ws.newRequest()
@@ -175,7 +175,7 @@ public class SearchActionTest {
   @Test
   public void return_user_not_having_email() {
     UserDto user = db.users().insertUser(u -> u.setEmail(null));
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
     userSession.logIn().setSystemAdministrator();
 
     SearchWsResponse response = ws.newRequest()
@@ -194,7 +194,7 @@ public class SearchActionTest {
     GroupDto group3 = db.users().insertGroup("group3");
     db.users().insertMember(group1, user);
     db.users().insertMember(group2, user);
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     userSession.logIn().setSystemAdministrator();
     assertThat(ws.newRequest()
@@ -212,7 +212,7 @@ public class SearchActionTest {
   @Test
   public void return_external_information() {
     UserDto user = db.users().insertUser();
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
     userSession.logIn().setSystemAdministrator();
 
     SearchWsResponse response = ws.newRequest()
@@ -226,7 +226,7 @@ public class SearchActionTest {
   @Test
   public void return_external_identity_only_when_system_administer() {
     UserDto user = db.users().insertUser();
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     userSession.logIn().setSystemAdministrator();
     assertThat(ws.newRequest()
@@ -247,7 +247,7 @@ public class SearchActionTest {
     db.users().insertToken(user);
     GroupDto group = db.users().insertGroup();
     db.users().insertMember(group, user);
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
     userSession.anonymous();
 
     SearchWsResponse response = ws.newRequest()
@@ -263,7 +263,7 @@ public class SearchActionTest {
     UserDto userWithLastConnectionDate = db.users().insertUser();
     db.users().updateLastConnectionDate(userWithLastConnectionDate, 10_000_000_000L);
     UserDto userWithoutLastConnectionDate = db.users().insertUser();
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
     userSession.logIn().setSystemAdministrator();
 
     SearchWsResponse response = ws.newRequest()
@@ -285,7 +285,7 @@ public class SearchActionTest {
     GroupDto group = db.users().insertGroup();
     db.users().insertMember(group, user);
     UserDto otherUser = db.users().insertUser();
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     userSession.logIn(user);
     assertThat(ws.newRequest().setParam("q", user.getLogin())
@@ -308,7 +308,7 @@ public class SearchActionTest {
   public void search_with_paging() {
     userSession.logIn();
     IntStream.rangeClosed(0, 9).forEach(i -> db.users().insertUser(u -> u.setLogin("user-" + i).setName("User " + i)));
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
 
     SearchWsResponse response = ws.newRequest()
       .setParam(Param.PAGE_SIZE, "5")
@@ -364,7 +364,7 @@ public class SearchActionTest {
     db.users().insertToken(simon);
     db.users().insertToken(simon);
     db.users().insertToken(fmallet);
-    userIndexer.indexOnStartup(null);
+    userIndexer.indexAll();
     userSession.logIn().setSystemAdministrator();
 
     String response = ws.newRequest().execute().getInput();