Search in sources :

Example 1 with IssueIndex

use of org.sonar.server.issue.index.IssueIndex in project sonarqube by SonarSource.

the class IssuesActionTest method before.

@Before
public void before() {
    IssueIndex issueIndex = new IssueIndex(es.client(), system2, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
    IssuesAction issuesAction = new IssuesAction(db.getDbClient(), issueIndex, userSessionRule, new ComponentFinder(db.getDbClient()));
    tester = new WsTester(new BatchWs(issuesAction));
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) WsTester(org.sonar.server.ws.WsTester) IssueIndex(org.sonar.server.issue.index.IssueIndex) AuthorizationTypeSupport(org.sonar.server.permission.index.AuthorizationTypeSupport) Before(org.junit.Before)

Example 2 with IssueIndex

use of org.sonar.server.issue.index.IssueIndex 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);
}
Also used : IssueDoc(org.sonar.server.issue.index.IssueDoc) RuleDto(org.sonar.db.rule.RuleDto) IssueIndex(org.sonar.server.issue.index.IssueIndex) ComponentDto(org.sonar.db.component.ComponentDto) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) SearchOptions(org.sonar.server.es.SearchOptions) AuthorizationTypeSupport(org.sonar.server.permission.index.AuthorizationTypeSupport) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

IssueIndex (org.sonar.server.issue.index.IssueIndex)2 AuthorizationTypeSupport (org.sonar.server.permission.index.AuthorizationTypeSupport)2 Before (org.junit.Before)1 Test (org.junit.Test)1 ComponentDto (org.sonar.db.component.ComponentDto)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 RuleDto (org.sonar.db.rule.RuleDto)1 ComponentFinder (org.sonar.server.component.ComponentFinder)1 SearchOptions (org.sonar.server.es.SearchOptions)1 IssueDoc (org.sonar.server.issue.index.IssueDoc)1 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)1 IssueIteratorFactory (org.sonar.server.issue.index.IssueIteratorFactory)1 WsTester (org.sonar.server.ws.WsTester)1