2626import com .google .common .collect .ImmutableMap ;
2727import io .opentelemetry .api .trace .SpanKind ;
2828import io .opentelemetry .instrumentation .test .utils .PortUtils ;
29+ import io .opentelemetry .instrumentation .testing .internal .AutoCleanupExtension ;
2930import io .opentelemetry .instrumentation .testing .junit .InstrumentationExtension ;
3031import io .opentelemetry .instrumentation .testing .junit .http .AbstractHttpServerUsingTest ;
3132import io .opentelemetry .instrumentation .testing .junit .http .HttpServerInstrumentationExtension ;
3233import org .apache .camel .CamelContext ;
3334import org .apache .camel .ProducerTemplate ;
3435import org .apache .camel .builder .RouteBuilder ;
3536import org .apache .camel .impl .DefaultCamelContext ;
36- import org .junit .jupiter .api .AfterAll ;
3737import org .junit .jupiter .api .BeforeAll ;
3838import org .junit .jupiter .api .Test ;
3939import org .junit .jupiter .api .extension .RegisterExtension ;
@@ -45,6 +45,8 @@ class TwoServicesWithDirectClientCamelTest
4545 @ RegisterExtension
4646 static final InstrumentationExtension testing = HttpServerInstrumentationExtension .forAgent ();
4747
48+ @ RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension .create ();
49+
4850 private static CamelContext clientContext ;
4951
5052 private static Integer portOne ;
@@ -74,14 +76,7 @@ protected String getContextPath() {
7476 @ BeforeAll
7577 protected void setUp () {
7678 startServer ();
77- }
78-
79- @ AfterAll
80- protected void cleanUp () throws Exception {
81- cleanupServer ();
82- if (clientContext != null ) {
83- clientContext .stop ();
84- }
79+ cleanup .deferAfterAll (this ::cleanupServer );
8580 }
8681
8782 void createAndStartClient () throws Exception {
@@ -97,6 +92,7 @@ public void configure() {
9792 }
9893 });
9994 clientContext .start ();
95+ cleanup .deferAfterAll (clientContext ::stop );
10096 }
10197
10298 @ Test
0 commit comments