Skip to content

Commit 4b257f0

Browse files
committed
CAMEL-23223 - improve assertion failure message to help investigation on
flaky test ManagedMessageHistoryAutoConfigIT instead of ``` org.opentest4j.AssertionFailedError: expected: <true> but was: <false> ``` there will now be a message like: ``` ManagedMessageHistoryAutoConfigIT.testMessageHistory:120->assertMetricDataHasNodeId:130 Expecting any elements of: [ImmutableHistogramPointData{getStartEpochNanos=1776755336333536296, getEpochNanos=1776755336415229081, getAttributes={camelContext="camel-1", kind="CamelMessageHistory", nodeId="foo", routeId="route1"}, getSum=1.0, getCount=5, hasMin=true, getMin=0.0, hasMax=true, getMax=1.0, getBoundaries=[0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0], getCounts=[4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], getExemplars=[]}, ImmutableHistogramPointData{getStartEpochNanos=1776755336333480676, getEpochNanos=1776755336415229081, getAttributes={camelContext="camel-1", kind="CamelMessageHistory", nodeId="bar", routeId="route2"}, getSum=1.0, getCount=5, hasMin=true, getMin=0.0, hasMax=true, getMax=1.0, getBoundaries=[0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0], getCounts=[4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], getExemplars=[]}, ImmutableHistogramPointData{getStartEpochNanos=1776755336334308001, getEpochNanos=1776755336415229081, getAttributes={camelContext="camel-1", kind="CamelMessageHistory", nodeId="baz", routeId="route2"}, getSum=0.0, getCount=5, hasMin=true, getMin=0.0, hasMax=true, getMax=0.0, getBoundaries=[0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0], getCounts=[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], getExemplars=[]}] to match 'No metric data found for node invalidToCheckErrorMessageof route route2 ' predicate but none did. ``` Signed-off-by: Aurélien Pupier <apupier@ibm.com>
1 parent 2de2902 commit 4b257f0

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

components/camel-opentelemetry-metrics/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
<artifactId>opentelemetry-exporter-logging</artifactId>
8585
<scope>test</scope>
8686
</dependency>
87+
<dependency>
88+
<groupId>org.assertj</groupId>
89+
<artifactId>assertj-core</artifactId>
90+
<scope>test</scope>
91+
</dependency>
8792
</dependencies>
8893

8994
<profiles>

components/camel-opentelemetry-metrics/src/test/java/org/apache/camel/opentelemetry/metrics/integration/messagehistory/ManagedMessageHistoryAutoConfigIT.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import static org.apache.camel.opentelemetry.metrics.OpenTelemetryConstants.DEFAULT_CAMEL_MESSAGE_HISTORY_METER_NAME;
4444
import static org.apache.camel.opentelemetry.metrics.OpenTelemetryConstants.ROUTE_ID_ATTRIBUTE;
45+
import static org.assertj.core.api.Assertions.assertThat;
4546
import static org.awaitility.Awaitility.await;
4647
import static org.junit.jupiter.api.Assertions.assertEquals;
4748
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -113,20 +114,22 @@ public void testMessageHistory() throws Exception {
113114

114115
assertPointDataForRouteId(metricData, "route1");
115116

116-
assertTrue(verifyMetricDataHasNodeId(metricData, "route1", "foo"));
117-
assertTrue(verifyMetricDataHasNodeId(metricData, "route2", "bar"));
118-
assertTrue(verifyMetricDataHasNodeId(metricData, "route2", "baz"));
117+
assertMetricDataHasNodeId(metricData, "route1", "foo");
118+
assertMetricDataHasNodeId(metricData, "route2", "bar");
119+
assertMetricDataHasNodeId(metricData, "route2", "baz");
119120

120121
dataCount++;
121122
}
122123
}
123124
assertTrue(dataCount > 0, "No metric data found");
124125
}
125126

126-
private boolean verifyMetricDataHasNodeId(MetricData metricData, String routeId, String nodeId) {
127-
return metricData.getData().getPoints().stream()
128-
.filter(point -> routeId.equals(getRouteId(point)))
129-
.anyMatch(point -> nodeId.equals(point.getAttributes().get(AttributeKey.stringKey("nodeId"))));
127+
private void assertMetricDataHasNodeId(MetricData metricData, String routeId, String nodeId) {
128+
assertThat(metricData.getData().getPoints())
129+
.anyMatch(point -> {
130+
return routeId.equals(getRouteId(point))
131+
&& nodeId.equals(point.getAttributes().get(AttributeKey.stringKey("nodeId")));
132+
}, "No metric data found for node " + nodeId + "of route " + routeId + " ");
130133
}
131134

132135
private void assertPointDataForRouteId(MetricData metricData, String routeId) {

0 commit comments

Comments
 (0)