diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2020-11-26 20:34:42 -0600 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-11-30 20:07:06 +0000 |
commit | 736bfc4d5ae032edaf556ee8a41efc1d9b9ce4f9 (patch) | |
tree | d17ef789c14df37e5cbe5692356b1d771ade26aa /server/sonar-webserver-webapi/src | |
parent | 59adbb849b1ce3338e6299dea939c454df7d0cdb (diff) | |
download | sonarqube-736bfc4d5ae032edaf556ee8a41efc1d9b9ce4f9.tar.gz sonarqube-736bfc4d5ae032edaf556ee8a41efc1d9b9ce4f9.zip |
Speed up unit tests by improving indexing in unit tests
* 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)
Diffstat (limited to 'server/sonar-webserver-webapi/src')
17 files changed, 137 insertions, 96 deletions
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java index 4a1f693bd46..b375cad9dd0 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchActionTest.java @@ -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() { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index db74e41a864..230d59b2012 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -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 { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java index cef814630e8..c032d97a755 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java @@ -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() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java index 0ac14278d18..677acf83580 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/hotspot/ws/SearchActionTest.java @@ -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) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java index 6a9414769a5..f177e4df6dc 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AuthorsActionTest.java @@ -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() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java index f662d7d4fc5..a64081a1a3c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java @@ -805,6 +805,6 @@ public class SearchActionComponentsTest { private void indexIssuesAndViews() { indexIssues(); - viewIndexer.indexOnStartup(null); + viewIndexer.indexAll(); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionFacetsTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionFacetsTest.java index 5e5d68d2375..de2fdee9dee 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionFacetsTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionFacetsTest.java @@ -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() { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index 69a75f86718..8ce84c15a76 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -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() { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java index 7ddda09df2d..c12a219754d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java @@ -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"); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java index 8afc5b9adff..223e899e7ed 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java @@ -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()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java index 258571a4a4a..36824bb6093 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ChangeParentActionTest.java @@ -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(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java index a533309f3bc..8e47d987fe1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/InheritanceActionTest.java @@ -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) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java index 31658beb136..eed8dd286eb 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsMediumTest.java @@ -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()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java index 600c8a0cf0a..bc1ad771512 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/ShowActionTest.java @@ -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()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java index 975ecda1639..0dd76c5e6a1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java @@ -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() { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java index cf16f7afe1a..4ecf507e701 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/CreateActionTest.java @@ -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") diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SearchActionTest.java index df3b3c2af5b..f0f010ef957 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/SearchActionTest.java @@ -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(); |