@@ -336,45 +336,53 @@ void testEnableDropSpans() {
336336
337337 @ Test
338338 void testActivationStackOverflow () {
339- doReturn (2 ).when (tracerImpl .getConfig (CoreConfiguration .class )).getTransactionMaxSpans ();
340- Transaction transaction = startTestRootTransaction ();
341- assertThat (tracerImpl .getActive ()).isNull ();
339+ doReturn (2 ).when (config .getConfig (CoreConfiguration .class )).getTransactionMaxSpans ();
340+
341+ ElasticApmTracer tracer = new ElasticApmTracerBuilder ()
342+ .configurationRegistry (config )
343+ .withApmServerClient (mock (ApmServerClient .class ))
344+ .reporter (reporter )
345+ .withObjectPoolFactory (objectPoolFactory )
346+ .buildAndStart ();
347+
348+ Transaction transaction = tracer .startRootTransaction (getClass ().getClassLoader ());
349+ assertThat (tracer .getActive ()).isNull ();
342350 try (Scope scope = transaction .activateInScope ()) {
343- assertThat (tracerImpl .getActive ()).isEqualTo (transaction );
351+ assertThat (tracer .getActive ()).isEqualTo (transaction );
344352 Span child1 = transaction .createSpan ();
345353 try (Scope childScope = child1 .activateInScope ()) {
346- assertThat (tracerImpl .getActive ()).isEqualTo (child1 );
354+ assertThat (tracer .getActive ()).isEqualTo (child1 );
347355 Span grandchild1 = child1 .createSpan ();
348356 try (Scope grandchildScope = grandchild1 .activateInScope ()) {
349357 // latter activation should not be applied due to activation stack overflow
350- assertThat (tracerImpl .getActive ()).isEqualTo (child1 );
358+ assertThat (tracer .getActive ()).isEqualTo (child1 );
351359 Span ggc = grandchild1 .createSpan ();
352360 try (Scope ggcScope = ggc .activateInScope ()) {
353- assertThat (tracerImpl .getActive ()).isEqualTo (child1 );
361+ assertThat (tracer .getActive ()).isEqualTo (child1 );
354362 ggc .end ();
355363 }
356364 grandchild1 .end ();
357365 }
358- assertThat (tracerImpl .getActive ()).isEqualTo (child1 );
366+ assertThat (tracer .getActive ()).isEqualTo (child1 );
359367 child1 .end ();
360368 }
361- assertThat (tracerImpl .getActive ()).isEqualTo (transaction );
369+ assertThat (tracer .getActive ()).isEqualTo (transaction );
362370 Span child2 = transaction .createSpan ();
363371 try (Scope childScope = child2 .activateInScope ()) {
364- assertThat (tracerImpl .getActive ()).isEqualTo (child2 );
372+ assertThat (tracer .getActive ()).isEqualTo (child2 );
365373 Span grandchild2 = child2 .createSpan ();
366374 try (Scope grandchildScope = grandchild2 .activateInScope ()) {
367375 // latter activation should not be applied due to activation stack overflow
368- assertThat (tracerImpl .getActive ()).isEqualTo (child2 );
376+ assertThat (tracer .getActive ()).isEqualTo (child2 );
369377 grandchild2 .end ();
370378 }
371- assertThat (tracerImpl .getActive ()).isEqualTo (child2 );
379+ assertThat (tracer .getActive ()).isEqualTo (child2 );
372380 child2 .end ();
373381 }
374- assertThat (tracerImpl .getActive ()).isEqualTo (transaction );
382+ assertThat (tracer .getActive ()).isEqualTo (transaction );
375383 transaction .end ();
376384 }
377- assertThat (tracerImpl .getActive ()).isNull ();
385+ assertThat (tracer .getActive ()).isNull ();
378386 assertThat (reporter .getTransactions ()).hasSize (1 );
379387 assertThat (reporter .getSpans ()).hasSize (2 );
380388 }
0 commit comments