Merge branch '2.5.x'

Closes gh-27118
pull/27144/head
Stephane Nicoll 3 years ago
commit 786d7cdb6e

@ -20,6 +20,7 @@ import java.util.List;
import com.mongodb.MongoClientSettings; import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClient;
import com.mongodb.client.internal.MongoClientImpl;
import com.mongodb.connection.ConnectionPoolSettings; import com.mongodb.connection.ConnectionPoolSettings;
import com.mongodb.event.ConnectionPoolListener; import com.mongodb.event.ConnectionPoolListener;
import io.micrometer.core.instrument.binder.mongodb.DefaultMongoCommandTagsProvider; import io.micrometer.core.instrument.binder.mongodb.DefaultMongoCommandTagsProvider;
@ -176,18 +177,15 @@ class MongoMetricsAutoConfigurationTests {
private MongoClientSettings getActualMongoClientSettingsUsedToConstructClient( private MongoClientSettings getActualMongoClientSettingsUsedToConstructClient(
final AssertableApplicationContext context) { final AssertableApplicationContext context) {
final MongoClient mongoClient = context.getBean(MongoClient.class); final MongoClientImpl mongoClient = (MongoClientImpl) context.getBean(MongoClient.class);
return (MongoClientSettings) ReflectionTestUtils.getField(mongoClient, "settings"); return mongoClient.getSettings();
} }
private List<ConnectionPoolListener> getConnectionPoolListenersFromClient( private List<ConnectionPoolListener> getConnectionPoolListenersFromClient(
final AssertableApplicationContext context) { final AssertableApplicationContext context) {
MongoClientSettings mongoClientSettings = getActualMongoClientSettingsUsedToConstructClient(context); MongoClientSettings mongoClientSettings = getActualMongoClientSettingsUsedToConstructClient(context);
ConnectionPoolSettings connectionPoolSettings = mongoClientSettings.getConnectionPoolSettings(); ConnectionPoolSettings connectionPoolSettings = mongoClientSettings.getConnectionPoolSettings();
@SuppressWarnings("unchecked") return connectionPoolSettings.getConnectionPoolListeners();
List<ConnectionPoolListener> listeners = (List<ConnectionPoolListener>) ReflectionTestUtils
.getField(connectionPoolSettings, "connectionPoolListeners");
return listeners;
} }
private MongoCommandTagsProvider getMongoCommandTagsProviderUsedToConstructListener( private MongoCommandTagsProvider getMongoCommandTagsProviderUsedToConstructListener(

@ -23,7 +23,6 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions; import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -43,8 +42,7 @@ public class RedisAutoConfigurationLettuceWithoutCommonsPool2Tests {
this.contextRunner.withPropertyValues("spring.redis.host:foo").run((context) -> { this.contextRunner.withPropertyValues("spring.redis.host:foo").run((context) -> {
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class); LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
assertThat(cf.getHostName()).isEqualTo("foo"); assertThat(cf.getHostName()).isEqualTo("foo");
assertThat(ReflectionTestUtils.getField(cf, "clientConfiguration")) assertThat(cf.getClientConfiguration()).isNotInstanceOf(LettucePoolingClientConfiguration.class);
.isNotInstanceOf(LettucePoolingClientConfiguration.class);
}); });
} }

@ -207,8 +207,7 @@ class RedisAutoConfigurationTests {
.run((context) -> { .run((context) -> {
LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class); LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class);
assertThat(cf.getHostName()).isEqualTo("foo"); assertThat(cf.getHostName()).isEqualTo("foo");
assertThat(ReflectionTestUtils.getField(cf, "clientConfiguration")) assertThat(cf.getClientConfiguration()).isNotInstanceOf(LettucePoolingClientConfiguration.class);
.isNotInstanceOf(LettucePoolingClientConfiguration.class);
}); });
} }
@ -439,7 +438,7 @@ class RedisAutoConfigurationTests {
} }
private LettucePoolingClientConfiguration getPoolingClientConfiguration(LettuceConnectionFactory factory) { private LettucePoolingClientConfiguration getPoolingClientConfiguration(LettuceConnectionFactory factory) {
return (LettucePoolingClientConfiguration) ReflectionTestUtils.getField(factory, "clientConfiguration"); return (LettucePoolingClientConfiguration) factory.getClientConfiguration();
} }
private String getUserName(LettuceConnectionFactory factory) { private String getUserName(LettuceConnectionFactory factory) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,6 @@ import org.springframework.http.converter.smile.MappingJackson2SmileHttpMessageC
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.http.converter.xml.SourceHttpMessageConverter; import org.springframework.http.converter.xml.SourceHttpMessageConverter;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -143,10 +142,9 @@ class HttpMessageConvertersTests {
MappingJackson2HttpMessageConverter.class, MappingJackson2SmileHttpMessageConverter.class); MappingJackson2HttpMessageConverter.class, MappingJackson2SmileHttpMessageConverter.class);
} }
@SuppressWarnings("unchecked")
private List<HttpMessageConverter<?>> extractFormPartConverters(List<HttpMessageConverter<?>> converters) { private List<HttpMessageConverter<?>> extractFormPartConverters(List<HttpMessageConverter<?>> converters) {
AllEncompassingFormHttpMessageConverter formConverter = findFormConverter(converters); AllEncompassingFormHttpMessageConverter formConverter = findFormConverter(converters);
return (List<HttpMessageConverter<?>>) ReflectionTestUtils.getField(formConverter, "partConverters"); return formConverter.getPartConverters();
} }
private AllEncompassingFormHttpMessageConverter findFormConverter(Collection<HttpMessageConverter<?>> converters) { private AllEncompassingFormHttpMessageConverter findFormConverter(Collection<HttpMessageConverter<?>> converters) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
import com.mongodb.MongoClientSettings; import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClients;
import com.mongodb.client.internal.MongoClientImpl;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
@ -28,7 +29,6 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -86,8 +86,8 @@ class MongoAutoConfigurationTests {
private MongoClientSettings getSettings(AssertableApplicationContext context) { private MongoClientSettings getSettings(AssertableApplicationContext context) {
assertThat(context).hasSingleBean(MongoClient.class); assertThat(context).hasSingleBean(MongoClient.class);
MongoClient client = context.getBean(MongoClient.class); MongoClientImpl client = (MongoClientImpl) context.getBean(MongoClient.class);
return (MongoClientSettings) ReflectionTestUtils.getField(client, "settings"); return client.getSettings();
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,8 +20,7 @@ import java.util.List;
import com.mongodb.MongoClientSettings; import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClient;
import com.mongodb.client.internal.MongoClientImpl;
import org.springframework.test.util.ReflectionTestUtils;
/** /**
* Tests for {@link MongoClientFactory}. * Tests for {@link MongoClientFactory}.
@ -42,7 +41,7 @@ class MongoClientFactoryTests extends MongoClientFactorySupportTests<MongoClient
@Override @Override
protected MongoClientSettings getClientSettings(MongoClient client) { protected MongoClientSettings getClientSettings(MongoClient client) {
return (MongoClientSettings) ReflectionTestUtils.getField(client, "settings"); return ((MongoClientImpl) client).getSettings();
} }
} }

@ -26,6 +26,7 @@ import com.mongodb.connection.StreamFactory;
import com.mongodb.connection.StreamFactoryFactory; import com.mongodb.connection.StreamFactoryFactory;
import com.mongodb.connection.netty.NettyStreamFactoryFactory; import com.mongodb.connection.netty.NettyStreamFactoryFactory;
import com.mongodb.reactivestreams.client.MongoClient; import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.internal.MongoClientImpl;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -111,8 +112,8 @@ class MongoReactiveAutoConfigurationTests {
} }
private MongoClientSettings getSettings(ApplicationContext context) { private MongoClientSettings getSettings(ApplicationContext context) {
MongoClient client = context.getBean(MongoClient.class); MongoClientImpl client = (MongoClientImpl) context.getBean(MongoClient.class);
return (MongoClientSettings) ReflectionTestUtils.getField(client, "settings"); return client.getSettings();
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)

@ -20,8 +20,7 @@ import java.util.List;
import com.mongodb.MongoClientSettings; import com.mongodb.MongoClientSettings;
import com.mongodb.reactivestreams.client.MongoClient; import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.internal.MongoClientImpl;
import org.springframework.test.util.ReflectionTestUtils;
/** /**
* Tests for {@link ReactiveMongoClientFactory}. * Tests for {@link ReactiveMongoClientFactory}.
@ -40,7 +39,7 @@ class ReactiveMongoClientFactoryTests extends MongoClientFactorySupportTests<Mon
@Override @Override
protected MongoClientSettings getClientSettings(MongoClient client) { protected MongoClientSettings getClientSettings(MongoClient client) {
return (MongoClientSettings) ReflectionTestUtils.getField(client, "settings"); return ((MongoClientImpl) client).getSettings();
} }
} }

@ -42,7 +42,7 @@ import org.apache.tomcat.util.net.AbstractEndpoint;
import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpChannel;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.thread.ThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import reactor.netty.http.HttpDecoderSpec; import reactor.netty.http.HttpDecoderSpec;
import reactor.netty.http.server.HttpRequestDecoderSpec; import reactor.netty.http.server.HttpRequestDecoderSpec;
@ -430,11 +430,11 @@ class ServerPropertiesTests {
void jettyThreadPoolPropertyDefaultsShouldMatchServerDefault() { void jettyThreadPoolPropertyDefaultsShouldMatchServerDefault() {
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0); JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);
JettyWebServer jetty = (JettyWebServer) jettyFactory.getWebServer(); JettyWebServer jetty = (JettyWebServer) jettyFactory.getWebServer();
Server server = (Server) ReflectionTestUtils.getField(jetty, "server"); Server server = jetty.getServer();
ThreadPool threadPool = (ThreadPool) ReflectionTestUtils.getField(server, "_threadPool"); QueuedThreadPool threadPool = (QueuedThreadPool) server.getThreadPool();
int idleTimeout = (int) ReflectionTestUtils.getField(threadPool, "_idleTimeout"); int idleTimeout = threadPool.getIdleTimeout();
int maxThreads = (int) ReflectionTestUtils.getField(threadPool, "_maxThreads"); int maxThreads = threadPool.getMaxThreads();
int minThreads = (int) ReflectionTestUtils.getField(threadPool, "_minThreads"); int minThreads = threadPool.getMinThreads();
assertThat(this.properties.getJetty().getThreads().getIdleTimeout().toMillis()).isEqualTo(idleTimeout); assertThat(this.properties.getJetty().getThreads().getIdleTimeout().toMillis()).isEqualTo(idleTimeout);
assertThat(this.properties.getJetty().getThreads().getMax()).isEqualTo(maxThreads); assertThat(this.properties.getJetty().getThreads().getMax()).isEqualTo(maxThreads);
assertThat(this.properties.getJetty().getThreads().getMin()).isEqualTo(minThreads); assertThat(this.properties.getJetty().getThreads().getMin()).isEqualTo(minThreads);

@ -696,8 +696,8 @@ class WebMvcAutoConfigurationTests {
this.contextRunner.withPropertyValues(prefix + "static-locations:classpath:/welcome-page/") this.contextRunner.withPropertyValues(prefix + "static-locations:classpath:/welcome-page/")
.withUserConfiguration(CorsConfigurer.class).run((context) -> { .withUserConfiguration(CorsConfigurer.class).run((context) -> {
WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class); WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class);
UrlBasedCorsConfigurationSource source = (UrlBasedCorsConfigurationSource) ReflectionTestUtils UrlBasedCorsConfigurationSource source = (UrlBasedCorsConfigurationSource) bean
.getField(bean, "corsConfigurationSource"); .getCorsConfigurationSource();
assertThat(source.getCorsConfigurations()).containsKey("/**"); assertThat(source.getCorsConfigurations()).containsKey("/**");
}); });
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -55,7 +55,6 @@ import org.springframework.messaging.simp.stomp.StompSession;
import org.springframework.messaging.simp.stomp.StompSessionHandler; import org.springframework.messaging.simp.stomp.StompSessionHandler;
import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter; import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration; import org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration;
@ -138,13 +137,10 @@ class WebSocketMessagingAutoConfigurationTests {
return customizedConverters; return customizedConverters;
} }
@SuppressWarnings("unchecked")
private List<MessageConverter> getDefaultConverters() { private List<MessageConverter> getDefaultConverters() {
DelegatingWebSocketMessageBrokerConfiguration configuration = new DelegatingWebSocketMessageBrokerConfiguration(); DelegatingWebSocketMessageBrokerConfiguration configuration = new DelegatingWebSocketMessageBrokerConfiguration();
// We shouldn't usually call this method directly since it's on a non-proxy config CompositeMessageConverter compositeDefaultConverter = configuration.brokerMessageConverter();
CompositeMessageConverter compositeDefaultConverter = ReflectionTestUtils.invokeMethod(configuration, return compositeDefaultConverter.getConverters();
"brokerMessageConverter");
return (List<MessageConverter>) ReflectionTestUtils.getField(compositeDefaultConverter, "converters");
} }
private Object performStompSubscription(String topic) throws Throwable { private Object performStompSubscription(String topic) throws Throwable {

Loading…
Cancel
Save