Skip to content

Commit 591f03d

Browse files
committed
chore: check that metadata is updated when using synthetic components
1 parent a5ffdc7 commit 591f03d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

measure/src/test/java/net/laprun/sustainability/power/measure/OngoingPowerMeasureTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ public double synthesizeFrom(double[] components, long timestamp) {
121121
final var measure = new OngoingPowerMeasure(metadata, doubler);
122122
final var testProc = new TestComponentProcessor();
123123
// need to get updated metadata
124-
final var doublerIndex = measure.metadata().metadataFor(doublerName).index();
124+
final var updatedMetadata = measure.metadata();
125+
assertThat(updatedMetadata.componentCardinality()).isEqualTo(metadata.componentCardinality() + 1);
126+
final var doublerIndex = updatedMetadata.metadataFor(doublerName).index();
127+
assertThat(doublerIndex).isEqualTo(metadata.componentCardinality());
125128
measure.registerProcessorFor(doublerIndex, testProc);
126129

127130
final var components = new double[metadata.componentCardinality()];
@@ -133,6 +136,7 @@ public double synthesizeFrom(double[] components, long timestamp) {
133136

134137
assertThat(testProc.values.getFirst().value()).isEqualTo(m1c1 * 2);
135138
assertThat(testProc.values.getLast().value()).isEqualTo(m2c1 * 2);
139+
assertThat(PowerMeasure.asString(measure)).contains("doubler", testProc.values.toString());
136140
}
137141

138142
private static class TestComponentProcessor implements ComponentProcessor {
@@ -142,6 +146,11 @@ private static class TestComponentProcessor implements ComponentProcessor {
142146
public void recordComponentValue(double value, long timestamp) {
143147
values.add(new PowerMeasure.TimestampedValue(timestamp, value));
144148
}
149+
150+
@Override
151+
public String output() {
152+
return values.toString();
153+
}
145154
}
146155

147156
private static class TestMeasureProcessor implements MeasureProcessor {

0 commit comments

Comments
 (0)