Search in sources :

Example 11 with EsQueueDto

use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.

the class RecoveryIndexerTest method successfully_recover_indexing_requests.

@Test
public void successfully_recover_indexing_requests() {
    EsQueueDto item1a = insertItem(FOO_TYPE, "f1");
    EsQueueDto item1b = insertItem(FOO_TYPE, "f2");
    IndexMainType type2 = IndexType.main(Index.simple("bars"), "bar");
    EsQueueDto item2 = insertItem(type2, "b1");
    SuccessfulFakeIndexer indexer1 = new SuccessfulFakeIndexer(FOO_TYPE);
    SuccessfulFakeIndexer indexer2 = new SuccessfulFakeIndexer(type2);
    advanceInTime();
    underTest = newRecoveryIndexer(indexer1, indexer2);
    underTest.recover();
    assertThatQueueHasSize(0);
    assertThatLogsContain(INFO, "Elasticsearch recovery - 3 documents processed [0 failures]");
    assertThat(indexer1.called).hasSize(1);
    assertThat(indexer1.called.get(0)).extracting(EsQueueDto::getUuid).containsExactlyInAnyOrder(item1a.getUuid(), item1b.getUuid());
    assertThatLogsContain(TRACE, "Elasticsearch recovery - processing 2 [foos/foo]");
    assertThat(indexer2.called).hasSize(1);
    assertThat(indexer2.called.get(0)).extracting(EsQueueDto::getUuid).containsExactlyInAnyOrder(item2.getUuid());
    assertThatLogsContain(TRACE, "Elasticsearch recovery - processing 1 [bars/bar]");
}
Also used : EsQueueDto(org.sonar.db.es.EsQueueDto) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) Test(org.junit.Test)

Example 12 with EsQueueDto

use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.

the class RecoveryIndexerTest method failing_always_on_same_document_does_not_generate_infinite_loop.

@Test
public void failing_always_on_same_document_does_not_generate_infinite_loop() {
    EsQueueDto buggy = insertItem(FOO_TYPE, "buggy");
    IntStream.range(0, 10).forEach(i -> insertItem(FOO_TYPE, "" + i));
    advanceInTime();
    FailingAlwaysOnSameElementIndexer indexer = new FailingAlwaysOnSameElementIndexer(FOO_TYPE, buggy);
    underTest = newRecoveryIndexer(indexer);
    underTest.recover();
    assertThatLogsContain(ERROR, "Elasticsearch recovery - too many failures [1/1 documents], waiting for next run");
    assertThatQueueHasSize(1);
}
Also used : EsQueueDto(org.sonar.db.es.EsQueueDto) Test(org.junit.Test)

Example 13 with EsQueueDto

use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.

the class IssueIndexerTest method recovery_does_not_fail_if_unsupported_docIdType.

