* 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)
@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);
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);
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;
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;
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)));
doIndexByProjectUuid(null, Size.LARGE);
}
+ public void indexAll() {
+ doIndexByProjectUuid(null, Size.REGULAR);
+ }
+
@Override
public void indexOnAnalysis(String branchUuid) {
doIndexByProjectUuid(branchUuid, Size.REGULAR);
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);
}
}
@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) {
doIndex(Size.LARGE, null);
}
+ public void indexAll() {
+ doIndex(Size.REGULAR, null);
+ }
+
@Override
public AuthorizationScope getAuthorizationScope() {
return AUTHORIZATION_SCOPE;
@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();
@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();
}
}
@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.
@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);
}
}
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();
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
*/
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);
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;
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;
.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);
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);
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);
.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);
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();
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"));
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")
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 -> {
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 -> {
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;
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));
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);
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(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);
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;
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);
}
private void index(ComponentDto... components) {
- indexer.indexOnStartup(emptySet());
+ indexer.indexAll();
Arrays.stream(components).forEach(c -> authorizationIndexerTester.allowOnlyAnyone(c));
}
}
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();
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;
}
private void index() {
- indexer.indexOnStartup(emptySet());
+ indexer.indexAll();
}
private static Language[] javaLanguage() {
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;
p -> p.setTagsString("sales, offshore, java"),
new Measure(coverage, c -> c.setValue(20d)));
addFavourite(project1);
+ index();
String jsonResult = ws.newRequest()
.setParam(FACETS, COVERAGE)
insertProject(organization, c -> c.setName("Maven"));
insertProject(organization, c -> c.setName("Apache"));
insertProject(organization, c -> c.setName("guava"));
+ index();
SearchProjectsWsResponse result = call(request);
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));
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"));
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)
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"));
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>)"));
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"));
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"));
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)"));
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"));
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"));
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"));
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"));
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"));
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"));
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"));
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"));
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",
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)
ComponentDto markDownProject = insertProject(organization);
ComponentDto sonarQubeProject = insertProject(organization);
Stream.of(javaProject, markDownProject).forEach(this::addFavourite);
+ index();
SearchProjectsWsResponse result = call(request.setFilter("isFavorite"));
ComponentDto markDownProject = insertProject(organization);
ComponentDto sonarQubeProject = insertProject(organization);
Stream.of(javaProject, markDownProject).forEach(this::addFavourite);
+ index();
addFavourite((String) null);
ComponentDto markDownProject = insertProject(organization);
ComponentDto sonarQubeProject = insertProject(organization);
Stream.of(javaProject, markDownProject).forEach(this::addFavourite);
+ index();
SearchProjectsWsResponse result = call(request.setFilter("isFavorite"));
ComponentDto project1 = insertProject(organization);
ComponentDto project2 = insertProject(organization);
ComponentDto project3 = insertProject(organization);
+ index();
SearchProjectsWsResponse result = call(request);
ComponentDto project1 = insertProject(organization);
ComponentDto project2 = insertProject(organization);
ComponentDto project3 = insertProject(organization);
+ index();
SearchProjectsWsResponse result = call(request);
insertProject(organization);
insertProject(organization);
insertProject(organization);
+ index();
SearchProjectsWsResponse result = call(request.setFilter("qualifier = APP"));
ComponentDto project1 = insertProject(organization);
ComponentDto project2 = insertProject(organization);
ComponentDto project3 = insertProject(organization);
+ index();
SearchProjectsWsResponse result = call(request.setFilter("qualifier = TRK"));
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);
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);
userSession.anonymous();
OrganizationDto organization = db.organizations().insert();
insertProject(organization);
+ index();
SearchProjectsWsResponse result = call(request);
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)));
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)));
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)));
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)));
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)));
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)));
ComponentDto project1 = insertProject(organization);
ComponentDto project2 = insertProject(organization);
ComponentDto project3 = insertProject(organization);
+ index();
SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_QUALIFIER)));
ComponentDto application2 = insertApplication(organization);
ComponentDto application3 = insertApplication(organization);
ComponentDto application4 = insertApplication(organization);
+ index();
SearchProjectsWsResponse result = call(request.setFilter("qualifier = APP").setFacets(singletonList(FILTER_QUALIFIER)));
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)));
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)));
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)));
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)));
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)));
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)));
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)));
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)));
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);
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");
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());
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());
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());
// 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")));
db.components().insertSnapshot(application1);
authorizationIndexerTester.allowOnlyAnyone(application1);
- projectMeasuresIndexer.indexOnStartup(null);
+ index();
SearchProjectsWsResponse result = call(request.setAdditionalFields(singletonList("leakPeriodDate")));
authorizationIndexerTester.allowOnlyAnyone(privateProject);
ComponentDto publicProject = db.components().insertPrivateProject(organization);
authorizationIndexerTester.allowOnlyAnyone(publicProject);
- projectMeasuresIndexer.indexOnStartup(null);
+ index();
SearchProjectsWsResponse result = call(request);
ComponentDto project = db.components().insertPublicProject();
authorizationIndexerTester.allowOnlyAnyone(project);
ComponentDto branch = db.components().insertProjectBranch(project);
- projectMeasuresIndexer.indexOnStartup(null);
+ index();
SearchProjectsWsResponse result = call(request);
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)
@Test
public void fail_if_page_size_greater_than_500() {
userSession.logIn();
-
expectedException.expect(IllegalArgumentException.class);
-
call(request.setPageSize(501));
}
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;
}
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 {
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);
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()
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")
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")
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()
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
doReturn(singletonList(project)).when(favoriteFinder).list();
- componentIndexer.indexOnStartup(null);
+ componentIndexer.indexAll();
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
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()
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()
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);
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()
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());
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()
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()
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);
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()
.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()
}
private void indexPermissions() {
- permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes());
+ permissionIndexer.indexAll(permissionIndexer.getIndexTypes());
}
private void indexIssues() {
}
private void indexViews() {
- viewIndexer.indexOnStartup(viewIndexer.getIndexTypes());
+ viewIndexer.indexAll();
}
private RuleDefinitionDto newRule(RuleType ruleType) {
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;
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()
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()
private void indexIssuesAndViews() {
indexIssues();
- viewIndexer.indexOnStartup(null);
+ viewIndexer.indexAll();
}
}
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;
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();
}
private void indexPermissions() {
- permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes());
+ permissionIndexer.indexAll(permissionIndexer.getIndexTypes());
}
private void indexIssues() {
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() {
}
private void indexPermissions() {
- permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes());
+ permissionIndexer.indexAll(permissionIndexer.getIndexTypes());
}
private void indexIssues() {
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;
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");
}
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");
}
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");
}
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");
}
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));
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));
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);
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())
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;
RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent1);
ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
- activeRuleIndexer.indexOnStartup(emptySet());
+ activeRuleIndexer.indexAll();
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
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);
RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent);
ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
- activeRuleIndexer.indexOnStartup(emptySet());
+ activeRuleIndexer.indexAll();
// Set parent
qProfileTree.setParentAndCommit(dbSession, child, parent);
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
- activeRuleIndexer.indexOnStartup(emptySet());
+ activeRuleIndexer.indexAll();
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
RuleDefinitionDto rule1 = createRule();
createActiveRule(rule1, parent);
ruleIndexer.commitAndIndex(dbSession, rule1.getUuid());
- activeRuleIndexer.indexOnStartup(emptySet());
+ activeRuleIndexer.indexAll();
assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, child.getKee())).isEmpty();
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();
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);
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);
db.qualityProfiles().activateRule(child, rule3);
long childRules = 1;
- activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+ activeRuleIndexer.indexAll();
InputStream response = ws.newRequest()
.setMediaType(PROTOBUF)
db.qualityProfiles().activateRule(profile, rule);
long activeRules = 0;
- activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+ activeRuleIndexer.indexAll();
InputStream response = ws.newRequest()
.setMediaType(PROTOBUF)
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);
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);
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);
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);
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());
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())
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())
}
private void indexRules() {
- ruleIndexer.indexOnStartup(ruleIndexer.getIndexTypes());
+ ruleIndexer.indexAll();
}
private void indexActiveRules() {
- activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
+ activeRuleIndexer.indexAll();
}
private String[] get101Tags() {
*/
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;
logInAsSystemAdministrator();
db.users().insertUser(newUserDto("john", "John", "john@email.com").setActive(false));
- userIndexer.indexOnStartup(new HashSet<>());
+ userIndexer.indexAll();
call(CreateRequest.builder()
.setLogin("john")
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()
.setEmail("user@mail.com")
.setLocal(true)
.setScmAccounts(singletonList("user1")));
- userIndexer.indexOnStartup(null);
+ userIndexer.indexAll();
assertThat(ws.newRequest()
.setParam("q", "user-%_%-")
@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()
@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()
UserDto user = db.users().insertUser();
db.users().insertToken(user);
db.users().insertToken(user);
- userIndexer.indexOnStartup(null);
+ userIndexer.indexAll();
userSession.logIn().setSystemAdministrator();
assertThat(ws.newRequest()
@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()
@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()
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()
@Test
public void return_external_information() {
UserDto user = db.users().insertUser();
- userIndexer.indexOnStartup(null);
+ userIndexer.indexAll();
userSession.logIn().setSystemAdministrator();
SearchWsResponse response = ws.newRequest()
@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()
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()
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()
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())
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")
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();