1616
1717package org .springframework .boot .actuate .autoconfigure .tracing .zipkin ;
1818
19+ import java .net .http .HttpClient ;
20+
1921import org .junit .jupiter .api .Test ;
2022import zipkin2 .reporter .BytesMessageSender ;
2123import zipkin2 .reporter .HttpEndpointSupplier ;
22-
24+ import org . springframework . boot . actuate . autoconfigure . tracing . zipkin . ZipkinConfigurations . HttpClientSenderConfiguration ;
2325import org .springframework .boot .actuate .autoconfigure .tracing .zipkin .ZipkinConfigurations .SenderConfiguration ;
2426import org .springframework .boot .autoconfigure .AutoConfigurations ;
27+ import org .springframework .boot .test .context .FilteredClassLoader ;
2528import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
2629import org .springframework .context .annotation .Bean ;
2730import org .springframework .context .annotation .Configuration ;
3942class ZipkinConfigurationsSenderConfigurationTests {
4043
4144 private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ()
42- .withConfiguration (AutoConfigurations .of (DefaultEncodingConfiguration .class , SenderConfiguration .class ));
45+ .withConfiguration (AutoConfigurations .of (DefaultEncodingConfiguration .class , SenderConfiguration .class ));
4346
4447 @ Test
4548 void shouldSupplyDefaultHttpClientSenderBean () {
@@ -49,6 +52,15 @@ void shouldSupplyDefaultHttpClientSenderBean() {
4952 });
5053 }
5154
55+ @ Test
56+ void shouldNotProvideHttpClientSenderIfHttpClientIsNotAvailable () {
57+ this .contextRunner .withUserConfiguration (HttpClientSenderConfiguration .class )
58+ .withClassLoader (new FilteredClassLoader (HttpClient .class ))
59+ .run ((context ) -> {
60+ assertThat (context ).doesNotHaveBean (ZipkinHttpClientSender .class );
61+ });
62+ }
63+
5264 @ Test
5365 void shouldBackOffOnCustomBeans () {
5466 this .contextRunner .withUserConfiguration (CustomConfiguration .class ).run ((context ) -> {
@@ -57,6 +69,16 @@ void shouldBackOffOnCustomBeans() {
5769 });
5870 }
5971
72+ @ Test
73+ void shouldUseCustomHttpEndpointSupplierFactory () {
74+ this .contextRunner .withUserConfiguration (CustomHttpEndpointSupplierFactoryConfiguration .class )
75+ .run ((context ) -> {
76+ ZipkinHttpClientSender httpClientSender = context .getBean (ZipkinHttpClientSender .class );
77+ assertThat (httpClientSender ).extracting ("endpointSupplier" )
78+ .isInstanceOf (CustomHttpEndpointSupplier .class );
79+ });
80+ }
81+
6082 @ Configuration (proxyBeanMethods = false )
6183 private static final class CustomConfiguration {
6284
@@ -67,6 +89,25 @@ BytesMessageSender customSender() {
6789
6890 }
6991
92+ @ Configuration (proxyBeanMethods = false )
93+ private static final class CustomHttpEndpointSupplierFactoryConfiguration {
94+
95+ @ Bean
96+ HttpEndpointSupplier .Factory httpEndpointSupplier () {
97+ return new CustomHttpEndpointSupplierFactory ();
98+ }
99+
100+ }
101+
102+ private static final class CustomHttpEndpointSupplierFactory implements HttpEndpointSupplier .Factory {
103+
104+ @ Override
105+ public HttpEndpointSupplier create (String endpoint ) {
106+ return new CustomHttpEndpointSupplier (endpoint );
107+ }
108+
109+ }
110+
70111 private record CustomHttpEndpointSupplier (String endpoint ) implements HttpEndpointSupplier {
71112
72113 @ Override
0 commit comments