66package io .opentelemetry .instrumentation .jmx .engine ;
77
88import static io .opentelemetry .sdk .testing .assertj .OpenTelemetryAssertions .assertThat ;
9+ import static org .assertj .core .groups .Tuple .tuple ;
910
11+ import io .opentelemetry .api .common .AttributeKey ;
12+ import io .opentelemetry .api .common .Attributes ;
1013import io .opentelemetry .sdk .OpenTelemetrySdk ;
1114import io .opentelemetry .sdk .metrics .SdkMeterProvider ;
1215import io .opentelemetry .sdk .metrics .data .LongPointData ;
1316import io .opentelemetry .sdk .metrics .data .MetricData ;
17+ import io .opentelemetry .sdk .metrics .data .PointData ;
1418import io .opentelemetry .sdk .testing .exporter .InMemoryMetricReader ;
1519import java .util .ArrayList ;
1620import java .util .Collection ;
2327import javax .management .MBeanServerFactory ;
2428import javax .management .MalformedObjectNameException ;
2529import javax .management .ObjectName ;
26- import org .assertj .core .api .Assertions ;
2730import org .junit .jupiter .api .AfterAll ;
2831import org .junit .jupiter .api .AfterEach ;
2932import org .junit .jupiter .api .BeforeAll ;
@@ -76,17 +79,18 @@ void before() {
7679
7780 @ AfterEach
7881 void after () throws Exception {
79- ObjectName objectName = new ObjectName (
80- "otel.jmx.test:type=" + Hello .class .getSimpleName () + ",*" );
81- theServer .queryMBeans (objectName , null ).forEach (
82- instance -> {
83- try {
84- theServer .unregisterMBean (instance .getObjectName ());
85- } catch (InstanceNotFoundException | MBeanRegistrationException e ) {
86- throw new RuntimeException (e );
87- }
88- }
89- );
82+ ObjectName objectName =
83+ new ObjectName ("otel.jmx.test:type=" + Hello .class .getSimpleName () + ",*" );
84+ theServer
85+ .queryMBeans (objectName , null )
86+ .forEach (
87+ instance -> {
88+ try {
89+ theServer .unregisterMBean (instance .getObjectName ());
90+ } catch (InstanceNotFoundException | MBeanRegistrationException e ) {
91+ throw new RuntimeException (e );
92+ }
93+ });
9094
9195 if (sdk != null ) {
9296 sdk .getSdkMeterProvider ().close ();
@@ -152,28 +156,23 @@ void partialAggregateMultipleParams() throws Exception {
152156
153157 String bean = getObjectName ("*" , "*" ).toString ();
154158
155- List <MetricAttribute > attributes = Collections .singletonList (
156- new MetricAttribute ("test.metric.param" ,
157- MetricAttributeExtractor .fromObjectNameParameter ("b" )));
159+ List <MetricAttribute > attributes =
160+ Collections .singletonList (
161+ new MetricAttribute (
162+ "test.metric.param" , MetricAttributeExtractor .fromObjectNameParameter ("b" )));
158163 Collection <MetricData > data = testMetric (bean , attributes );
159164
160165 assertThat (data )
161166 .isNotEmpty ()
162- .satisfiesExactlyInAnyOrder (
167+ .satisfiesExactly (
163168 metric -> {
164169 assertThat (metric .getName ()).isEqualTo ("test.metric" );
165- Collection <LongPointData > points = metric .getLongSumData ().getPoints ();
166- assertThat (points ).hasSize (1 );
167- LongPointData pointData = points .stream ().findFirst ().get ();
168- assertThat (pointData .getAttributes ()).containsEntry ("b" , "y" );
169- assertThat (pointData .getValue ()).isEqualTo (6 );
170- }, metric -> {
171- Assertions .assertThat (metric .getName ()).isEqualTo ("test.metric" );
172- Collection <LongPointData > points = metric .getLongSumData ().getPoints ();
173- assertThat (points ).hasSize (1 );
174- LongPointData pointData = points .stream ().findFirst ().get ();
175- assertThat (pointData .getAttributes ()).containsEntry ("b" , "x" );
176- assertThat (pointData .getValue ()).isEqualTo (4 );
170+ AttributeKey <String > metricAttribute = AttributeKey .stringKey ("test.metric.param" );
171+ assertThat (metric .getLongSumData ().getPoints ())
172+ .extracting (LongPointData ::getValue , PointData ::getAttributes )
173+ .containsExactlyInAnyOrder (
174+ tuple (6L , Attributes .of (metricAttribute , "y" )),
175+ tuple (4L , Attributes .of (metricAttribute , "x" )));
177176 });
178177 }
179178
@@ -197,17 +196,16 @@ private Collection<MetricData> testMetric(String mbean, List<MetricAttribute> at
197196 return waitMetricsReceived ();
198197 }
199198
200- private static void checkSingleValue (Collection <MetricData > data , int expectedValue ) {
199+ private static void checkSingleValue (Collection <MetricData > data , long expectedValue ) {
201200 assertThat (data )
202201 .isNotEmpty ()
203202 .satisfiesExactlyInAnyOrder (
204203 metric -> {
205204 assertThat (metric .getName ()).isEqualTo ("test.metric" );
206- Collection <LongPointData > points = metric .getLongSumData ().getPoints ();
207- assertThat (points ).hasSize (1 );
208- LongPointData pointData = points .stream ().findFirst ().get ();
209- assertThat (pointData .getValue ()).isEqualTo (expectedValue );
210- assertThat (pointData .getAttributes ()).isEmpty ();
205+ assertThat (metric .getLongSumData ().getPoints ())
206+ .extracting (LongPointData ::getValue , PointData ::getAttributes )
207+ .containsExactlyInAnyOrder (
208+ tuple (expectedValue , Attributes .empty ()));
211209 });
212210 }
213211
0 commit comments