Skip to content

Commit c9eb0a7

Browse files
committed
ActiveMqIntegrationTest converted
1 parent f3bac7e commit c9eb0a7

File tree

2 files changed

+40
-52
lines changed

2 files changed

+40
-52
lines changed

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

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package io.opentelemetry.contrib.jmxscraper.target_systems;
77

8-
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertGaugeWithAttributes;
9-
import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes;
108
import static org.assertj.core.api.Assertions.entry;
119

1210
import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer;
@@ -39,112 +37,86 @@ protected JmxScraperContainer customizeScraperContainer(
3937
}
4038

4139
@Override
42-
protected void verifyMetrics() {
43-
waitAndAssertMetrics(
44-
metric ->
45-
assertSumWithAttributes(
46-
metric,
40+
protected MetricsVerifier createMetricsVerifier() {
41+
return MetricsVerifier.create()
42+
.assertUpDownCounterWithAttributes(
4743
"activemq.consumer.count",
4844
"The number of consumers currently reading from the broker.",
4945
"{consumer}",
50-
/* isMonotonic= */ false,
5146
attrs ->
5247
attrs.containsOnly(
5348
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
54-
entry("broker", "localhost"))),
55-
metric ->
56-
assertSumWithAttributes(
57-
metric,
49+
entry("broker", "localhost")))
50+
.assertUpDownCounterWithAttributes(
5851
"activemq.producer.count",
5952
"The number of producers currently attached to the broker.",
6053
"{producer}",
61-
/* isMonotonic= */ false,
6254
attrs ->
6355
attrs.containsOnly(
6456
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
65-
entry("broker", "localhost"))),
66-
metric ->
67-
assertSumWithAttributes(
68-
metric,
57+
entry("broker", "localhost")))
58+
.assertUpDownCounterWithAttributes(
6959
"activemq.connection.count",
7060
"The total number of current connections.",
7161
"{connection}",
72-
/* isMonotonic= */ false,
73-
attrs -> attrs.containsOnly(entry("broker", "localhost"))),
74-
metric ->
75-
assertGaugeWithAttributes(
76-
metric,
62+
attrs -> attrs.containsOnly(entry("broker", "localhost")))
63+
.assertGaugeWithAttributes(
7764
"activemq.memory.usage",
7865
"The percentage of configured memory used.",
7966
"%",
8067
attrs ->
8168
attrs.containsOnly(
8269
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
83-
entry("broker", "localhost"))),
84-
metric ->
85-
assertGaugeWithAttributes(
86-
metric,
70+
entry("broker", "localhost")))
71+
.assertGaugeWithAttributes(
8772
"activemq.disk.store_usage",
8873
"The percentage of configured disk used for persistent messages.",
8974
"%",
90-
attrs -> attrs.containsOnly(entry("broker", "localhost"))),
91-
metric ->
92-
assertGaugeWithAttributes(
93-
metric,
75+
attrs -> attrs.containsOnly(entry("broker", "localhost")))
76+
.assertGaugeWithAttributes(
9477
"activemq.disk.temp_usage",
9578
"The percentage of configured disk used for non-persistent messages.",
9679
"%",
97-
attrs -> attrs.containsOnly(entry("broker", "localhost"))),
98-
metric ->
99-
assertSumWithAttributes(
100-
metric,
80+
attrs -> attrs.containsOnly(entry("broker", "localhost")))
81+
.assertUpDownCounterWithAttributes(
10182
"activemq.message.current",
10283
"The current number of messages waiting to be consumed.",
10384
"{message}",
104-
/* isMonotonic= */ false,
10585
attrs ->
10686
attrs.containsOnly(
10787
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
108-
entry("broker", "localhost"))),
109-
metric ->
110-
assertSumWithAttributes(
111-
metric,
88+
entry("broker", "localhost")))
89+
.assertCounterWithAttributes(
11290
"activemq.message.expired",
11391
"The total number of messages not delivered because they expired.",
11492
"{message}",
11593
attrs ->
11694
attrs.containsOnly(
11795
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
118-
entry("broker", "localhost"))),
119-
metric ->
120-
assertSumWithAttributes(
121-
metric,
96+
entry("broker", "localhost")))
97+
.assertCounterWithAttributes(
12298
"activemq.message.enqueued",
12399
"The total number of messages received by the broker.",
124100
"{message}",
125101
attrs ->
126102
attrs.containsOnly(
127103
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
128-
entry("broker", "localhost"))),
129-
metric ->
130-
assertSumWithAttributes(
131-
metric,
104+
entry("broker", "localhost")))
105+
.assertCounterWithAttributes(
132106
"activemq.message.dequeued",
133107
"The total number of messages delivered to consumers.",
134108
"{message}",
135109
attrs ->
136110
attrs.containsOnly(
137111
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
138-
entry("broker", "localhost"))),
139-
metric ->
140-
assertGaugeWithAttributes(
141-
metric,
112+
entry("broker", "localhost")))
113+
.assertGaugeWithAttributes(
142114
"activemq.message.wait_time.avg",
143115
"The average time a message was held on a destination.",
144116
"ms",
145117
attrs ->
146118
attrs.containsOnly(
147119
entry("destination", "ActiveMQ.Advisory.MasterBroker"),
148-
entry("broker", "localhost"))));
120+
entry("broker", "localhost")));
149121
}
150122
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ public MetricsVerifier assertUpDownCounter(String metricName, String description
7474
return assertSum(metricName, description, unit, /* isMonotonic= */ false);
7575
}
7676

77+
@SafeVarargs
78+
@SuppressWarnings("CanIgnoreReturnValueSuggester")
79+
public final MetricsVerifier assertGaugeWithAttributes(String metricName, String description,
80+
String unit, Consumer<MapAssert<String, String>>... attributeGroupAssertions) {
81+
assertions.put(
82+
metricName,
83+
metric -> {
84+
assertDescription(metric, description);
85+
assertUnit(metric, unit);
86+
assertMetricWithGauge(metric);
87+
assertAttributedPoints(metricName, metric.getGauge().getDataPointsList(), attributeGroupAssertions);
88+
});
89+
90+
return this;
91+
}
92+
7793
@SafeVarargs
7894
@SuppressWarnings("CanIgnoreReturnValueSuggester")
7995
public final MetricsVerifier assertCounterWithAttributes(

0 commit comments

Comments
 (0)