use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.
the class ProjectMeasuresIndexer method index.
@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
if (items.isEmpty()) {
return new IndexingResult();
}
OneToOneResilientIndexingListener listener = new OneToOneResilientIndexingListener(dbClient, dbSession, items);
BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener);
bulkIndexer.start();
List<String> projectUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toArrayList(items.size()));
Iterator<String> it = projectUuids.iterator();
while (it.hasNext()) {
String projectUuid = it.next();
try (ProjectMeasuresIndexerIterator rowIt = ProjectMeasuresIndexerIterator.create(dbSession, projectUuid)) {
while (rowIt.hasNext()) {
bulkIndexer.add(toProjectMeasuresDoc(rowIt.next()).toIndexRequest());
it.remove();
}
}
}
// the remaining uuids reference projects that don't exist in db. They must be deleted from index.
projectUuids.forEach(projectUuid -> bulkIndexer.addDeletion(TYPE_PROJECT_MEASURES, projectUuid, AuthorizationDoc.idOf(projectUuid)));
return bulkIndexer.stop();
}
use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.
the class ComponentIndexerTest method errors_during_indexing_are_recovered.
@Test
public void errors_during_indexing_are_recovered() {
ComponentDto project1 = db.components().insertPrivateProject();
es.lockWrites(TYPE_COMPONENT);
IndexingResult result = indexProject(project1, PROJECT_CREATION);
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();
assertThat(es.countDocuments(TYPE_COMPONENT)).isZero();
es.unlockWrites(TYPE_COMPONENT);
result = recover();
assertThat(result.getTotal()).isOne();
assertThat(result.getFailures()).isZero();
assertThatIndexContainsOnly(project1);
}
use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.
the class ComponentIndexerTest method update_index_on_project_creation.
@Test
public void update_index_on_project_creation() {
ComponentDto project = db.components().insertPrivateProject();
IndexingResult result = indexProject(project, PROJECT_CREATION);
assertThatIndexContainsOnly(project);
assertThat(result.getTotal()).isOne();
assertThat(result.getSuccess()).isOne();
}
use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.
the class IssueIndexerTest method index_is_updated_when_deleting_project.
@Test
public void index_is_updated_when_deleting_project() {
addIssueToIndex("P1", "I1");
assertThatIndexHasSize(1);
IndexingResult result = indexProject("P1", ProjectIndexer.Cause.PROJECT_DELETION);
assertThat(result.getTotal()).isOne();
assertThat(result.getSuccess()).isOne();
assertThatIndexHasSize(0);
}
use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.
the class IssueIndexerTest method index_is_not_updated_when_updating_tags.
@Test
public void index_is_not_updated_when_updating_tags() {
// 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_TAGS_UPDATE);
assertThat(result.getTotal()).isZero();
assertThatIndexHasSize(0);
}
Aggregations