17
17
package org .springframework .boot .actuate .autoconfigure .tracing .zipkin ;
18
18
19
19
import java .io .IOException ;
20
+ import java .net .http .HttpClient ;
20
21
import java .nio .charset .StandardCharsets ;
21
22
import java .util .List ;
22
23
import java .util .concurrent .TimeUnit ;
31
32
import zipkin2 .reporter .urlconnection .URLConnectionSender ;
32
33
33
34
import org .springframework .boot .actuate .autoconfigure .tracing .zipkin .ZipkinConfigurations .SenderConfiguration ;
35
+ import org .springframework .boot .actuate .autoconfigure .tracing .zipkin .ZipkinConfigurations .UrlConnectionSenderConfiguration ;
34
36
import org .springframework .boot .autoconfigure .AutoConfigurations ;
35
37
import org .springframework .boot .test .context .FilteredClassLoader ;
36
38
import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
39
41
import org .springframework .boot .web .client .RestTemplateBuilder ;
40
42
import org .springframework .context .annotation .Bean ;
41
43
import org .springframework .context .annotation .Configuration ;
44
+ import org .springframework .web .client .RestTemplate ;
42
45
import org .springframework .web .reactive .function .client .WebClient ;
43
46
44
47
import static org .assertj .core .api .Assertions .assertThat ;
49
52
* Tests for {@link SenderConfiguration}.
50
53
*
51
54
* @author Moritz Halbritter
55
+ * @author Wick Dynex
52
56
*/
53
57
@ SuppressWarnings ({ "deprecation" , "removal" })
54
58
class ZipkinConfigurationsSenderConfigurationTests {
@@ -63,34 +67,33 @@ class ZipkinConfigurationsSenderConfigurationTests {
63
67
.withConfiguration (AutoConfigurations .of (DefaultEncodingConfiguration .class , SenderConfiguration .class ));
64
68
65
69
@ Test
66
- void shouldSupplyBeans () {
70
+ void shouldSupplyDefaultHttpClientSenderBeans () {
67
71
this .contextRunner .run ((context ) -> {
68
72
assertThat (context ).hasSingleBean (BytesMessageSender .class );
69
- assertThat (context ).hasSingleBean (URLConnectionSender .class );
73
+ assertThat (context ).hasSingleBean (ZipkinHttpClientSender .class );
70
74
assertThat (context ).doesNotHaveBean (ZipkinRestTemplateSender .class );
75
+ assertThat (context ).doesNotHaveBean (ZipkinWebClientSenderTests .class );
76
+ assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
71
77
});
72
78
}
73
79
74
80
@ Test
75
- void shouldUseHttpClientIfUrlSenderIsNotAvailable () {
76
- this .contextRunner .withUserConfiguration (HttpClientConfiguration .class )
77
- .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" , "org.springframework.web.client" ,
78
- "org.springframework.web.reactive.function.client" ))
81
+ void shouldUseUrlSenderIfHttpSenderIsNotAvailable () {
82
+ this .contextRunner .withUserConfiguration (UrlConnectionSenderConfiguration .class )
83
+ .withClassLoader (new FilteredClassLoader (HttpClient .class , WebClient .class , RestTemplate .class ))
79
84
.run ((context ) -> {
80
- assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
85
+ assertThat (context ).doesNotHaveBean (ZipkinHttpClientSender .class );
81
86
assertThat (context ).hasSingleBean (BytesMessageSender .class );
82
- assertThat (context ).hasSingleBean (ZipkinHttpClientSender .class );
83
- then (context .getBean (ZipkinHttpClientBuilderCustomizer .class )).should ()
84
- .customize (ArgumentMatchers .any ());
87
+ assertThat (context ).hasSingleBean (URLConnectionSender .class );
85
88
});
86
89
}
87
90
88
91
@ Test
89
- void shouldPreferWebClientSenderIfWebApplicationIsReactiveAndUrlSenderIsNotAvailable () {
92
+ void shouldPreferWebClientSenderIfWebApplicationIsReactiveAndHttpClientSenderIsNotAvailable () {
90
93
this .reactiveContextRunner .withUserConfiguration (RestTemplateConfiguration .class , WebClientConfiguration .class )
91
- .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" ))
94
+ .withClassLoader (new FilteredClassLoader (HttpClient . class ))
92
95
.run ((context ) -> {
93
- assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
96
+ assertThat (context ).doesNotHaveBean (ZipkinHttpClientSender .class );
94
97
assertThat (context ).hasSingleBean (BytesMessageSender .class );
95
98
assertThat (context ).hasSingleBean (ZipkinWebClientSender .class );
96
99
then (context .getBean (ZipkinWebClientBuilderCustomizer .class )).should ()
@@ -99,55 +102,55 @@ void shouldPreferWebClientSenderIfWebApplicationIsReactiveAndUrlSenderIsNotAvail
99
102
}
100
103
101
104
@ Test
102
- void shouldPreferWebClientSenderIfWebApplicationIsServletAndUrlSenderIsNotAvailable () {
105
+ void shouldPreferWebClientSenderIfWebApplicationIsServletAndHttpClientSenderIsNotAvailable () {
103
106
this .servletContextRunner .withUserConfiguration (RestTemplateConfiguration .class , WebClientConfiguration .class )
104
- .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" ))
107
+ .withClassLoader (new FilteredClassLoader (HttpClient . class ))
105
108
.run ((context ) -> {
106
- assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
109
+ assertThat (context ).doesNotHaveBean (ZipkinHttpClientSender .class );
107
110
assertThat (context ).hasSingleBean (BytesMessageSender .class );
108
111
assertThat (context ).hasSingleBean (ZipkinWebClientSender .class );
109
112
});
110
113
}
111
114
112
115
@ Test
113
- void shouldPreferWebClientInNonWebApplicationAndUrlConnectionSenderIsNotAvailable () {
116
+ void shouldPreferWebClientInNonWebApplicationAndHttpClientSenderIsNotAvailable () {
114
117
this .contextRunner .withUserConfiguration (RestTemplateConfiguration .class , WebClientConfiguration .class )
115
- .withClassLoader (new FilteredClassLoader ("zipkin2.reporter.urlconnection" ))
118
+ .withClassLoader (new FilteredClassLoader (HttpClient . class ))
116
119
.run ((context ) -> {
117
- assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
120
+ assertThat (context ).doesNotHaveBean (ZipkinHttpClientSender .class );
118
121
assertThat (context ).hasSingleBean (BytesMessageSender .class );
119
122
assertThat (context ).hasSingleBean (ZipkinWebClientSender .class );
120
123
});
121
124
}
122
125
123
126
@ Test
124
- void willUseRestTemplateInNonWebApplicationIfUrlConnectionSenderAndWebClientAreNotAvailable () {
127
+ void willUseRestTemplateInNonWebApplicationIfSenderAndWebClientAreNotAvailable () {
125
128
this .contextRunner .withUserConfiguration (RestTemplateConfiguration .class )
126
- .withClassLoader (new FilteredClassLoader (URLConnectionSender .class , WebClient .class ))
129
+ .withClassLoader (new FilteredClassLoader (HttpClient .class , WebClient .class ))
127
130
.run ((context ) -> {
128
- assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
131
+ assertThat (context ).doesNotHaveBean (HttpClient .class );
129
132
assertThat (context ).hasSingleBean (BytesMessageSender .class );
130
133
assertThat (context ).hasSingleBean (ZipkinRestTemplateSender .class );
131
134
});
132
135
}
133
136
134
137
@ Test
135
- void willUseRestTemplateInServletWebApplicationIfUrlConnectionSenderAndWebClientNotAvailable () {
138
+ void willUseRestTemplateInServletWebApplicationIfHttpClientSenderAndWebClientNotAvailable () {
136
139
this .servletContextRunner .withUserConfiguration (RestTemplateConfiguration .class )
137
- .withClassLoader (new FilteredClassLoader (URLConnectionSender .class , WebClient .class ))
140
+ .withClassLoader (new FilteredClassLoader (HttpClient .class , WebClient .class ))
138
141
.run ((context ) -> {
139
- assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
142
+ assertThat (context ).doesNotHaveBean (ZipkinHttpClientSender .class );
140
143
assertThat (context ).hasSingleBean (BytesMessageSender .class );
141
144
assertThat (context ).hasSingleBean (ZipkinRestTemplateSender .class );
142
145
});
143
146
}
144
147
145
148
@ Test
146
- void willUseRestTemplateInReactiveWebApplicationIfUrlConnectionSenderAndWebClientAreNotAvailable () {
149
+ void willUseRestTemplateInReactiveWebApplicationIfHttpClientSenderAndWebClientAreNotAvailable () {
147
150
this .reactiveContextRunner .withUserConfiguration (RestTemplateConfiguration .class )
148
- .withClassLoader (new FilteredClassLoader (URLConnectionSender .class , WebClient .class ))
151
+ .withClassLoader (new FilteredClassLoader (HttpClient .class , WebClient .class ))
149
152
.run ((context ) -> {
150
- assertThat (context ).doesNotHaveBean (URLConnectionSender .class );
153
+ assertThat (context ).doesNotHaveBean (ZipkinHttpClientSender .class );
151
154
assertThat (context ).hasSingleBean (BytesMessageSender .class );
152
155
assertThat (context ).hasSingleBean (ZipkinRestTemplateSender .class );
153
156
});
@@ -158,7 +161,7 @@ void shouldNotUseWebClientSenderIfNoBuilderIsAvailable() {
158
161
this .reactiveContextRunner .run ((context ) -> {
159
162
assertThat (context ).doesNotHaveBean (ZipkinWebClientSender .class );
160
163
assertThat (context ).hasSingleBean (BytesMessageSender .class );
161
- assertThat (context ).hasSingleBean (URLConnectionSender .class );
164
+ assertThat (context ).hasSingleBean (ZipkinHttpClientSender .class );
162
165
});
163
166
}
164
167
@@ -177,7 +180,7 @@ void shouldApplyZipkinRestTemplateBuilderCustomizers() throws IOException {
177
180
this .reactiveContextRunner
178
181
.withPropertyValues ("management.zipkin.tracing.endpoint=" + mockWebServer .url ("/" ))
179
182
.withUserConfiguration (RestTemplateConfiguration .class )
180
- .withClassLoader (new FilteredClassLoader (URLConnectionSender .class , WebClient .class ))
183
+ .withClassLoader (new FilteredClassLoader (HttpClient .class , WebClient .class ))
181
184
.run ((context ) -> {
182
185
assertThat (context ).hasSingleBean (ZipkinRestTemplateSender .class );
183
186
ZipkinRestTemplateSender sender = context .getBean (ZipkinRestTemplateSender .class );
@@ -192,6 +195,7 @@ void shouldApplyZipkinRestTemplateBuilderCustomizers() throws IOException {
192
195
@ Test
193
196
void shouldUseCustomHttpEndpointSupplierFactory () {
194
197
this .contextRunner .withUserConfiguration (CustomHttpEndpointSupplierFactoryConfiguration .class )
198
+ .withClassLoader (new FilteredClassLoader (HttpClient .class , WebClient .class , RestTemplate .class ))
195
199
.run ((context ) -> assertThat (context .getBean (URLConnectionSender .class ))
196
200
.extracting ("delegate.endpointSupplier" )
197
201
.isInstanceOf (CustomHttpEndpointSupplier .class ));
@@ -201,7 +205,7 @@ void shouldUseCustomHttpEndpointSupplierFactory() {
201
205
@ SuppressWarnings ("resource" )
202
206
void shouldUseCustomHttpEndpointSupplierFactoryWhenReactive () {
203
207
this .reactiveContextRunner .withUserConfiguration (WebClientConfiguration .class )
204
- .withClassLoader (new FilteredClassLoader (URLConnectionSender .class ))
208
+ .withClassLoader (new FilteredClassLoader (HttpClient .class ))
205
209
.withUserConfiguration (CustomHttpEndpointSupplierFactoryConfiguration .class )
206
210
.run ((context ) -> assertThat (context .getBean (ZipkinWebClientSender .class )).extracting ("endpointSupplier" )
207
211
.isInstanceOf (CustomHttpEndpointSupplier .class ));
@@ -211,7 +215,7 @@ void shouldUseCustomHttpEndpointSupplierFactoryWhenReactive() {
211
215
@ SuppressWarnings ("resource" )
212
216
void shouldUseCustomHttpEndpointSupplierFactoryWhenRestTemplate () {
213
217
this .contextRunner .withUserConfiguration (RestTemplateConfiguration .class )
214
- .withClassLoader (new FilteredClassLoader (URLConnectionSender .class , WebClient .class ))
218
+ .withClassLoader (new FilteredClassLoader (HttpClient .class , WebClient .class ))
215
219
.withUserConfiguration (CustomHttpEndpointSupplierFactoryConfiguration .class )
216
220
.run ((context ) -> assertThat (context .getBean (ZipkinRestTemplateSender .class )).extracting ("endpointSupplier" )
217
221
.isInstanceOf (CustomHttpEndpointSupplier .class ));
0 commit comments