@Test
public void recovery_does_not_fail_if_unsupported_docIdType() {
    EsQueueDto item = EsQueueDto.create(TYPE_ISSUE.format(), "I1", "unknown", "P1");
    db.getDbClient().esQueueDao().insert(db.getSession(), item);
    db.commit();
    recover();
    assertThat(logTester.logs(LoggerLevel.ERROR)).filteredOn(l -> l.contains("Unsupported es_queue.doc_id_type for issues. Manual fix is required: ")).hasSize(1);
    assertThatEsQueueTableHasSize(1);
}
Also used : Arrays(java.util.Arrays) SecurityStandards(org.sonar.server.security.SecurityStandards) TYPE_AUTHORIZATION(org.sonar.server.permission.index.IndexAuthorizationConstants.TYPE_AUTHORIZATION) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Date(java.util.Date) EsQueueDto(org.sonar.db.es.EsQueueDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SANS_TOP_25_POROUS_DEFENSES(org.sonar.server.security.SecurityStandards.SANS_TOP_25_POROUS_DEFENSES) DbSession(org.sonar.db.DbSession) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) IndexingResult(org.sonar.server.es.IndexingResult) Arrays.asList(java.util.Arrays.asList) Assertions(org.assertj.core.api.Assertions) ComponentTesting(org.sonar.db.component.ComponentTesting) ProjectIndexer(org.sonar.server.es.ProjectIndexer) StartupIndexer(org.sonar.server.es.StartupIndexer) SearchHit(org.elasticsearch.search.SearchHit) DbTester(org.sonar.db.DbTester) TYPE_ISSUE(org.sonar.server.issue.index.IssueIndexDefinition.TYPE_ISSUE) Collections.emptySet(java.util.Collections.emptySet) IssueTesting(org.sonar.db.issue.IssueTesting) AuthorizationScope(org.sonar.server.permission.index.AuthorizationScope) IndexPermissions(org.sonar.server.permission.index.IndexPermissions) Predicate(java.util.function.Predicate) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Test(org.junit.Test) VulnerabilityProbability(org.sonar.server.security.SecurityStandards.VulnerabilityProbability) Collectors(java.util.stream.Collectors) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) Qualifiers(org.sonar.api.resources.Qualifiers) IssueDocTesting.newDoc(org.sonar.server.issue.IssueDocTesting.newDoc) SQCategory(org.sonar.server.security.SecurityStandards.SQCategory) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) EsQueueDto(org.sonar.db.es.EsQueueDto) Test(org.junit.Test)

Example 14 with EsQueueDto

use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.

the class PermissionIndexerTest method indexPermissions.

private IndexingResult indexPermissions(ComponentDto project, ProjectIndexer.Cause cause) {
    DbSession dbSession = db.getSession();
    Collection<EsQueueDto> items = underTest.prepareForRecovery(dbSession, singletonList(project.uuid()), cause);
    dbSession.commit();
    return underTest.index(dbSession, items);
}
Also used : DbSession(org.sonar.db.DbSession) EsQueueDto(org.sonar.db.es.EsQueueDto)

Example 15 with EsQueueDto

use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.

the class OneToManyResilientIndexingListenerTest method ES_QUEUE_rows_are_not_deleted_on_partial_error.

@Test
public void ES_QUEUE_rows_are_not_deleted_on_partial_error() {
    EsQueueDto item1 = insertInQueue(TYPE_ISSUE, "P1");
    EsQueueDto item2 = insertInQueue(TYPE_ISSUE, "P2");
    EsQueueDto outOfScopeItem = insertInQueue(ComponentIndexDefinition.TYPE_COMPONENT, "P1");
    db.commit();
    // does not contain outOfScopeItem
    IndexingListener underTest = newListener(asList(item1, item2));
    DocId issue1 = newDocId(TYPE_ISSUE, "I1");
    DocId issue2 = newDocId(TYPE_ISSUE, "I2");
    underTest.onSuccess(asList(issue1, issue2));
    assertThatEsTableContainsOnly(item1, item2, outOfScopeItem);
    // one failure among the 2 indexing requests of issues
    IndexingResult result = new IndexingResult();
    result.incrementSuccess().incrementRequests();
    result.incrementRequests();
    underTest.onFinish(result);
    assertThatEsTableContainsOnly(item1, item2, outOfScopeItem);
}
Also used : EsQueueDto(org.sonar.db.es.EsQueueDto) Test(org.junit.Test)

Aggregations

EsQueueDto (org.sonar.db.es.EsQueueDto)26 Test (org.junit.Test)13 DbSession (org.sonar.db.DbSession)7 IndexingResult (org.sonar.server.es.IndexingResult)6 HashMap (java.util.HashMap)3 BulkIndexer (org.sonar.server.es.BulkIndexer)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 ComponentDto (org.sonar.db.component.ComponentDto)2 OneToOneResilientIndexingListener (org.sonar.server.es.OneToOneResilientIndexingListener)2 ProjectIndexer (org.sonar.server.es.ProjectIndexer)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.singletonList (java.util.Collections.singletonList)1