Skip to content

Commit f3bac7e

Browse files
committed
Fine tuning assertion messages.
Method names improvement.
1 parent 8cb96ad commit f3bac7e

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/JvmIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ protected MetricsVerifier createMetricsVerifier() {
4646

4747
return MetricsVerifier.create()
4848
.assertGauge("jvm.classes.loaded", "number of loaded classes", "1")
49-
.assertTypedSum(
49+
.assertTypedCounter(
5050
"jvm.gc.collections.count",
5151
"total number of collections that have occurred",
5252
"1",
5353
gcCollectionLabels)
54-
.assertTypedSum(
54+
.assertTypedCounter(
5555
"jvm.gc.collections.elapsed",
5656
"the approximate accumulated collection elapsed time in milliseconds",
5757
"ms",

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/MetricsVerifier.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,8 @@ public final MetricsVerifier assertUpDownCounterWithAttributes(
9696
metricName, description, unit, /* isMonotonic= */ false, attributeGroupAssertions);
9797
}
9898

99-
@SafeVarargs
100-
@SuppressWarnings("CanIgnoreReturnValueSuggester")
101-
private final MetricsVerifier assertSumWithAttributes(
102-
String metricName,
103-
String description,
104-
String unit,
105-
boolean isMonotonic,
106-
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
107-
assertions.put(
108-
metricName,
109-
metric -> {
110-
assertDescription(metric, description);
111-
assertUnit(metric, unit);
112-
assertMetricWithSum(metric, isMonotonic);
113-
assertAttributedPoints(
114-
metricName, metric.getSum().getDataPointsList(), attributeGroupAssertions);
115-
});
116-
117-
return this;
118-
}
119-
12099
@SuppressWarnings("CanIgnoreReturnValueSuggester")
121-
public MetricsVerifier assertTypedSum(
100+
public MetricsVerifier assertTypedCounter(
122101
String metricName, String description, String unit, List<String> types) {
123102
assertions.put(
124103
metricName,
@@ -164,7 +143,7 @@ public void verify(List<Metric> metrics) {
164143
}
165144

166145
if (strictMode && !unverifiedMetrics.isEmpty()) {
167-
fail("The following metrics were received but not verified: " + unverifiedMetrics);
146+
fail("Metrics received but not verified because no assertion exists: " + unverifiedMetrics);
168147
}
169148
}
170149

@@ -176,7 +155,7 @@ private void verifyAllExpectedMetricsWereReceived(List<Metric> metrics) {
176155

177156
assertionNames.removeAll(receivedMetricNames);
178157
if (!assertionNames.isEmpty()) {
179-
fail("The following metrics were expected but not received: " + assertionNames);
158+
fail("Metrics expected but not received: " + assertionNames);
180159
}
181160
}
182161

@@ -196,6 +175,27 @@ private MetricsVerifier assertSum(
196175
return this;
197176
}
198177

178+
@SafeVarargs
179+
@SuppressWarnings("CanIgnoreReturnValueSuggester")
180+
private final MetricsVerifier assertSumWithAttributes(
181+
String metricName,
182+
String description,
183+
String unit,
184+
boolean isMonotonic,
185+
Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
186+
assertions.put(
187+
metricName,
188+
metric -> {
189+
assertDescription(metric, description);
190+
assertUnit(metric, unit);
191+
assertMetricWithSum(metric, isMonotonic);
192+
assertAttributedPoints(
193+
metricName, metric.getSum().getDataPointsList(), attributeGroupAssertions);
194+
});
195+
196+
return this;
197+
}
198+
199199
private static void assertMetricWithGauge(Metric metric) {
200200
assertThat(metric.hasGauge()).withFailMessage("Metric with gauge expected").isTrue();
201201
}

0 commit comments

Comments
 (0)