25
25
import io .opentelemetry .api .metrics .ObservableLongUpDownCounter ;
26
26
import io .opentelemetry .instrumentation .testing .junit .AgentInstrumentationExtension ;
27
27
import io .opentelemetry .sdk .common .InstrumentationScopeInfo ;
28
+ import java .lang .reflect .Method ;
28
29
import org .assertj .core .api .AbstractIterableAssert ;
29
30
import org .junit .jupiter .api .BeforeEach ;
30
31
import org .junit .jupiter .api .Test ;
@@ -116,7 +117,7 @@ void observableLongCounter() throws InterruptedException {
116
117
.hasAttributesSatisfying (
117
118
equalTo (AttributeKey .stringKey ("q" ), "r" ))))));
118
119
119
- observableCounter . close ();
120
+ close (observableCounter );
120
121
121
122
// sleep exporter interval
122
123
Thread .sleep (100 );
@@ -192,7 +193,7 @@ void observableDoubleCounter() throws InterruptedException {
192
193
.hasAttributesSatisfying (
193
194
equalTo (AttributeKey .stringKey ("q" ), "r" ))))));
194
195
195
- observableCounter . close ();
196
+ close (observableCounter );
196
197
197
198
// sleep exporter interval
198
199
Thread .sleep (100 );
@@ -267,7 +268,7 @@ void observableLongUpDownCounter() throws InterruptedException {
267
268
.hasAttributesSatisfying (
268
269
equalTo (AttributeKey .stringKey ("q" ), "r" ))))));
269
270
270
- observableCounter . close ();
271
+ close (observableCounter );
271
272
272
273
// sleep exporter interval
273
274
Thread .sleep (100 );
@@ -343,7 +344,7 @@ void observableDoubleUpDownCounter() throws InterruptedException {
343
344
.hasAttributesSatisfying (
344
345
equalTo (AttributeKey .stringKey ("q" ), "r" ))))));
345
346
346
- observableCounter . close ();
347
+ close (observableCounter );
347
348
348
349
// sleep exporter interval
349
350
Thread .sleep (100 );
@@ -448,7 +449,7 @@ void longGauge() throws InterruptedException {
448
449
.hasAttributesSatisfying (
449
450
equalTo (AttributeKey .stringKey ("q" ), "r" ))))));
450
451
451
- observableGauge . close ();
452
+ close (observableGauge );
452
453
453
454
// sleep exporter interval
454
455
Thread .sleep (100 );
@@ -490,7 +491,7 @@ void doubleGauge() throws InterruptedException {
490
491
.hasAttributesSatisfying (
491
492
equalTo (AttributeKey .stringKey ("q" ), "r" ))))));
492
493
493
- observableGauge . close ();
494
+ close (observableGauge );
494
495
495
496
// sleep exporter interval
496
497
Thread .sleep (100 );
@@ -499,4 +500,14 @@ void doubleGauge() throws InterruptedException {
499
500
500
501
testing .waitAndAssertMetrics (instrumentationName , "test" , AbstractIterableAssert ::isEmpty );
501
502
}
503
+
504
+ private static void close (Object observableInstrument ) {
505
+ // our bridge includes close method, although it was added in 1.12
506
+ try {
507
+ Method close = observableInstrument .getClass ().getDeclaredMethod ("close" );
508
+ close .invoke (observableInstrument );
509
+ } catch (Exception exception ) {
510
+ throw new IllegalStateException ("Failed to call close" , exception );
511
+ }
512
+ }
502
513
}
0 commit comments