use of org.sonar.server.issue.index.IssueIteratorFactory in project sonarqube by SonarSource.
the class ViewIndexerTest method clear_views_lookup_cache_on_index_view_uuid.
@Test
public void clear_views_lookup_cache_on_index_view_uuid() {
IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
IssueIndexer issueIndexer = new IssueIndexer(esTester.client(), new IssueIteratorFactory(dbClient));
String viewUuid = "ABCD";
RuleDto rule = RuleTesting.newXooX1();
dbClient.ruleDao().insert(dbSession, rule);
ComponentDto project1 = addProjectWithIssue(rule, dbTester.organizations().insert());
issueIndexer.indexOnStartup(issueIndexer.getIndexTypes());
permissionIndexer.indexProjectsByUuids(dbSession, asList(project1.uuid()));
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto view = ComponentTesting.newView(organizationDto, "ABCD");
ComponentDto techProject1 = ComponentTesting.newProjectCopy("CDEF", project1, view);
dbClient.componentDao().insert(dbSession, view, techProject1);
dbSession.commit();
// First view indexation
underTest.index(viewUuid);
// Execute issue query on view -> 1 issue on view
SearchResult<IssueDoc> docs = issueIndex.search(IssueQuery.builder().viewUuids(newArrayList(viewUuid)).build(), new SearchOptions());
assertThat(docs.getDocs()).hasSize(1);
// Add a project to the view and index it again
ComponentDto project2 = addProjectWithIssue(rule, organizationDto);
issueIndexer.indexOnStartup(issueIndexer.getIndexTypes());
permissionIndexer.indexProjectsByUuids(dbSession, asList(project2.uuid()));
ComponentDto techProject2 = ComponentTesting.newProjectCopy("EFGH", project2, view);
dbClient.componentDao().insert(dbSession, techProject2);
dbSession.commit();
underTest.index(viewUuid);
// Execute issue query on view -> issue of project2 are well taken into account : the cache has been cleared
assertThat(issueIndex.search(IssueQuery.builder().viewUuids(newArrayList(viewUuid)).build(), new SearchOptions()).getDocs()).hasSize(2);
}
Aggregations