1616
1717package com .splunk .opentelemetry .profiler .snapshot ;
1818
19+ import static org .awaitility .Awaitility .await ;
20+ import static org .junit .jupiter .api .Assertions .assertEquals ;
21+
1922import io .opentelemetry .api .trace .Span ;
2023import io .opentelemetry .api .trace .SpanContext ;
2124import io .opentelemetry .context .Context ;
2225import io .opentelemetry .context .ContextKey ;
2326import io .opentelemetry .context .ContextStorage ;
2427import io .opentelemetry .context .Scope ;
2528import io .opentelemetry .sdk .trace .IdGenerator ;
26- import org .junit .jupiter .api .Test ;
27-
2829import java .lang .reflect .Field ;
2930import java .lang .reflect .Method ;
3031import java .time .Instant ;
3132import java .util .Optional ;
3233import java .util .concurrent .Callable ;
3334import java .util .concurrent .CountDownLatch ;
3435import java .util .concurrent .Executors ;
35-
36- import static org .awaitility .Awaitility .await ;
37- import static org .junit .jupiter .api .Assertions .assertEquals ;
36+ import org .junit .jupiter .api .Test ;
3837
3938class ActiveSpanTrackerTest {
4039 private final ContextStorage storage = ContextStorage .get ();
@@ -127,7 +126,8 @@ void trackActiveSpanForMultipleTraces() throws Exception {
127126 var f2 = executor .submit (attach (span2 , releaseLatch ));
128127 releaseLatch .countDown ();
129128
130- try (var scope1 = f1 .get (); var scope2 = f2 .get ()) {
129+ try (var scope1 = f1 .get ();
130+ var scope2 = f2 .get ()) {
131131 assertEquals (Optional .of (span1 .getSpanContext ()), spanTracker .getActiveSpan (scope1 .thread ));
132132 assertEquals (Optional .of (span2 .getSpanContext ()), spanTracker .getActiveSpan (scope2 .thread ));
133133 } finally {
@@ -146,10 +146,8 @@ void trackMultipleActiveSpansForSameTraceFromDifferentThreads() throws Exception
146146 var executor = Executors .newFixedThreadPool (2 );
147147 try (var scope1 = executor .submit (attach (span1 )).get ();
148148 var scope2 = executor .submit (attach (span2 )).get ()) {
149- assertEquals (
150- Optional .of (span1 .getSpanContext ()), spanTracker .getActiveSpan (scope1 .thread ));
151- assertEquals (
152- Optional .of (span2 .getSpanContext ()), spanTracker .getActiveSpan (scope2 .thread ));
149+ assertEquals (Optional .of (span1 .getSpanContext ()), spanTracker .getActiveSpan (scope1 .thread ));
150+ assertEquals (Optional .of (span2 .getSpanContext ()), spanTracker .getActiveSpan (scope2 .thread ));
153151 } finally {
154152 executor .shutdown ();
155153 }
@@ -163,7 +161,8 @@ private Callable<ThreadScope> attach(Span span, CountDownLatch latch) {
163161 return () -> {
164162 var context = Context .root ().with (span );
165163 var threadScope = new ThreadScope (Thread .currentThread (), spanTracker .attach (context ));
166- System .out .println (Instant .now () + ": " + Thread .currentThread ().getName () + " waiting to be released." );
164+ System .out .println (
165+ Instant .now () + ": " + Thread .currentThread ().getName () + " waiting to be released." );
167166 latch .await ();
168167 System .out .println (Instant .now () + ": " + Thread .currentThread ().getName () + " released." );
169168 return threadScope ;
@@ -267,10 +266,12 @@ void automaticallyRemoveUnclosedScopesAfterTheirReferencesExpire() throws Except
267266 var span = Span .wrap (Snapshotting .spanContext ().build ());
268267 registry .register (span .getSpanContext ());
269268
270- Thread thread = new Thread (() -> {
271- var context = Context .root ().with (span );
272- spanTracker .attach (context );
273- });
269+ Thread thread =
270+ new Thread (
271+ () -> {
272+ var context = Context .root ().with (span );
273+ spanTracker .attach (context );
274+ });
274275 thread .start ();
275276 thread .join ();
276277 thread = null ;
@@ -280,19 +281,21 @@ void automaticallyRemoveUnclosedScopesAfterTheirReferencesExpire() throws Except
280281 }
281282
282283 /**
283- * The internal OpenTelemetry {@link io.opentelemetry.instrumentation.api.internal.cache.Cache} interface doesn't
284- * define a "size" so instead we have this ugly reflection hack to get access to it.
284+ * The internal OpenTelemetry {@link io.opentelemetry.instrumentation.api.internal.cache.Cache}
285+ * interface doesn't define a "size" so instead we have this ugly reflection hack to get access to
286+ * it.
285287 */
286288 private int numberOfActiveSpans () {
287289 try {
288290 Class <ActiveSpanTracker > trackerClass = ActiveSpanTracker .class ;
289291 Field field = trackerClass .getDeclaredField ("cache" );
290292 field .setAccessible (true );
291293
292- Class <?> clazz = Class .forName ("io.opentelemetry.instrumentation.api.internal.cache.WeakLockFreeCache" );
294+ Class <?> clazz =
295+ Class .forName ("io.opentelemetry.instrumentation.api.internal.cache.WeakLockFreeCache" );
293296 Method method = clazz .getDeclaredMethod ("size" );
294297 method .setAccessible (true );
295- return (int )method .invoke (field .get (spanTracker ));
298+ return (int ) method .invoke (field .get (spanTracker ));
296299 } catch (Exception e ) {
297300 throw new RuntimeException (e );
298301 }
0 commit comments