private void changeCell(ComponentDto component, String metricKey, Function<LiveMeasureDto, Boolean> changer) { MeasureCell cell = table.get(component.uuid(), metricKey); if (cell == null) { LiveMeasureDto measure = new LiveMeasureDto() .setComponentUuid(component.uuid()) .setProjectUuid(component.projectUuid()) .setMetricId(metricsByKeys.get(metricKey).getId()); cell = new MeasureCell(measure, true); table.put(component.uuid(), metricKey, cell); changer.apply(cell.getMeasure()); } else if (changer.apply(cell.getMeasure())) { cell.setChanged(true); } }
public static LiveMeasureDto newLiveMeasure() { return new LiveMeasureDto() .setMetricId(cursor++) .setComponentUuid(String.valueOf(cursor++)) .setProjectUuid(String.valueOf(cursor++)) .setData(String.valueOf(cursor++)) .setValue((double) cursor++) .setVariation((double) cursor++); }
@Test public void deleteByComponentUuidExcludingMetricIds_with_empty_metrics() { LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1); LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2); LiveMeasureDto measureOnOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(2); underTest.insertOrUpdate(db.getSession(), measure1); underTest.insertOrUpdate(db.getSession(), measure2); underTest.insertOrUpdate(db.getSession(), measureOnOtherComponent); int count = underTest.deleteByComponentUuidExcludingMetricIds(db.getSession(), "C1", Collections.emptyList()); assertThat(count).isEqualTo(2); verifyTableSize(1); verifyPersisted(measureOnOtherComponent); }
private LiveMeasureDto newMeasure(MetricDto metric, ComponentDto component) { return new LiveMeasureDto().setMetricId(metric.getId()).setData("foo").setComponentUuid(component.uuid()); } }
@Test public void deleteByComponentUuidExcludingMetricIds() { LiveMeasureDto measure1 = newLiveMeasure().setComponentUuid("C1").setMetricId(1); LiveMeasureDto measure2 = newLiveMeasure().setComponentUuid("C1").setMetricId(2); LiveMeasureDto measure3 = newLiveMeasure().setComponentUuid("C1").setMetricId(3); LiveMeasureDto measureOtherComponent = newLiveMeasure().setComponentUuid("C2").setMetricId(3); underTest.insertOrUpdate(db.getSession(), measure1); underTest.insertOrUpdate(db.getSession(), measure2); underTest.insertOrUpdate(db.getSession(), measure3); underTest.insertOrUpdate(db.getSession(), measureOtherComponent); int count = underTest.deleteByComponentUuidExcludingMetricIds(db.getSession(), "C1", Arrays.asList(1, 2)); verifyTableSize(3); verifyPersisted(measure1); verifyPersisted(measure2); verifyPersisted(measureOtherComponent); assertThat(count).isEqualTo(1); }
public LiveMeasureDto toLiveMeasureDto(Measure measure, Metric metric, Component component) { LiveMeasureDto out = new LiveMeasureDto(); out.setMetricId(metric.getId()); out.setComponentUuid(component.getUuid()); out.setProjectUuid(treeRootHolder.getRoot().getUuid()); if (measure.hasVariation()) { out.setVariation(measure.getVariation()); } out.setValue(valueAsDouble(measure)); out.setData(data(measure)); return out; }
public static LiveMeasureDto newLiveMeasure(ComponentDto component, MetricDto metric) { return new LiveMeasureDto() .setMetricId(metric.getId()) .setComponentUuid(component.uuid()) .setProjectUuid(component.projectUuid()) .setData(String.valueOf(cursor++)) .setValue((double) cursor++) .setVariation((double) cursor++); } }
@Test public void refreshGateStatus_provides_measures_to_evaluator() { ComponentDto project = ComponentTesting.newPublicProjectDto(newOrganizationDto()); MetricDto numericMetric = newMetricDto().setValueType(Metric.ValueType.FLOAT.name()); MetricDto numericNewMetric = newMetricDto().setValueType(Metric.ValueType.FLOAT.name()).setKey("new_metric"); MetricDto stringMetric = newMetricDto().setValueType(Metric.ValueType.STRING.name()); MetricDto statusMetric = newMetricDto().setKey(CoreMetrics.ALERT_STATUS_KEY); MetricDto detailsMetric = newMetricDto().setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY); QualityGate gate = new QualityGate("1", "foo", Collections.emptySet()); LiveMeasureDto numericMeasure = new LiveMeasureDto().setMetricId(numericMetric.getId()).setValue(1.23).setVariation(4.56).setComponentUuid(project.uuid()); LiveMeasureDto numericNewMeasure = new LiveMeasureDto().setMetricId(numericNewMetric.getId()).setValue(7.8).setVariation(8.9).setComponentUuid(project.uuid()); LiveMeasureDto stringMeasure = new LiveMeasureDto().setMetricId(stringMetric.getId()).setData("bar").setComponentUuid(project.uuid()); MeasureMatrix matrix = new MeasureMatrix(singleton(project), asList(statusMetric, detailsMetric, numericMetric, numericNewMetric, stringMetric), asList(numericMeasure, numericNewMeasure, stringMeasure)); underTest.refreshGateStatus(project, gate, matrix); QualityGateEvaluator.Measures measures = qualityGateEvaluator.getCalledMeasures(); QualityGateEvaluator.Measure loadedStringMeasure = measures.get(stringMetric.getKey()).get(); assertThat(loadedStringMeasure.getStringValue()).hasValue("bar"); assertThat(loadedStringMeasure.getValue()).isEmpty(); assertThat(loadedStringMeasure.getType()).isEqualTo(Metric.ValueType.STRING); QualityGateEvaluator.Measure loadedNumericMeasure = measures.get(numericMetric.getKey()).get(); assertThat(loadedNumericMeasure.getStringValue()).isEmpty(); assertThat(loadedNumericMeasure.getValue()).hasValue(1.23); assertThat(loadedNumericMeasure.getType()).isEqualTo(Metric.ValueType.FLOAT); QualityGateEvaluator.Measure loadedNumericNewMeasure = measures.get(numericNewMetric.getKey()).get(); assertThat(loadedNumericNewMeasure.getStringValue()).isEmpty(); assertThat(loadedNumericNewMeasure.getNewMetricValue()).hasValue(8.9); assertThat(loadedNumericNewMeasure.getType()).isEqualTo(Metric.ValueType.FLOAT); }
private LiveMeasureDto insertMeasure(String componentUuid, String projectUuid, Metric metric) { LiveMeasureDto measure = newLiveMeasure() .setComponentUuid(componentUuid) .setProjectUuid(projectUuid) .setMetricId(metricRepository.getByKey(metric.getKey()).getId()); dbClient.liveMeasureDao().insertOrUpdate(db.getSession(), measure); return measure; }
private void changeCell(ComponentDto component, String metricKey, Function<LiveMeasureDto, Boolean> changer) { MeasureCell cell = table.get(component.uuid(), metricKey); if (cell == null) { LiveMeasureDto measure = new LiveMeasureDto() .setComponentUuid(component.uuid()) .setProjectUuid(component.projectUuid()) .setMetricId(metricsByKeys.get(metricKey).getId()); cell = new MeasureCell(measure, true); table.put(component.uuid(), metricKey, cell); changer.apply(cell.getMeasure()); } else if (changer.apply(cell.getMeasure())) { cell.setChanged(true); } }
public LiveMeasureDto toLiveMeasureDto(Measure measure, Metric metric, Component component) { LiveMeasureDto out = new LiveMeasureDto(); out.setMetricId(metric.getId()); out.setComponentUuid(component.getUuid()); out.setProjectUuid(treeRootHolder.getRoot().getUuid()); if (measure.hasVariation()) { out.setVariation(measure.getVariation()); } out.setValue(valueAsDouble(measure)); out.setData(data(measure)); return out; }