Skip to content

Commit 4e3e37b

Browse files
committed
<modify>: adjust configuration class filter order.
1 parent 7302188 commit 4e3e37b

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/zipkin/ZipkinConfigurationsSenderConfigurationTests.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class ZipkinConfigurationsSenderConfigurationTests {
6363
private final WebApplicationContextRunner servletContextRunner = new WebApplicationContextRunner()
6464
.withConfiguration(AutoConfigurations.of(DefaultEncodingConfiguration.class, SenderConfiguration.class));
6565

66+
// passed
6667
@Test
6768
void shouldSupplyDefaultHttpClientSenderBeans() {
6869
this.contextRunner.run((context) -> {
@@ -74,10 +75,11 @@ void shouldSupplyDefaultHttpClientSenderBeans() {
7475
});
7576
}
7677

78+
// passed
7779
@Test
7880
void shouldUseUrlSenderIfHttpSenderIsNotAvailable() {
7981
this.contextRunner.withUserConfiguration(UrlConnectionSenderConfiguration.class)
80-
.withClassLoader(new FilteredClassLoader("zipkin2.reporter.http.HttpClientSender", "org.springframework.web.client",
82+
.withClassLoader(new FilteredClassLoader("java.net.http.HttpClient", "org.springframework.web.client",
8183
"org.springframework.web.reactive.function.client"))
8284
.run((context) -> {
8385
assertThat(context).doesNotHaveBean(ZipkinHttpClientSender.class);
@@ -86,43 +88,47 @@ void shouldUseUrlSenderIfHttpSenderIsNotAvailable() {
8688
});
8789
}
8890

91+
// passed
8992
@Test
9093
void shouldPreferWebClientSenderIfWebApplicationIsReactiveAndHttpClientSenderIsNotAvailable() {
9194
this.reactiveContextRunner.withUserConfiguration(RestTemplateConfiguration.class, WebClientConfiguration.class)
92-
.withClassLoader(new FilteredClassLoader("zipkin2.reporter.urlconnection"))
95+
.withClassLoader(new FilteredClassLoader("java.net.http.HttpClient"))
9396
.run((context) -> {
94-
assertThat(context).doesNotHaveBean(URLConnectionSender.class);
97+
assertThat(context).doesNotHaveBean(ZipkinHttpClientSender.class);
9598
assertThat(context).hasSingleBean(BytesMessageSender.class);
9699
assertThat(context).hasSingleBean(ZipkinWebClientSender.class);
97100
then(context.getBean(ZipkinWebClientBuilderCustomizer.class)).should()
98101
.customize(ArgumentMatchers.any());
99102
});
100103
}
101104

105+
// passed
102106
@Test
103107
void shouldPreferWebClientSenderIfWebApplicationIsServletAndHttpClientSenderIsNotAvailable() {
104108
this.servletContextRunner.withUserConfiguration(RestTemplateConfiguration.class, WebClientConfiguration.class)
105-
.withClassLoader(new FilteredClassLoader("zipkin2.reporter.http.HttpClientSender"))
109+
.withClassLoader(new FilteredClassLoader("java.net.http.HttpClient"))
106110
.run((context) -> {
107111
assertThat(context).doesNotHaveBean(ZipkinHttpClientSender.class);
108112
assertThat(context).hasSingleBean(BytesMessageSender.class);
109113
assertThat(context).hasSingleBean(ZipkinWebClientSender.class);
110114
});
111115
}
112116

117+
// passed
113118
@Test
114-
void shouldPreferWebClientInNonWebApplicationAndUrlConnectionSenderIsNotAvailable() {
119+
void shouldPreferWebClientInNonWebApplicationAndHttpClientSenderIsNotAvailable() {
115120
this.contextRunner.withUserConfiguration(RestTemplateConfiguration.class, WebClientConfiguration.class)
116-
.withClassLoader(new FilteredClassLoader("zipkin2.reporter.urlconnection"))
121+
.withClassLoader(new FilteredClassLoader("java.net.http.HttpClient"))
117122
.run((context) -> {
118-
assertThat(context).doesNotHaveBean(URLConnectionSender.class);
123+
assertThat(context).doesNotHaveBean(ZipkinHttpClientSender.class);
119124
assertThat(context).hasSingleBean(BytesMessageSender.class);
120125
assertThat(context).hasSingleBean(ZipkinWebClientSender.class);
121126
});
122127
}
123128

129+
// passed
124130
@Test
125-
void willUseRestTemplateInNonWebApplicationIfUrlConnectionSenderAndWebClientAreNotAvailable() {
131+
void willUseRestTemplateInNonWebApplicationIfSenderAndWebClientAreNotAvailable() {
126132
this.contextRunner.withUserConfiguration(RestTemplateConfiguration.class)
127133
.withClassLoader(new FilteredClassLoader(URLConnectionSender.class, WebClient.class))
128134
.run((context) -> {
@@ -132,37 +138,41 @@ void willUseRestTemplateInNonWebApplicationIfUrlConnectionSenderAndWebClientAreN
132138
});
133139
}
134140

141+
// passed
135142
@Test
136-
void willUseRestTemplateInServletWebApplicationIfUrlConnectionSenderAndWebClientNotAvailable() {
143+
void willUseRestTemplateInServletWebApplicationIfHttpClientSenderAndWebClientNotAvailable() {
137144
this.servletContextRunner.withUserConfiguration(RestTemplateConfiguration.class)
138-
.withClassLoader(new FilteredClassLoader(URLConnectionSender.class, WebClient.class))
145+
.withClassLoader(new FilteredClassLoader("java.net.http.HttpClient", "org.springframework.web.reactive.function.client"))
139146
.run((context) -> {
140-
assertThat(context).doesNotHaveBean(URLConnectionSender.class);
147+
assertThat(context).doesNotHaveBean(ZipkinHttpClientSender.class);
141148
assertThat(context).hasSingleBean(BytesMessageSender.class);
142149
assertThat(context).hasSingleBean(ZipkinRestTemplateSender.class);
143150
});
144151
}
145152

153+
// passed
146154
@Test
147-
void willUseRestTemplateInReactiveWebApplicationIfUrlConnectionSenderAndWebClientAreNotAvailable() {
155+
void willUseRestTemplateInReactiveWebApplicationIfHttpClientSenderAndWebClientAreNotAvailable() {
148156
this.reactiveContextRunner.withUserConfiguration(RestTemplateConfiguration.class)
149-
.withClassLoader(new FilteredClassLoader(URLConnectionSender.class, WebClient.class))
157+
.withClassLoader(new FilteredClassLoader("java.net.http.HttpClient", "org.springframework.web.reactive.function.client"))
150158
.run((context) -> {
151-
assertThat(context).doesNotHaveBean(URLConnectionSender.class);
159+
assertThat(context).doesNotHaveBean(ZipkinHttpClientSender.class);
152160
assertThat(context).hasSingleBean(BytesMessageSender.class);
153161
assertThat(context).hasSingleBean(ZipkinRestTemplateSender.class);
154162
});
155163
}
156164

165+
// passed
157166
@Test
158167
void shouldNotUseWebClientSenderIfNoBuilderIsAvailable() {
159168
this.reactiveContextRunner.run((context) -> {
160169
assertThat(context).doesNotHaveBean(ZipkinWebClientSender.class);
161170
assertThat(context).hasSingleBean(BytesMessageSender.class);
162-
assertThat(context).hasSingleBean(URLConnectionSender.class);
171+
assertThat(context).hasSingleBean(ZipkinHttpClientSender.class);
163172
});
164173
}
165174

175+
// passed
166176
@Test
167177
void shouldBackOffOnCustomBeans() {
168178
this.contextRunner.withUserConfiguration(CustomConfiguration.class).run((context) -> {
@@ -171,14 +181,15 @@ void shouldBackOffOnCustomBeans() {
171181
});
172182
}
173183

184+
// passed
174185
@Test
175186
void shouldApplyZipkinRestTemplateBuilderCustomizers() throws IOException {
176187
try (MockWebServer mockWebServer = new MockWebServer()) {
177188
mockWebServer.enqueue(new MockResponse().setResponseCode(204));
178189
this.reactiveContextRunner
179190
.withPropertyValues("management.zipkin.tracing.endpoint=" + mockWebServer.url("/"))
180191
.withUserConfiguration(RestTemplateConfiguration.class)
181-
.withClassLoader(new FilteredClassLoader(URLConnectionSender.class, WebClient.class))
192+
.withClassLoader(new FilteredClassLoader("java.net.http.HttpClient", "org.springframework.web.reactive.function.client"))
182193
.run((context) -> {
183194
assertThat(context).hasSingleBean(ZipkinRestTemplateSender.class);
184195
ZipkinRestTemplateSender sender = context.getBean(ZipkinRestTemplateSender.class);

0 commit comments

Comments
 (0)