Search in sources :

Example 6 with IndexingResult

use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.

the class IssueIndexerTest method index_is_not_updated_when_updating_project_key.

@Test
public void index_is_not_updated_when_updating_project_key() {
    // issue is inserted to verify that indexing of project is not triggered
    IssueDto issue = db.issues().insert();
    IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE);
    assertThat(result.getTotal()).isZero();
    assertThatIndexHasSize(0);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 7 with IndexingResult

use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.

the class IssueIndexerTest method indexing_errors_during_commitAndIndexIssues_are_recovered.

@Test
public void indexing_errors_during_commitAndIndexIssues_are_recovered() {
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    // insert issues in db without committing
    IssueDto issue1 = IssueTesting.newIssue(rule, project, file);
    IssueDto issue2 = IssueTesting.newIssue(rule, project, file);
    db.getDbClient().issueDao().insert(db.getSession(), issue1, issue2);
    // index is read-only
    es.lockWrites(TYPE_ISSUE);
    underTest.commitAndIndexIssues(db.getSession(), asList(issue1, issue2));
    // issues are persisted but not indexed
    assertThatIndexHasSize(0);
    assertThatDbHasOnly(issue1, issue2);
    assertThatEsQueueTableHasSize(2);
    // re-enable write on index
    es.unlockWrites(TYPE_ISSUE);
    // emulate the recovery daemon
    IndexingResult result = recover();
    assertThatEsQueueTableHasSize(0);
    assertThatIndexHasOnly(issue1, issue2);
    assertThat(result.isSuccess()).isTrue();
    assertThat(result.getTotal()).isEqualTo(2L);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 8 with IndexingResult

use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.

the class IssueIndexerTest method errors_during_project_deletion_are_recovered.

@Test
public void errors_during_project_deletion_are_recovered() {
    addIssueToIndex("P1", "I1");
    assertThatIndexHasSize(1);
    es.lockWrites(TYPE_ISSUE);
    IndexingResult result = indexProject("P1", ProjectIndexer.Cause.PROJECT_DELETION);
    assertThat(result.getTotal()).isOne();
    assertThat(result.getFailures()).isOne();
    // index is still read-only, fail to recover
    result = recover();
    assertThat(result.getTotal()).isOne();
    assertThat(result.getFailures()).isOne();
    assertThatIndexHasSize(1);
    es.unlockWrites(TYPE_ISSUE);
    result = recover();
    assertThat(result.getTotal()).isOne();
    assertThat(result.getFailures()).isZero();
    assertThatIndexHasSize(0);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) Test(org.junit.Test)

Example 9 with IndexingResult

use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.

the class PermissionIndexerTest method errors_during_indexing_are_recovered.

@Test
public void errors_during_indexing_are_recovered() {
    ComponentDto project = createAndIndexPublicProject();
    es.lockWrites(INDEX_TYPE_FOO_AUTH);
    IndexingResult result = indexPermissions(project, PERMISSION_CHANGE);
    assertThat(result.getTotal()).isOne();
    assertThat(result.getFailures()).isOne();
    // index is still read-only, fail to recover
    result = recover();
    assertThat(result.getTotal()).isOne();
    assertThat(result.getFailures()).isOne();
    assertThatAuthIndexHasSize(0);
    assertThatEsQueueTableHasSize(1);
    es.unlockWrites(INDEX_TYPE_FOO_AUTH);
    result = recover();
    assertThat(result.getTotal()).isOne();
    assertThat(result.getFailures()).isZero();
    verifyAnyoneAuthorized(project);
    assertThatEsQueueTableHasSize(0);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 10 with IndexingResult

use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.

the class IssueIndexer method index.

@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
    ListMultimap<String, EsQueueDto> itemsByIssueKey = ArrayListMultimap.create();
    ListMultimap<String, EsQueueDto> itemsByProjectKey = ArrayListMultimap.create();
    items.forEach(i -> {
        if (ID_TYPE_ISSUE_KEY.equals(i.getDocIdType())) {
            itemsByIssueKey.put(i.getDocId(), i);
        } else if (ID_TYPE_PROJECT_UUID.equals(i.getDocIdType())) {
            itemsByProjectKey.put(i.getDocId(), i);
        } else {
            LOGGER.error("Unsupported es_queue.doc_id_type for issues. Manual fix is required: " + i);
        }
    });
    IndexingResult result = new IndexingResult();
    result.add(doIndexIssueItems(dbSession, itemsByIssueKey));
    result.add(doIndexProjectItems(dbSession, itemsByProjectKey));
    return result;
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) EsQueueDto(org.sonar.db.es.EsQueueDto)

Aggregations

IndexingResult (org.sonar.server.es.IndexingResult)26 Test (org.junit.Test)15 ComponentDto (org.sonar.db.component.ComponentDto)11 BulkIndexer (org.sonar.server.es.BulkIndexer)8 OneToOneResilientIndexingListener (org.sonar.server.es.OneToOneResilientIndexingListener)6 EsQueueDto (org.sonar.db.es.EsQueueDto)5 IssueDto (org.sonar.db.issue.IssueDto)5 OneToManyResilientIndexingListener (org.sonar.server.es.OneToManyResilientIndexingListener)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)2 IndexingListener (org.sonar.server.es.IndexingListener)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1