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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations