16
16
17
17
package org .springframework .boot .actuate .autoconfigure .tracing .zipkin ;
18
18
19
+ import java .net .http .HttpClient ;
20
+
19
21
import org .junit .jupiter .api .Test ;
20
22
import zipkin2 .reporter .BytesMessageSender ;
21
23
import zipkin2 .reporter .HttpEndpointSupplier ;
22
-
24
+ import org . springframework . boot . actuate . autoconfigure . tracing . zipkin . ZipkinConfigurations . HttpClientSenderConfiguration ;
23
25
import org .springframework .boot .actuate .autoconfigure .tracing .zipkin .ZipkinConfigurations .SenderConfiguration ;
24
26
import org .springframework .boot .autoconfigure .AutoConfigurations ;
27
+ import org .springframework .boot .test .context .FilteredClassLoader ;
25
28
import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
26
29
import org .springframework .context .annotation .Bean ;
27
30
import org .springframework .context .annotation .Configuration ;
39
42
class ZipkinConfigurationsSenderConfigurationTests {
40
43
41
44
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ()
42
- .withConfiguration (AutoConfigurations .of (DefaultEncodingConfiguration .class , SenderConfiguration .class ));
45
+ .withConfiguration (AutoConfigurations .of (DefaultEncodingConfiguration .class , SenderConfiguration .class ));
43
46
44
47
@ Test
45
48
void shouldSupplyDefaultHttpClientSenderBean () {
@@ -49,6 +52,15 @@ void shouldSupplyDefaultHttpClientSenderBean() {
49
52
});
50
53
}
51
54
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
+
52
64
@ Test
53
65
void shouldBackOffOnCustomBeans () {
54
66
this .contextRunner .withUserConfiguration (CustomConfiguration .class ).run ((context ) -> {
@@ -57,6 +69,16 @@ void shouldBackOffOnCustomBeans() {
57
69
});
58
70
}
59
71
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
+
60
82
@ Configuration (proxyBeanMethods = false )
61
83
private static final class CustomConfiguration {
62
84
@@ -67,6 +89,25 @@ BytesMessageSender customSender() {
67
89
68
90
}
69
91
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
+
70
111
private record CustomHttpEndpointSupplier (String endpoint ) implements HttpEndpointSupplier {
71
112
72
113
@ Override
0 commit comments