Search in sources :

Example 11 with ProjectMeasures

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method does_not_return_none_numeric_metrics.

@Test
public void does_not_return_none_numeric_metrics() {
    ComponentDto project = dbTester.components().insertPrivateProject();
    MetricDto dataMetric = dbTester.measures().insertMetric(m -> m.setValueType(DATA.name()).setKey("data"));
    MetricDto distribMetric = dbTester.measures().insertMetric(m -> m.setValueType(DISTRIB.name()).setKey("distrib"));
    MetricDto stringMetric = dbTester.measures().insertMetric(m -> m.setValueType(STRING.name()).setKey("string"));
    dbTester.measures().insertLiveMeasure(project, dataMetric, m -> m.setData("dat"));
    dbTester.measures().insertLiveMeasure(project, distribMetric, m -> m.setData("dis"));
    dbTester.measures().insertLiveMeasure(project, stringMetric, m -> m.setData("str"));
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
    assertThat(docsById.get(project.uuid()).getMeasures().getNumericMeasures()).isEmpty();
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 12 with ProjectMeasures

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures in project sonarqube by SonarSource.

the class ProjectMeasuresIndexerIteratorTest method non_main_branches_are_not_indexed.

@Test
public void non_main_branches_are_not_indexed() {
    ComponentDto project = dbTester.components().insertPrivateProject();
    MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc"));
    dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(10d));
    ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey("feature/foo"));
    dbTester.measures().insertLiveMeasure(branch, metric, m -> m.setValue(20d));
    Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById();
    assertThat(docsById).hasSize(1).containsOnlyKeys(project.uuid());
    assertThat(docsById.get(project.uuid()).getMeasures().getNumericMeasures().get(metric.getKey())).isEqualTo(10d);
}
Also used : MetricDto(org.sonar.db.metric.MetricDto) ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 13 with ProjectMeasures

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures in project sonarqube by SonarSource.

the class ProjectMeasuresIndexer method doIndex.

private void doIndex(Size size, @Nullable String projectUuid) {
    try (DbSession dbSession = dbClient.openSession(false);
        ProjectMeasuresIndexerIterator rowIt = ProjectMeasuresIndexerIterator.create(dbSession, projectUuid)) {
        BulkIndexer bulkIndexer = createBulkIndexer(size, IndexingListener.FAIL_ON_ERROR);
        bulkIndexer.start();
        while (rowIt.hasNext()) {
            ProjectMeasures doc = rowIt.next();
            bulkIndexer.add(toProjectMeasuresDoc(doc).toIndexRequest());
        }
        bulkIndexer.stop();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) ProjectMeasuresIndexerIterator(org.sonar.db.measure.ProjectMeasuresIndexerIterator) BulkIndexer(org.sonar.server.es.BulkIndexer)

Example 14 with ProjectMeasures

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures in project sonarqube by SonarSource.

the class ProjectMeasuresIndexer method doIndex.

private static void doIndex(BulkIndexer bulk, Iterator<ProjectMeasures> docs) {
    bulk.start();
    while (docs.hasNext()) {
        ProjectMeasures doc = docs.next();
        bulk.add(newIndexRequest(toProjectMeasuresDoc(doc)));
    }
    bulk.stop();
}
Also used : ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures)

Aggregations

ProjectMeasures (org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures)14 Test (org.junit.Test)12 ComponentDto (org.sonar.db.component.ComponentDto)12 MetricDto (org.sonar.db.metric.MetricDto)9 SnapshotDto (org.sonar.db.component.SnapshotDto)3 DbSession (org.sonar.db.DbSession)1 ProjectMeasuresIndexerIterator (org.sonar.db.measure.ProjectMeasuresIndexerIterator)1 BulkIndexer (org.sonar.server.es.BulkIndexer)1