Skip to content

Commit 2279e00

Browse files
committed
refactor a bit test
1 parent 37cf457 commit 2279e00

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

instrumentation/jmx-metrics/library/src/test/java/io/opentelemetry/instrumentation/jmx/engine/MetricAggregationTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ void singleInstance() throws Exception {
102102
ObjectName bean = getObjectName(null, null);
103103
theServer.registerMBean(new Hello(42), bean);
104104

105-
testMetric(bean.toString(), 42);
105+
Collection<MetricData> data = testMetric(bean.toString());
106+
checkSingleValue(data, 42);
106107
}
107108

108109
@Test
@@ -111,7 +112,8 @@ void multipleInstancesAggregated_twoInstances() throws Exception {
111112
theServer.registerMBean(new Hello(37), getObjectName("value2", null));
112113

113114
String bean = getObjectName("*", null).toString();
114-
testMetric(bean, 79);
115+
Collection<MetricData> data = testMetric(bean);
116+
checkSingleValue(data, 79);
115117
}
116118

117119
@Test
@@ -122,10 +124,11 @@ void multipleInstancesAggregated_fourInstances() throws Exception {
122124
theServer.registerMBean(new Hello(5), getObjectName("4", "b"));
123125

124126
String bean = getObjectName("*", "*").toString();
125-
testMetric(bean, 11);
127+
Collection<MetricData> data = testMetric(bean);
128+
checkSingleValue(data, 11);
126129
}
127130

128-
void testMetric(String mbean, int expectedValue) throws MalformedObjectNameException {
131+
private Collection<MetricData> testMetric(String mbean) throws MalformedObjectNameException {
129132
JmxMetricInsight metricInsight = JmxMetricInsight.createService(sdk, 0);
130133
MetricConfiguration metricConfiguration = new MetricConfiguration();
131134
List<MetricExtractor> extractors = new ArrayList<>();
@@ -142,8 +145,10 @@ void testMetric(String mbean, int expectedValue) throws MalformedObjectNameExcep
142145
metricConfiguration.addMetricDef(metricDef);
143146
metricInsight.startLocal(metricConfiguration);
144147

145-
Collection<MetricData> data = waitMetricsReceived();
148+
return waitMetricsReceived();
149+
}
146150

151+
private static void checkSingleValue(Collection<MetricData> data, int expectedValue) {
147152
assertThat(data)
148153
.isNotEmpty()
149154
.satisfiesExactlyInAnyOrder(

0 commit comments

Comments
 (0)