|
|
@@ -8,8 +8,6 @@ import org.junit.jupiter.api.Test;
|
|
|
|
|
|
import java.time.OffsetDateTime;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
@@ -17,30 +15,33 @@ import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
class ThresholdCheckerTest {
|
|
|
|
|
|
- private static final Sensor SOURCE = new Sensor(100L, 100000L, 10343L, 10L);
|
|
|
+ private static final Sensor SENSOR = new Sensor(100L, 1000L, 1001L);
|
|
|
|
|
|
@Test
|
|
|
void check_size_1_INSTANT() {
|
|
|
|
|
|
ThresholdChecker<Observation> checker = new ThresholdChecker<>(
|
|
|
List.of(
|
|
|
- new Threshold(SOURCE.id(), NotifyTrigger.Type.INSTANT, true, AttributeName.VAL, List.of(new ThresholdRule("gt", 10.0)))
|
|
|
+ new Threshold(1, SENSOR.id(), NotifyTrigger.Mode.INSTANT, AttributeType.VAL, true, false, List.of(
|
|
|
+ new ThresholdRule(ThresholdMode.GT, 10.0)
|
|
|
+ ))
|
|
|
),
|
|
|
Validator.<Observation>create()
|
|
|
- .addMapping(AttributeName.VAL, o -> o::value),
|
|
|
+ .addMapping(AttributeType.VAL, o -> o::value),
|
|
|
(report) -> {
|
|
|
- assertEquals(SOURCE.id(), report.sourceId());
|
|
|
+ assertEquals(SENSOR.id(), report.datasourceId());
|
|
|
assertEquals(1, report.violatedData().length);
|
|
|
ValidationResult valResult = report.violatedData()[0];
|
|
|
- assertEquals(AttributeName.VAL, valResult.attribute());
|
|
|
- assertEquals(25.3, valResult.validatedValue());
|
|
|
+ assertEquals(AttributeType.VAL, valResult.attributeType());
|
|
|
+ assertEquals(23.3, valResult.validatedValue());
|
|
|
assertEquals(1, valResult.records().size());
|
|
|
- }
|
|
|
+ },
|
|
|
+ true
|
|
|
);
|
|
|
|
|
|
long count = Stream.of(
|
|
|
- Observation.of(SOURCE, 25.3, OffsetDateTime.now())
|
|
|
- ).filter(checker.check()).count();
|
|
|
+ Observation.of(SENSOR, RawObservation.of(SENSOR.unitId(), SENSOR.sensorId(), 23.3, OffsetDateTime.now()))
|
|
|
+ ).filter(checker::check).count();
|
|
|
assertEquals(1, count);
|
|
|
}
|
|
|
|
|
|
@@ -49,25 +50,28 @@ class ThresholdCheckerTest {
|
|
|
|
|
|
ThresholdChecker<Observation> checker = new ThresholdChecker<>(
|
|
|
List.of(
|
|
|
- new Threshold(SOURCE.id(), NotifyTrigger.Type.ON_CHANGE, true, AttributeName.VAL, List.of(new ThresholdRule("gt", 10.0)))
|
|
|
+ new Threshold(1, SENSOR.id(), NotifyTrigger.Mode.ON_CHANGE, AttributeType.VAL, true, false, List.of(
|
|
|
+ new ThresholdRule(ThresholdMode.GT, 10.0)
|
|
|
+ ))
|
|
|
),
|
|
|
Validator.<Observation>create()
|
|
|
- .addMapping(AttributeName.VAL, o -> o::value),
|
|
|
+ .addMapping(AttributeType.VAL, o -> o::value),
|
|
|
(report) -> {
|
|
|
- assertEquals(SOURCE.id(), report.sourceId());
|
|
|
+ assertEquals(SENSOR.id(), report.datasourceId());
|
|
|
assertEquals(1, report.violatedData().length);
|
|
|
ValidationResult valResult = report.violatedData()[0];
|
|
|
- assertEquals(AttributeName.VAL, valResult.attribute());
|
|
|
+ assertEquals(AttributeType.VAL, valResult.attributeType());
|
|
|
assertEquals(25.3, valResult.validatedValue());
|
|
|
assertEquals(1, valResult.records().size());
|
|
|
- }
|
|
|
+ },
|
|
|
+ true
|
|
|
);
|
|
|
|
|
|
long count = Stream.of(
|
|
|
- Observation.of(SOURCE, 9.9, OffsetDateTime.now()),
|
|
|
- Observation.of(SOURCE, 25.3, OffsetDateTime.now()),
|
|
|
- Observation.of(SOURCE, 30.5, OffsetDateTime.now())
|
|
|
- ).filter(checker.check()).count();
|
|
|
+ Observation.of(SENSOR, RawObservation.of(SENSOR.unitId(), SENSOR.sensorId(),9.9, OffsetDateTime.now())),
|
|
|
+ Observation.of(SENSOR, RawObservation.of(SENSOR.unitId(), SENSOR.sensorId(),25.3, OffsetDateTime.now())),
|
|
|
+ Observation.of(SENSOR, RawObservation.of(SENSOR.unitId(), SENSOR.sensorId(),30.5, OffsetDateTime.now()))
|
|
|
+ ).filter(checker::check).count();
|
|
|
assertEquals(3, count);
|
|
|
}
|
|
|
|
|
|
@@ -76,15 +80,17 @@ class ThresholdCheckerTest {
|
|
|
AtomicInteger reportStep = new AtomicInteger(1);
|
|
|
ThresholdChecker<Observation> checker = new ThresholdChecker<>(
|
|
|
List.of(
|
|
|
- new Threshold(SOURCE.id(), NotifyTrigger.Type.ON_CHANGE, true, AttributeName.VAL, List.of(new ThresholdRule("gt", 10.0)))
|
|
|
+ new Threshold(1, SENSOR.id(), NotifyTrigger.Mode.ON_CHANGE, AttributeType.VAL, true, false, List.of(
|
|
|
+ new ThresholdRule(ThresholdMode.GT, 10.0)
|
|
|
+ ))
|
|
|
),
|
|
|
Validator.<Observation>create()
|
|
|
- .addMapping(AttributeName.VAL, o -> o::value),
|
|
|
+ .addMapping(AttributeType.VAL, o -> o::value),
|
|
|
(report) -> {
|
|
|
- assertEquals(SOURCE.id(), report.sourceId());
|
|
|
+ assertEquals(SENSOR.id(), report.datasourceId());
|
|
|
assertEquals(1, report.violatedData().length);
|
|
|
ValidationResult valResult = report.violatedData()[0];
|
|
|
- assertEquals(AttributeName.VAL, valResult.attribute());
|
|
|
+ assertEquals(AttributeType.VAL, valResult.attributeType());
|
|
|
|
|
|
if (reportStep.compareAndSet(1, 2)) {
|
|
|
assertEquals(25.3, valResult.validatedValue());
|
|
|
@@ -96,56 +102,58 @@ class ThresholdCheckerTest {
|
|
|
assertTrue(valResult.isValid());
|
|
|
assertEquals(0, valResult.records().size());
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ true
|
|
|
);
|
|
|
|
|
|
long count = Stream.of(
|
|
|
- Observation.of(SOURCE, 9.9, OffsetDateTime.now()),
|
|
|
- Observation.of(SOURCE, 25.3, OffsetDateTime.now()),
|
|
|
- Observation.of(SOURCE, 30.5, OffsetDateTime.now()),
|
|
|
- Observation.of(SOURCE, 8.5, OffsetDateTime.now())
|
|
|
- ).filter(checker.check()).count();
|
|
|
+ Observation.of(SENSOR, RawObservation.of(SENSOR.unitId(), SENSOR.sensorId(), 9.9, OffsetDateTime.now())),
|
|
|
+ Observation.of(SENSOR, RawObservation.of(SENSOR.unitId(), SENSOR.sensorId(), 25.3, OffsetDateTime.now())),
|
|
|
+ Observation.of(SENSOR, RawObservation.of(SENSOR.unitId(), SENSOR.sensorId(),30.5, OffsetDateTime.now())),
|
|
|
+ Observation.of(SENSOR, RawObservation.of(SENSOR.unitId(), SENSOR.sensorId(), 8.5, OffsetDateTime.now()))
|
|
|
+ ).filter(checker::check).count();
|
|
|
assertEquals(4, count);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
void check_doubleStatistics_INSTANT() {
|
|
|
- long sourceId = SOURCE.groupId();
|
|
|
+ long datasourceId = SENSOR.id();
|
|
|
|
|
|
ThresholdChecker<DoubleStatistics> checker = new ThresholdChecker<>(
|
|
|
List.of(
|
|
|
- new Threshold(sourceId, NotifyTrigger.Type.INSTANT, true, AttributeName.MIN, List.of(new ThresholdRule("lt", 0.0))),
|
|
|
- new Threshold(sourceId, NotifyTrigger.Type.INSTANT, true, AttributeName.MAX, List.of(new ThresholdRule("gt", 5.0)))
|
|
|
+ new Threshold(1, -1, NotifyTrigger.Mode.INSTANT, AttributeType.MIN, true, false, List.of(new ThresholdRule(ThresholdMode.LT, 0.0))),
|
|
|
+ new Threshold(1, -1, NotifyTrigger.Mode.INSTANT, AttributeType.MAX, true, false, List.of(new ThresholdRule(ThresholdMode.GT, 5.0)))
|
|
|
),
|
|
|
Validator.<DoubleStatistics>create()
|
|
|
- .addMapping(AttributeName.MIN, s -> s::min)
|
|
|
- .addMapping(AttributeName.MAX, s -> s::max)
|
|
|
- .addMapping(AttributeName.AVG, s -> s::average),
|
|
|
+ .addMapping(AttributeType.MIN, s -> s::min)
|
|
|
+ .addMapping(AttributeType.MAX, s -> s::max)
|
|
|
+ .addMapping(AttributeType.AVG, s -> s::average),
|
|
|
(report) -> {
|
|
|
- assertEquals(sourceId, report.sourceId());
|
|
|
+ assertEquals(datasourceId, report.datasourceId());
|
|
|
assertEquals(2, report.violatedData().length);
|
|
|
ValidationResult[] violatedData = report.violatedData();
|
|
|
- ValidationResult minResult = violatedData[0].attribute().equals(AttributeName.MIN) ? violatedData[0] : violatedData[1];
|
|
|
- ValidationResult maxResult = violatedData[0].attribute().equals(AttributeName.MAX) ? violatedData[0] : violatedData[1];
|
|
|
+ ValidationResult minResult = violatedData[0].attributeType().equals(AttributeType.MIN) ? violatedData[0] : violatedData[1];
|
|
|
+ ValidationResult maxResult = violatedData[0].attributeType().equals(AttributeType.MAX) ? violatedData[0] : violatedData[1];
|
|
|
|
|
|
- assertEquals(AttributeName.MIN, minResult.attribute());
|
|
|
+ assertEquals(AttributeType.MIN, minResult.attributeType());
|
|
|
assertEquals(-1.5, minResult.validatedValue());
|
|
|
assertEquals(1, minResult.records().size());
|
|
|
|
|
|
- assertEquals(AttributeName.MAX, maxResult.attribute());
|
|
|
+ assertEquals(AttributeType.MAX, maxResult.attributeType());
|
|
|
assertEquals(5.2, maxResult.validatedValue());
|
|
|
assertEquals(1, maxResult.records().size());
|
|
|
- }
|
|
|
+ },
|
|
|
+ true
|
|
|
);
|
|
|
|
|
|
- DoubleStatistics ds = DoubleStatistics.init(sourceId, OffsetDateTime.now());
|
|
|
- ds.accept(sourceId, -1.5);
|
|
|
- ds.accept(sourceId, 3.3);
|
|
|
- ds.accept(sourceId, 5.2);
|
|
|
+ DoubleStatistics ds = DoubleStatistics.init(datasourceId, OffsetDateTime.now());
|
|
|
+ ds.accept(datasourceId, -1.5);
|
|
|
+ ds.accept(datasourceId, 3.3);
|
|
|
+ ds.accept(datasourceId, 5.2);
|
|
|
|
|
|
|
|
|
long count = Stream.of(ds)
|
|
|
- .filter(checker.check()).count();
|
|
|
+ .filter(checker::check).count();
|
|
|
assertEquals(1, count);
|
|
|
}
|
|
|
}
|