Remove some deprecated API usage, switch to newer JDK api usages, refactor.
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.cloud.client.actuator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
@@ -152,16 +153,16 @@ public class FeaturesEndpoint implements ApplicationContextAware {
|
||||
|
||||
Feature feature = (Feature) o;
|
||||
|
||||
if (this.type != null ? !this.type.equals(feature.type) : feature.type != null) {
|
||||
if (!Objects.equals(this.type, feature.type)) {
|
||||
return false;
|
||||
}
|
||||
if (this.name != null ? !this.name.equals(feature.name) : feature.name != null) {
|
||||
if (!Objects.equals(this.name, feature.name)) {
|
||||
return false;
|
||||
}
|
||||
if (this.version != null ? !this.version.equals(feature.version) : feature.version != null) {
|
||||
if (!Objects.equals(this.version, feature.version)) {
|
||||
return false;
|
||||
}
|
||||
return this.vendor != null ? this.vendor.equals(feature.vendor) : feature.vendor == null;
|
||||
return Objects.equals(this.vendor, feature.vendor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,11 +36,11 @@ public class HasFeatures {
|
||||
}
|
||||
|
||||
public static HasFeatures abstractFeatures(Class<?>... abstractFeatures) {
|
||||
return new HasFeatures(Arrays.asList(abstractFeatures), Collections.<NamedFeature>emptyList());
|
||||
return new HasFeatures(Arrays.asList(abstractFeatures), Collections.emptyList());
|
||||
}
|
||||
|
||||
public static HasFeatures namedFeatures(NamedFeature... namedFeatures) {
|
||||
return new HasFeatures(Collections.<Class<?>>emptyList(), Arrays.asList(namedFeatures));
|
||||
return new HasFeatures(Collections.emptyList(), Arrays.asList(namedFeatures));
|
||||
}
|
||||
|
||||
public static HasFeatures namedFeature(String name, Class<?> type) {
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface CircuitBreaker {
|
||||
return run(toRun, throwable -> {
|
||||
throw new NoFallbackAvailableException("No fallback available.", throwable);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
<T> T run(Supplier<T> toRun, Function<Throwable, T> fallback);
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ enum CircuitBreakerObservationDocumentation implements ObservationDocumentation
|
||||
public String asString() {
|
||||
return "spring.cloud.circuitbreaker.type";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -52,8 +52,7 @@ public class EnableDiscoveryClientImportSelector extends SpringFactoryImportSele
|
||||
}
|
||||
else {
|
||||
Environment env = getEnvironment();
|
||||
if (ConfigurableEnvironment.class.isInstance(env)) {
|
||||
ConfigurableEnvironment configEnv = (ConfigurableEnvironment) env;
|
||||
if (env instanceof ConfigurableEnvironment configEnv) {
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("spring.cloud.service-registry.auto-registration.enabled", false);
|
||||
MapPropertySource propertySource = new MapPropertySource("springCloudDiscoveryClient", map);
|
||||
|
||||
@@ -63,12 +63,8 @@ public class DiscoveryClientHealthIndicatorProperties {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuffer sb = new StringBuffer("DiscoveryClientHealthIndicatorProperties{");
|
||||
sb.append("enabled=").append(this.enabled);
|
||||
sb.append(", includeDescription=").append(this.includeDescription);
|
||||
sb.append(", useServicesQuery=").append(this.useServicesQuery);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
return "DiscoveryClientHealthIndicatorProperties{" + "enabled=" + this.enabled + ", includeDescription="
|
||||
+ this.includeDescription + ", useServicesQuery=" + this.useServicesQuery + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class DiscoveryCompositeHealthContributor implements CompositeHealthContr
|
||||
}
|
||||
|
||||
private NamedContributor<HealthContributor> asNamedContributor(DiscoveryHealthIndicator indicator) {
|
||||
return new NamedContributor<HealthContributor>() {
|
||||
return new NamedContributor<>() {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ReactiveDiscoveryCompositeHealthContributor implements CompositeRea
|
||||
}
|
||||
|
||||
private NamedContributor<ReactiveHealthContributor> asNamedContributor(ReactiveDiscoveryHealthIndicator indicator) {
|
||||
return new NamedContributor<ReactiveHealthContributor>() {
|
||||
return new NamedContributor<>() {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.client.hypermedia;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.scheduling.config.ContextLifecycleScheduledTaskRegistrar;
|
||||
@@ -52,13 +53,8 @@ public class RemoteResourceRefresher extends ContextLifecycleScheduledTaskRegist
|
||||
public void afterPropertiesSet() {
|
||||
|
||||
for (final RemoteResource resource : this.discoveredResources) {
|
||||
addFixedDelayTask(new IntervalTask(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
resource.verifyOrDiscover();
|
||||
}
|
||||
}, this.fixedDelay, this.initialDelay));
|
||||
addFixedDelayTask(new IntervalTask(resource::verifyOrDiscover, Duration.ofMillis(fixedDelay),
|
||||
Duration.ofMillis(initialDelay)));
|
||||
}
|
||||
|
||||
super.afterPropertiesSet();
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ClientHttpResponseStatusCodeException extends RetryableStatusCodeEx
|
||||
*/
|
||||
public ClientHttpResponseStatusCodeException(String serviceId, ClientHttpResponse response, byte[] body)
|
||||
throws IOException {
|
||||
super(serviceId, response.getRawStatusCode(), response, null);
|
||||
super(serviceId, response.getStatusCode().value(), response, null);
|
||||
this.response = new ClientHttpResponseWrapper(response, body);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ClientHttpResponseStatusCodeException extends RetryableStatusCodeEx
|
||||
|
||||
@Override
|
||||
public int getRawStatusCode() throws IOException {
|
||||
return this.response.getRawStatusCode();
|
||||
return this.response.getStatusCode().value();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -59,10 +59,9 @@ public class DefaultRequest<T> implements Request<T> {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof DefaultRequest)) {
|
||||
if (!(o instanceof DefaultRequest<?> that)) {
|
||||
return false;
|
||||
}
|
||||
DefaultRequest<?> that = (DefaultRequest<?>) o;
|
||||
return Objects.equals(context, that.context);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,10 +62,9 @@ public class DefaultRequestContext extends HintRequestContext {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof DefaultRequestContext)) {
|
||||
if (!(o instanceof DefaultRequestContext that)) {
|
||||
return false;
|
||||
}
|
||||
DefaultRequestContext that = (DefaultRequestContext) o;
|
||||
return Objects.equals(clientRequest, that.clientRequest);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,10 +55,9 @@ public class DefaultResponse implements Response<ServiceInstance> {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof DefaultResponse)) {
|
||||
if (!(o instanceof DefaultResponse that)) {
|
||||
return false;
|
||||
}
|
||||
DefaultResponse that = (DefaultResponse) o;
|
||||
return Objects.equals(serviceInstance, that.serviceInstance);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,10 +72,9 @@ public class HintRequestContext implements TimedRequestContext {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof HintRequestContext)) {
|
||||
if (!(o instanceof HintRequestContext that)) {
|
||||
return false;
|
||||
}
|
||||
HintRequestContext that = (HintRequestContext) o;
|
||||
return Objects.equals(hint, that.hint);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,7 @@ public abstract class LoadBalancedRecoveryCallback<T, R> implements RecoveryCall
|
||||
public T recover(RetryContext context) throws Exception {
|
||||
Throwable lastThrowable = context.getLastThrowable();
|
||||
if (lastThrowable != null) {
|
||||
if (lastThrowable instanceof RetryableStatusCodeException) {
|
||||
RetryableStatusCodeException ex = (RetryableStatusCodeException) lastThrowable;
|
||||
if (lastThrowable instanceof RetryableStatusCodeException ex) {
|
||||
return createResponse((R) ex.getResponse(), ex.getUri());
|
||||
}
|
||||
else if (lastThrowable instanceof Exception) {
|
||||
|
||||
@@ -141,10 +141,9 @@ public class RequestData {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof RequestData)) {
|
||||
if (!(o instanceof RequestData that)) {
|
||||
return false;
|
||||
}
|
||||
RequestData that = (RequestData) o;
|
||||
return httpMethod == that.httpMethod && Objects.equals(url, that.url) && Objects.equals(headers, that.headers)
|
||||
&& Objects.equals(cookies, that.cookies) && Objects.equals(attributes, that.attributes);
|
||||
}
|
||||
|
||||
@@ -90,8 +90,7 @@ public class RetryLoadBalancerInterceptor implements ClientHttpRequestIntercepto
|
||||
RetryTemplate template = createRetryTemplate(serviceName, request, retryPolicy);
|
||||
return template.execute(context -> {
|
||||
ServiceInstance serviceInstance = null;
|
||||
if (context instanceof LoadBalancedRetryContext) {
|
||||
LoadBalancedRetryContext lbContext = (LoadBalancedRetryContext) context;
|
||||
if (context instanceof LoadBalancedRetryContext lbContext) {
|
||||
serviceInstance = lbContext.getServiceInstance();
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Retrieved service instance from LoadBalancedRetryContext: %s",
|
||||
@@ -109,8 +108,7 @@ public class RetryLoadBalancerInterceptor implements ClientHttpRequestIntercepto
|
||||
+ "Reattempting service instance selection");
|
||||
}
|
||||
ServiceInstance previousServiceInstance = null;
|
||||
if (context instanceof LoadBalancedRetryContext) {
|
||||
LoadBalancedRetryContext lbContext = (LoadBalancedRetryContext) context;
|
||||
if (context instanceof LoadBalancedRetryContext lbContext) {
|
||||
previousServiceInstance = lbContext.getPreviousServiceInstance();
|
||||
}
|
||||
DefaultRequest<RetryableRequestContext> lbRequest = new DefaultRequest<>(
|
||||
@@ -120,8 +118,7 @@ public class RetryLoadBalancerInterceptor implements ClientHttpRequestIntercepto
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Selected service instance: %s", serviceInstance));
|
||||
}
|
||||
if (context instanceof LoadBalancedRetryContext) {
|
||||
LoadBalancedRetryContext lbContext = (LoadBalancedRetryContext) context;
|
||||
if (context instanceof LoadBalancedRetryContext lbContext) {
|
||||
lbContext.setServiceInstance(serviceInstance);
|
||||
}
|
||||
Response<ServiceInstance> lbResponse = new DefaultResponse(serviceInstance);
|
||||
@@ -139,7 +136,7 @@ public class RetryLoadBalancerInterceptor implements ClientHttpRequestIntercepto
|
||||
new RetryableRequestContext(null, new RequestData(request), hint));
|
||||
ServiceInstance finalServiceInstance = serviceInstance;
|
||||
ClientHttpResponse response = loadBalancer.execute(serviceName, finalServiceInstance, lbRequest);
|
||||
int statusCode = response.getRawStatusCode();
|
||||
int statusCode = response.getStatusCode().value();
|
||||
if (retryPolicy != null && retryPolicy.retryableStatusCode(statusCode)) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Retrying on status code: %d", statusCode));
|
||||
|
||||
@@ -66,13 +66,12 @@ public class RetryableRequestContext extends RequestDataContext {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof RetryableRequestContext)) {
|
||||
if (!(o instanceof RetryableRequestContext context)) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
RetryableRequestContext context = (RetryableRequestContext) o;
|
||||
return Objects.equals(previousServiceInstance, context.previousServiceInstance);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class ReactorLoadBalancerExchangeFilterFunction implements LoadBalancedEx
|
||||
URI originalUrl = clientRequest.url();
|
||||
String serviceId = originalUrl.getHost();
|
||||
if (serviceId == null) {
|
||||
String message = String.format("Request URI does not contain a valid hostname: %s", originalUrl.toString());
|
||||
String message = String.format("Request URI does not contain a valid hostname: %s", originalUrl);
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn(message);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class RetryableLoadBalancerExchangeFilterFunction implements LoadBalanced
|
||||
URI originalUrl = clientRequest.url();
|
||||
String serviceId = originalUrl.getHost();
|
||||
if (serviceId == null) {
|
||||
String message = String.format("Request URI does not contain a valid hostname: %s", originalUrl.toString());
|
||||
String message = String.format("Request URI does not contain a valid hostname: %s", originalUrl);
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn(message);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public abstract class ConfigDataMissingEnvironmentPostProcessor implements Envir
|
||||
}
|
||||
|
||||
private boolean propertySourceWithConfigImport(PropertySource propertySource) {
|
||||
if (CompositePropertySource.class.isInstance(propertySource)) {
|
||||
if (propertySource instanceof CompositePropertySource) {
|
||||
return ((CompositePropertySource) propertySource).getPropertySources().stream()
|
||||
.anyMatch(this::propertySourceWithConfigImport);
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ public class CommonsConfigAutoConfiguration {
|
||||
@Nullable DefaultsBindHandlerAdvisor.MappingsProvider[] providers) {
|
||||
Map<ConfigurationPropertyName, ConfigurationPropertyName> additionalMappings = new HashMap<>();
|
||||
if (!ObjectUtils.isEmpty(providers)) {
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
DefaultsBindHandlerAdvisor.MappingsProvider mappingsProvider = providers[i];
|
||||
for (DefaultsBindHandlerAdvisor.MappingsProvider mappingsProvider : providers) {
|
||||
additionalMappings.putAll(mappingsProvider.getDefaultMappings());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.commons.httpclient;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -68,10 +67,7 @@ public class DefaultApacheHttpClientConnectionManagerFactory implements ApacheHt
|
||||
registryBuilder.register(HTTPS_SCHEME,
|
||||
new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE));
|
||||
}
|
||||
catch (NoSuchAlgorithmException e) {
|
||||
LOG.warn("Error creating SSLContext", e);
|
||||
}
|
||||
catch (KeyManagementException e) {
|
||||
catch (NoSuchAlgorithmException | KeyManagementException e) {
|
||||
LOG.warn("Error creating SSLContext", e);
|
||||
}
|
||||
}
|
||||
@@ -88,14 +84,14 @@ public class DefaultApacheHttpClientConnectionManagerFactory implements ApacheHt
|
||||
return connectionManager;
|
||||
}
|
||||
|
||||
class DisabledValidationTrustManager implements X509TrustManager {
|
||||
static class DisabledValidationTrustManager implements X509TrustManager {
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
|
||||
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
|
||||
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,10 +56,7 @@ public class DefaultOkHttpClientFactory implements OkHttpClientFactory {
|
||||
this.builder.sslSocketFactory(disabledSSLSocketFactory, disabledTrustManager);
|
||||
this.builder.hostnameVerifier(new TrustAllHostnames());
|
||||
}
|
||||
catch (NoSuchAlgorithmException e) {
|
||||
LOG.warn("Error setting SSLSocketFactory in OKHttpClient", e);
|
||||
}
|
||||
catch (KeyManagementException e) {
|
||||
catch (NoSuchAlgorithmException | KeyManagementException e) {
|
||||
LOG.warn("Error setting SSLSocketFactory in OKHttpClient", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.commons.httpclient;
|
||||
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
@@ -45,11 +44,11 @@ public interface OkHttpClientFactory {
|
||||
class DisableValidationTrustManager implements X509TrustManager {
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
|
||||
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
|
||||
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,14 +43,14 @@ public class TaskSchedulerWrapper<T extends TaskScheduler> implements Initializi
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
if (DisposableBean.class.isInstance(taskScheduler)) {
|
||||
if (taskScheduler instanceof DisposableBean) {
|
||||
((DisposableBean) this.taskScheduler).destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (InitializingBean.class.isInstance(taskScheduler)) {
|
||||
if (taskScheduler instanceof InitializingBean) {
|
||||
((InitializingBean) this.taskScheduler).afterPropertiesSet();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.configuration;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -37,7 +36,7 @@ public class CompatibilityVerifierProperties {
|
||||
* the patch version if you don't want to specify a concrete value. Example:
|
||||
* {@code 3.4.x}
|
||||
*/
|
||||
private List<String> compatibleBootVersions = Arrays.asList("3.0.x");
|
||||
private List<String> compatibleBootVersions = List.of("3.0.x");
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
|
||||
@@ -33,7 +33,7 @@ class SpringBootVersionVerifier implements CompatibilityVerifier {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SpringBootVersionVerifier.class);
|
||||
|
||||
final Map<String, CompatibilityPredicate> ACCEPTED_VERSIONS = new HashMap<String, CompatibilityPredicate>() {
|
||||
final Map<String, CompatibilityPredicate> ACCEPTED_VERSIONS = new HashMap<>() {
|
||||
{
|
||||
this.put("3.0", is3_0());
|
||||
}
|
||||
@@ -105,11 +105,12 @@ class SpringBootVersionVerifier implements CompatibilityVerifier {
|
||||
}
|
||||
|
||||
private String action() {
|
||||
return String.format("Change Spring Boot version to one of the following versions %s .\n"
|
||||
+ "You can find the latest Spring Boot versions here [%s]. \n"
|
||||
+ "If you want to learn more about the Spring Cloud Release train compatibility, you "
|
||||
+ "can visit this page [%s] and check the [Release Trains] section.\n"
|
||||
+ "If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]",
|
||||
return String.format(
|
||||
"""
|
||||
Change Spring Boot version to one of the following versions %s .
|
||||
You can find the latest Spring Boot versions here [%s].\s
|
||||
If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [%s] and check the [Release Trains] section.
|
||||
If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]""",
|
||||
this.acceptedVersions, "https://spring.io/projects/spring-boot#learn",
|
||||
"https://spring.io/projects/spring-cloud#overview");
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.configuration;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -48,13 +46,8 @@ public class TlsProperties {
|
||||
private String trustStorePassword = "";
|
||||
|
||||
private static Map<String, String> extTypes() {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
|
||||
result.put("p12", "PKCS12");
|
||||
result.put("pfx", "PKCS12");
|
||||
result.put("jks", "JKS");
|
||||
|
||||
return Collections.unmodifiableMap(result);
|
||||
return Map.of("p12", "PKCS12", "pfx", "PKCS12", "jks", "JKS");
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
|
||||
@@ -60,10 +60,9 @@ final class VerificationResult {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof VerificationResult)) {
|
||||
if (!(o instanceof VerificationResult that)) {
|
||||
return false;
|
||||
}
|
||||
VerificationResult that = (VerificationResult) o;
|
||||
return description.equals(that.description) && action.equals(that.action);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class EnableDiscoveryClientImportSelectorTests {
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
MockitoAnnotations.openMocks(this);
|
||||
this.importSelector.setBeanClassLoader(getClass().getClassLoader());
|
||||
this.importSelector.setEnvironment(this.environment);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.client.discovery.health;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -87,7 +87,7 @@ public class DiscoveryClientHealthIndicatorTests {
|
||||
public DiscoveryClient discoveryClient() {
|
||||
DiscoveryClient mock = mock(DiscoveryClient.class);
|
||||
given(mock.description()).willReturn("TestDiscoveryClient");
|
||||
given(mock.getServices()).willReturn(Arrays.asList("TestService1"));
|
||||
given(mock.getServices()).willReturn(List.of("TestService1"));
|
||||
return mock;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,31 +38,29 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
public class DiscoveryCompositeHealthContributorTests {
|
||||
|
||||
@Test
|
||||
public void createWhenIndicatorsAreNullThrowsException() throws Exception {
|
||||
public void createWhenIndicatorsAreNullThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new DiscoveryCompositeHealthContributor(null))
|
||||
.withMessage("'indicators' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContributorReturnsContributor() throws Exception {
|
||||
public void getContributorReturnsContributor() {
|
||||
TestDiscoveryHealthIndicator indicator = new TestDiscoveryHealthIndicator("test", Health.up().build());
|
||||
DiscoveryCompositeHealthContributor composite = new DiscoveryCompositeHealthContributor(
|
||||
Arrays.asList(indicator));
|
||||
DiscoveryCompositeHealthContributor composite = new DiscoveryCompositeHealthContributor(List.of(indicator));
|
||||
HealthIndicator adapted = (HealthIndicator) composite.getContributor("test");
|
||||
assertThat(adapted).isNotNull();
|
||||
assertThat(adapted.health()).isSameAs(indicator.health());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContributorWhenMissingReturnsNull() throws Exception {
|
||||
public void getContributorWhenMissingReturnsNull() {
|
||||
TestDiscoveryHealthIndicator indicator = new TestDiscoveryHealthIndicator("test", Health.up().build());
|
||||
DiscoveryCompositeHealthContributor composite = new DiscoveryCompositeHealthContributor(
|
||||
Arrays.asList(indicator));
|
||||
DiscoveryCompositeHealthContributor composite = new DiscoveryCompositeHealthContributor(List.of(indicator));
|
||||
assertThat((HealthIndicator) composite.getContributor("missing")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void iteratorIteratesNamedContributors() throws Exception {
|
||||
public void iteratorIteratesNamedContributors() {
|
||||
TestDiscoveryHealthIndicator indicator1 = new TestDiscoveryHealthIndicator("test1", Health.up().build());
|
||||
TestDiscoveryHealthIndicator indicator2 = new TestDiscoveryHealthIndicator("test2", Health.down().build());
|
||||
DiscoveryCompositeHealthContributor composite = new DiscoveryCompositeHealthContributor(
|
||||
|
||||
@@ -44,23 +44,23 @@ public class ClientHttpResponseStatusCodeExceptionTest {
|
||||
ClientHttpResponseStatusCodeException exp = new ClientHttpResponseStatusCodeException("service", response,
|
||||
response.getStatusText().getBytes());
|
||||
ClientHttpResponse expResponse = exp.getResponse();
|
||||
then(expResponse.getRawStatusCode()).isEqualTo(response.getRawStatusCode());
|
||||
then(expResponse.getStatusCode().value()).isEqualTo(response.getRawStatusCode());
|
||||
then(expResponse.getStatusText()).isEqualTo(response.getStatusText());
|
||||
then(expResponse.getHeaders()).isEqualTo(response.getHeaders());
|
||||
then(new String(StreamUtils.copyToByteArray(expResponse.getBody()))).isEqualTo(response.getStatusText());
|
||||
}
|
||||
|
||||
class MyClientHttpResponse extends AbstractClientHttpResponse {
|
||||
static class MyClientHttpResponse extends AbstractClientHttpResponse {
|
||||
|
||||
private boolean closed = false;
|
||||
|
||||
@Override
|
||||
public int getRawStatusCode() throws IOException {
|
||||
public int getRawStatusCode() {
|
||||
return 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatusText() throws IOException {
|
||||
public String getStatusText() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
|
||||
@@ -46,19 +46,19 @@ public class LoadBalancedRetryContextTest {
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
this.context = null;
|
||||
this.request = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequest() throws Exception {
|
||||
public void getRequest() {
|
||||
LoadBalancedRetryContext lbContext = new LoadBalancedRetryContext(this.context, this.request);
|
||||
then(lbContext.getRequest()).isEqualTo(this.request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setRequest() throws Exception {
|
||||
public void setRequest() {
|
||||
LoadBalancedRetryContext lbContext = new LoadBalancedRetryContext(this.context, this.request);
|
||||
HttpRequest newRequest = mock(HttpRequest.class);
|
||||
lbContext.setRequest(newRequest);
|
||||
@@ -66,7 +66,7 @@ public class LoadBalancedRetryContextTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServiceInstance() throws Exception {
|
||||
public void getServiceInstance() {
|
||||
LoadBalancedRetryContext lbContext = new LoadBalancedRetryContext(this.context, this.request);
|
||||
ServiceInstance serviceInstance = mock(ServiceInstance.class);
|
||||
lbContext.setServiceInstance(serviceInstance);
|
||||
|
||||
@@ -60,12 +60,10 @@ public class LoadBalancerRequestFactoryConfigurationTests {
|
||||
@Mock
|
||||
private ServiceInstance instance;
|
||||
|
||||
private byte[] body = new byte[] {};
|
||||
private final byte[] body = new byte[] {};
|
||||
|
||||
private ArgumentCaptor<HttpRequest> httpRequestCaptor;
|
||||
|
||||
private LoadBalancerRequestFactory lbReqFactory;
|
||||
|
||||
private LoadBalancerRequest<?> lbRequest;
|
||||
|
||||
@BeforeEach
|
||||
@@ -78,8 +76,8 @@ public class LoadBalancerRequestFactoryConfigurationTests {
|
||||
.properties("spring.aop.proxyTargetClass=true").sources(config, LoadBalancerAutoConfiguration.class)
|
||||
.run();
|
||||
|
||||
this.lbReqFactory = context.getBean(LoadBalancerRequestFactory.class);
|
||||
this.lbRequest = this.lbReqFactory.createRequest(this.request, this.body, this.execution);
|
||||
LoadBalancerRequestFactory lbReqFactory = context.getBean(LoadBalancerRequestFactory.class);
|
||||
this.lbRequest = lbReqFactory.createRequest(this.request, this.body, this.execution);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ public class LoadBalancerRequestFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testOneTransformer() throws Exception {
|
||||
List<LoadBalancerRequestTransformer> transformers = Arrays.asList(this.transformer1);
|
||||
List<LoadBalancerRequestTransformer> transformers = List.of(this.transformer1);
|
||||
when(this.transformer1.transformRequest(any(ServiceRequestWrapper.class), eq(this.instance)))
|
||||
.thenReturn(this.transformedRequest1);
|
||||
|
||||
|
||||
@@ -188,8 +188,6 @@ class TestServiceInstance implements ServiceInstance {
|
||||
|
||||
private String scheme = "http";
|
||||
|
||||
private String host = "test.example";
|
||||
|
||||
private int port = 8080;
|
||||
|
||||
private boolean secure;
|
||||
@@ -218,6 +216,7 @@ class TestServiceInstance implements ServiceInstance {
|
||||
|
||||
@Override
|
||||
public String getHost() {
|
||||
String host = "test.example";
|
||||
return host;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -34,6 +35,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
@@ -90,7 +92,7 @@ public class RetryLoadBalancerInterceptorTests {
|
||||
lbRequestFactory = mock(LoadBalancerRequestFactory.class);
|
||||
properties = new LoadBalancerProperties();
|
||||
properties.getRetry().setRetryOnAllExceptions(true);
|
||||
lbFactory = mock(ReactiveLoadBalancer.Factory.class, withSettings().lenient());
|
||||
lbFactory = mock(ReactiveLoadBalancer.Factory.class, withSettings().strictness(Strictness.LENIENT));
|
||||
when(lbFactory.getProperties(any())).thenReturn(properties);
|
||||
}
|
||||
|
||||
@@ -115,9 +117,7 @@ public class RetryLoadBalancerInterceptorTests {
|
||||
|
||||
when(lbRequestFactory.createRequest(any(), any(), any())).thenReturn(mock(LoadBalancerRequest.class));
|
||||
|
||||
Assertions.assertThrows(IOException.class, () -> {
|
||||
interceptor.intercept(request, body, execution);
|
||||
});
|
||||
Assertions.assertThrows(IOException.class, () -> interceptor.intercept(request, body, execution));
|
||||
verify(lbRequestFactory).createRequest(request, body, execution);
|
||||
}
|
||||
|
||||
@@ -130,9 +130,7 @@ public class RetryLoadBalancerInterceptorTests {
|
||||
loadBalancedRetryFactory, lbFactory);
|
||||
byte[] body = new byte[] {};
|
||||
ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
interceptor.intercept(request, body, execution);
|
||||
});
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> interceptor.intercept(request, body, execution));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -287,9 +285,7 @@ public class RetryLoadBalancerInterceptorTests {
|
||||
new MyLoadBalancedRetryFactory(policy), lbFactory);
|
||||
byte[] body = new byte[] {};
|
||||
ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
|
||||
Assertions.assertThrows(IOException.class, () -> {
|
||||
interceptor.intercept(request, body, execution);
|
||||
});
|
||||
Assertions.assertThrows(IOException.class, () -> interceptor.intercept(request, body, execution));
|
||||
verify(lbRequestFactory).createRequest(request, body, execution);
|
||||
}
|
||||
|
||||
@@ -369,9 +365,8 @@ public class RetryLoadBalancerInterceptorTests {
|
||||
new MyLoadBalancedRetryFactory(policy, backOffPolicy, new RetryListener[] { myRetryListener }),
|
||||
lbFactory);
|
||||
ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
|
||||
Assertions.assertThrows(TerminatedRetryException.class, () -> {
|
||||
interceptor.intercept(request, new byte[] {}, execution);
|
||||
});
|
||||
Assertions.assertThrows(TerminatedRetryException.class,
|
||||
() -> interceptor.intercept(request, new byte[] {}, execution));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -445,22 +440,12 @@ public class RetryLoadBalancerInterceptorTests {
|
||||
|
||||
@Override
|
||||
public BackOffPolicy createBackOffPolicy(String service) {
|
||||
if (backOffPolicy == null) {
|
||||
return new NoBackOffPolicy();
|
||||
}
|
||||
else {
|
||||
return backOffPolicy;
|
||||
}
|
||||
return Objects.requireNonNullElseGet(backOffPolicy, NoBackOffPolicy::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RetryListener[] createRetryListeners(String service) {
|
||||
if (retryListeners == null) {
|
||||
return new RetryListener[0];
|
||||
}
|
||||
else {
|
||||
return retryListeners;
|
||||
}
|
||||
return Objects.requireNonNullElseGet(retryListeners, () -> new RetryListener[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,8 +63,7 @@ class DiscoveryClientBasedReactiveLoadBalancer implements ReactiveLoadBalancer<S
|
||||
public Publisher<Response<ServiceInstance>> choose(Request request) {
|
||||
|
||||
List<ServiceInstance> instances = discoveryClient.getInstances(serviceId);
|
||||
if (request.getContext() instanceof RetryableRequestContext) {
|
||||
RetryableRequestContext context = (RetryableRequestContext) request.getContext();
|
||||
if (request.getContext() instanceof RetryableRequestContext context) {
|
||||
if (context.getPreviousServiceInstance() != null) {
|
||||
List<ServiceInstance> instancesCopy = discoveryClient.getInstances(serviceId);
|
||||
instancesCopy.remove(context.getPreviousServiceInstance());
|
||||
|
||||
@@ -96,7 +96,7 @@ class LoadBalancerClientRequestTransformerTest {
|
||||
assertThat(headers.getFirst("X-InstanceId")).isEqualTo("testServiceId");
|
||||
}
|
||||
|
||||
class Transformer1 implements LoadBalancerClientRequestTransformer {
|
||||
static class Transformer1 implements LoadBalancerClientRequestTransformer {
|
||||
|
||||
@Override
|
||||
public ClientRequest transformRequest(ClientRequest request, ServiceInstance instance) {
|
||||
@@ -105,7 +105,7 @@ class LoadBalancerClientRequestTransformerTest {
|
||||
|
||||
}
|
||||
|
||||
class Transformer2 implements LoadBalancerClientRequestTransformer {
|
||||
static class Transformer2 implements LoadBalancerClientRequestTransformer {
|
||||
|
||||
@Override
|
||||
public ClientRequest transformRequest(ClientRequest request, ServiceInstance instance) {
|
||||
|
||||
@@ -166,7 +166,7 @@ public class ReactorLoadBalancerClientAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
ReactiveLoadBalancer.Factory<ServiceInstance> reactiveLoadBalancerFactory(LoadBalancerProperties properties) {
|
||||
return new ReactiveLoadBalancer.Factory<ServiceInstance>() {
|
||||
return new ReactiveLoadBalancer.Factory<>() {
|
||||
@Override
|
||||
public ReactiveLoadBalancer<ServiceInstance> getInstance(String serviceId) {
|
||||
return new TestReactiveLoadBalancer();
|
||||
@@ -211,7 +211,7 @@ public class ReactorLoadBalancerClientAutoConfigurationTests {
|
||||
return new TestService(loadBalancedWebClientBuilder());
|
||||
}
|
||||
|
||||
private final class TestService {
|
||||
private static final class TestService {
|
||||
|
||||
public final WebClient webClient;
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ class ReactorLoadBalancerExchangeFilterFunctionTests {
|
||||
@Bean
|
||||
ReactiveLoadBalancer.Factory<ServiceInstance> reactiveLoadBalancerFactory(DiscoveryClient discoveryClient,
|
||||
LoadBalancerProperties properties) {
|
||||
return new ReactiveLoadBalancer.Factory<ServiceInstance>() {
|
||||
return new ReactiveLoadBalancer.Factory<>() {
|
||||
|
||||
private final TestLoadBalancerLifecycle testLoadBalancerLifecycle = new TestLoadBalancerLifecycle();
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ class RetryableLoadBalancerExchangeFilterFunctionIntegrationTests {
|
||||
@Bean
|
||||
ReactiveLoadBalancer.Factory<ServiceInstance> reactiveLoadBalancerFactory(DiscoveryClient discoveryClient,
|
||||
LoadBalancerProperties properties) {
|
||||
return new ReactiveLoadBalancer.Factory<ServiceInstance>() {
|
||||
return new ReactiveLoadBalancer.Factory<>() {
|
||||
|
||||
private final TestLoadBalancerLifecycle testLoadBalancerLifecycle = new TestLoadBalancerLifecycle();
|
||||
|
||||
|
||||
@@ -110,7 +110,8 @@ public class ConfigDataMissingEnvironmentPostProcessorTests {
|
||||
assertThat(output).doesNotContain("Error binding spring.config.import");
|
||||
}
|
||||
|
||||
public class TestConfigDataMissingEnvironmentPostProcessor extends ConfigDataMissingEnvironmentPostProcessor {
|
||||
static public class TestConfigDataMissingEnvironmentPostProcessor
|
||||
extends ConfigDataMissingEnvironmentPostProcessor {
|
||||
|
||||
@Override
|
||||
protected boolean shouldProcessEnvironment(Environment environment) {
|
||||
|
||||
@@ -53,27 +53,27 @@ public class CustomHttpClientConfigurationTests {
|
||||
OkHttpClientConnectionPoolFactory okHttpClientConnectionPoolFactory;
|
||||
|
||||
@Test
|
||||
public void connManFactory() throws Exception {
|
||||
public void connManFactory() {
|
||||
then(ApacheHttpClientConnectionManagerFactory.class.isInstance(this.connectionManagerFactory)).isTrue();
|
||||
then(CustomApplication.MyApacheHttpClientConnectionManagerFactory.class
|
||||
.isInstance(this.connectionManagerFactory)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void apacheHttpClientFactory() throws Exception {
|
||||
public void apacheHttpClientFactory() {
|
||||
then(ApacheHttpClientFactory.class.isInstance(this.httpClientFactory)).isTrue();
|
||||
then(CustomApplication.MyApacheHttpClientFactory.class.isInstance(this.httpClientFactory)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionPoolFactory() throws Exception {
|
||||
public void connectionPoolFactory() {
|
||||
then(OkHttpClientConnectionPoolFactory.class.isInstance(this.okHttpClientConnectionPoolFactory)).isTrue();
|
||||
then(CustomApplication.MyOkHttpConnectionPoolFactory.class.isInstance(this.okHttpClientConnectionPoolFactory))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void okHttpClientFactory() throws Exception {
|
||||
public void okHttpClientFactory() {
|
||||
then(OkHttpClientFactory.class.isInstance(this.okHttpClientFactory)).isTrue();
|
||||
then(CustomApplication.MyOkHttpClientFactory.class.isInstance(this.okHttpClientFactory)).isTrue();
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.mockito.Mockito.mock;
|
||||
public class DefaultApacheHttpClientFactoryTests {
|
||||
|
||||
@Test
|
||||
public void createClient() throws Exception {
|
||||
public void createClient() {
|
||||
final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(100).setConnectTimeout(200)
|
||||
.setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
|
||||
CloseableHttpClient httpClient = new DefaultApacheHttpClientFactory(HttpClientBuilder.create()).createBuilder()
|
||||
|
||||
@@ -45,26 +45,26 @@ public class DefaultHttpClientConfigurationTests {
|
||||
OkHttpClientConnectionPoolFactory okHttpClientConnectionPoolFactory;
|
||||
|
||||
@Test
|
||||
public void connManFactory() throws Exception {
|
||||
public void connManFactory() {
|
||||
then(ApacheHttpClientConnectionManagerFactory.class.isInstance(this.connectionManagerFactory)).isTrue();
|
||||
then(DefaultApacheHttpClientConnectionManagerFactory.class.isInstance(this.connectionManagerFactory)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void apacheHttpClientFactory() throws Exception {
|
||||
public void apacheHttpClientFactory() {
|
||||
then(ApacheHttpClientFactory.class.isInstance(this.httpClientFactory)).isTrue();
|
||||
then(DefaultApacheHttpClientFactory.class.isInstance(this.httpClientFactory)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connPoolFactory() throws Exception {
|
||||
public void connPoolFactory() {
|
||||
then(OkHttpClientConnectionPoolFactory.class.isInstance(this.okHttpClientConnectionPoolFactory)).isTrue();
|
||||
then(DefaultOkHttpClientConnectionPoolFactory.class.isInstance(this.okHttpClientConnectionPoolFactory))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setOkHttpClientFactory() throws Exception {
|
||||
public void setOkHttpClientFactory() {
|
||||
then(OkHttpClientFactory.class.isInstance(this.okHttpClientFactory)).isTrue();
|
||||
then(DefaultOkHttpClientFactory.class.isInstance(this.okHttpClientFactory)).isTrue();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ResourceServerTokenRelayTests {
|
||||
AccessTokenContextRelay accessTokenContextRelay;
|
||||
|
||||
@Test
|
||||
public void tokenRelayJWT() throws Exception {
|
||||
public void tokenRelayJWT() {
|
||||
|
||||
mockServerToReceiveRelay.expect(requestTo("https://example.com/test"))
|
||||
.andExpect(header("authorization", AUTH_HEADER_TO_BE_RELAYED))
|
||||
@@ -82,7 +82,7 @@ public class ResourceServerTokenRelayTests {
|
||||
ResponseEntity<String> exchange = testRestTemplate.exchange("/token-relay", HttpMethod.GET, authorizationHeader,
|
||||
String.class);
|
||||
|
||||
assertThat(exchange.getStatusCodeValue()).isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(exchange.getStatusCode().value()).isEqualTo(HttpStatus.OK.value());
|
||||
assertThat(exchange.getBody()).isEqualTo(TEST_RESPONSE);
|
||||
|
||||
mockServerToReceiveRelay.verify();
|
||||
@@ -92,7 +92,7 @@ public class ResourceServerTokenRelayTests {
|
||||
private HttpEntity<String> createAuthorizationHeader() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Authorization", AUTH_HEADER_TO_BE_RELAYED);
|
||||
return new HttpEntity<String>("parameters", headers);
|
||||
return new HttpEntity<>("parameters", headers);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ public class CompatibilityVerifierTests {
|
||||
|
||||
@Test
|
||||
public void should_not_print_the_report_when_no_errors_were_found(CapturedOutput output) {
|
||||
CompositeCompatibilityVerifier verifier = new CompositeCompatibilityVerifier(
|
||||
new ArrayList<CompatibilityVerifier>());
|
||||
CompositeCompatibilityVerifier verifier = new CompositeCompatibilityVerifier(new ArrayList<>());
|
||||
|
||||
verifier.verifyDependencies();
|
||||
|
||||
@@ -47,18 +46,8 @@ public class CompatibilityVerifierTests {
|
||||
@Test
|
||||
public void should_print_the_report_when_errors_were_found() {
|
||||
List<CompatibilityVerifier> list = new ArrayList<>();
|
||||
list.add(new CompatibilityVerifier() {
|
||||
@Override
|
||||
public VerificationResult verify() {
|
||||
return VerificationResult.notCompatible("Wrong Boot version", "Use Boot version 1.2");
|
||||
}
|
||||
});
|
||||
list.add(new CompatibilityVerifier() {
|
||||
@Override
|
||||
public VerificationResult verify() {
|
||||
return VerificationResult.notCompatible("Wrong JDK version", "Use JDK 25");
|
||||
}
|
||||
});
|
||||
list.add(() -> VerificationResult.notCompatible("Wrong Boot version", "Use Boot version 1.2"));
|
||||
list.add(() -> VerificationResult.notCompatible("Wrong JDK version", "Use JDK 25"));
|
||||
CompositeCompatibilityVerifier verifier = new CompositeCompatibilityVerifier(list);
|
||||
|
||||
try {
|
||||
|
||||
@@ -51,7 +51,7 @@ public class KeyAndCert {
|
||||
}
|
||||
|
||||
public String subject() {
|
||||
String dn = certificate.getSubjectDN().getName();
|
||||
String dn = certificate.getSubjectX500Principal().getName();
|
||||
int index = dn.indexOf('=');
|
||||
return dn.substring(index + 1);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class SSHContextFactoryTests {
|
||||
}
|
||||
|
||||
private static File saveCert(KeyAndCert keyCert) throws Exception {
|
||||
return saveKeyStore(keyCert.subject(), () -> keyCert.storeCert());
|
||||
return saveKeyStore(keyCert.subject(), keyCert::storeCert);
|
||||
}
|
||||
|
||||
private static File saveKeyStore(String prefix, KeyStoreSupplier func) throws Exception {
|
||||
|
||||
@@ -70,7 +70,7 @@ public class RefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
public void testSimpleProperties() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.service instanceof Advised).isTrue();
|
||||
// Change the dynamic property source...
|
||||
@@ -83,7 +83,7 @@ public class RefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
public void testRefresh() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
@@ -101,7 +101,7 @@ public class RefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshBean() throws Exception {
|
||||
public void testRefreshBean() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
@@ -121,10 +121,8 @@ public class RefreshScopeIntegrationTests {
|
||||
// see gh-349
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCheckedException() throws Exception {
|
||||
Assertions.assertThrows(ServiceException.class, () -> {
|
||||
this.service.throwsException();
|
||||
});
|
||||
public void testCheckedException() {
|
||||
Assertions.assertThrows(ServiceException.class, () -> this.service.throwsException());
|
||||
}
|
||||
|
||||
public interface Service {
|
||||
@@ -169,13 +167,13 @@ public class RefreshScopeIntegrationTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
public void afterPropertiesSet() {
|
||||
logger.debug("Initializing message: " + this.message);
|
||||
initCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
public void destroy() {
|
||||
logger.debug("Destroying message: " + this.message);
|
||||
destroyCount++;
|
||||
this.message = null;
|
||||
|
||||
@@ -288,7 +288,7 @@ public class BootstrapApplicationListener implements ApplicationListener<Applica
|
||||
if (application.getAllSources().contains(BootstrapMarkerConfiguration.class)) {
|
||||
return;
|
||||
}
|
||||
application.addPrimarySources(Arrays.asList(BootstrapMarkerConfiguration.class));
|
||||
application.addPrimarySources(List.of(BootstrapMarkerConfiguration.class));
|
||||
@SuppressWarnings("rawtypes")
|
||||
Set target = new LinkedHashSet<>(application.getInitializers());
|
||||
target.addAll(getOrderedBeansOfType(context, ApplicationContextInitializer.class));
|
||||
@@ -315,13 +315,12 @@ public class BootstrapApplicationListener implements ApplicationListener<Applica
|
||||
initializers.add(ini);
|
||||
}
|
||||
}
|
||||
ArrayList<ApplicationContextInitializer<?>> target = new ArrayList<ApplicationContextInitializer<?>>(
|
||||
initializers);
|
||||
ArrayList<ApplicationContextInitializer<?>> target = new ArrayList<>(initializers);
|
||||
application.setInitializers(target);
|
||||
}
|
||||
|
||||
private <T> List<T> getOrderedBeansOfType(ListableBeanFactory context, Class<T> type) {
|
||||
List<T> result = new ArrayList<T>();
|
||||
List<T> result = new ArrayList<>();
|
||||
for (String name : context.getBeanNamesForType(type)) {
|
||||
result.add(context.getBean(name, type));
|
||||
}
|
||||
@@ -375,8 +374,7 @@ public class BootstrapApplicationListener implements ApplicationListener<Applica
|
||||
|
||||
private void reorderSources(ConfigurableEnvironment environment) {
|
||||
PropertySource<?> removed = environment.getPropertySources().remove(DEFAULT_PROPERTIES);
|
||||
if (removed instanceof ExtendedDefaultPropertySource) {
|
||||
ExtendedDefaultPropertySource defaultProperties = (ExtendedDefaultPropertySource) removed;
|
||||
if (removed instanceof ExtendedDefaultPropertySource defaultProperties) {
|
||||
environment.getPropertySources()
|
||||
.addLast(new MapPropertySource(DEFAULT_PROPERTIES, defaultProperties.getSource()));
|
||||
for (PropertySource<?> source : defaultProperties.getPropertySources().getPropertySources()) {
|
||||
@@ -428,7 +426,7 @@ public class BootstrapApplicationListener implements ApplicationListener<Applica
|
||||
if (propertySource instanceof MapPropertySource) {
|
||||
return (Map<String, Object>) propertySource.getSource();
|
||||
}
|
||||
return new LinkedHashMap<String, Object>();
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
public CompositePropertySource getPropertySources() {
|
||||
|
||||
@@ -135,10 +135,7 @@ public class BootstrapConfigFileApplicationListener
|
||||
private static final Set<String> LOAD_FILTERED_PROPERTY;
|
||||
|
||||
static {
|
||||
Set<String> filteredProperties = new HashSet<>();
|
||||
filteredProperties.add("spring.profiles.active");
|
||||
filteredProperties.add("spring.profiles.include");
|
||||
LOAD_FILTERED_PROPERTY = Collections.unmodifiableSet(filteredProperties);
|
||||
LOAD_FILTERED_PROPERTY = Set.of("spring.profiles.active", "spring.profiles.include");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,8 +47,7 @@ public class BootstrapPropertySource<T> extends EnumerablePropertySource<T> {
|
||||
|
||||
@Override
|
||||
public String[] getPropertyNames() {
|
||||
Set<String> names = new LinkedHashSet<>();
|
||||
names.addAll(Arrays.asList(this.delegate.getPropertyNames()));
|
||||
Set<String> names = new LinkedHashSet<>(Arrays.asList(this.delegate.getPropertyNames()));
|
||||
|
||||
return StringUtils.toStringArray(names);
|
||||
}
|
||||
|
||||
@@ -98,8 +98,7 @@ public class PropertySourceBootstrapConfiguration
|
||||
}
|
||||
List<PropertySource<?>> sourceList = new ArrayList<>();
|
||||
for (PropertySource<?> p : source) {
|
||||
if (p instanceof EnumerablePropertySource) {
|
||||
EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) p;
|
||||
if (p instanceof EnumerablePropertySource<?> enumerable) {
|
||||
sourceList.add(new BootstrapPropertySource<>(enumerable));
|
||||
}
|
||||
else {
|
||||
@@ -153,7 +152,7 @@ public class PropertySourceBootstrapConfiguration
|
||||
rebinder.setEnvironment(environment);
|
||||
// We can't fire the event in the ApplicationContext here (too early), but we can
|
||||
// create our own listener and poke it (it doesn't need the key changes)
|
||||
rebinder.onApplicationEvent(new EnvironmentChangeEvent(applicationContext, Collections.<String>emptySet()));
|
||||
rebinder.onApplicationEvent(new EnvironmentChangeEvent(applicationContext, Collections.emptySet()));
|
||||
}
|
||||
|
||||
private void insertPropertySources(MutablePropertySources propertySources, List<PropertySource<?>> composite) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.bootstrap.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -52,7 +51,7 @@ public interface PropertySourceLocator {
|
||||
if (propertySource == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (CompositePropertySource.class.isInstance(propertySource)) {
|
||||
if (propertySource instanceof CompositePropertySource) {
|
||||
Collection<PropertySource<?>> sources = ((CompositePropertySource) propertySource).getPropertySources();
|
||||
List<PropertySource<?>> filteredSources = new ArrayList<>();
|
||||
for (PropertySource<?> p : sources) {
|
||||
@@ -63,7 +62,7 @@ public interface PropertySourceLocator {
|
||||
return filteredSources;
|
||||
}
|
||||
else {
|
||||
return Arrays.asList(propertySource);
|
||||
return List.of(propertySource);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,11 +94,10 @@ public abstract class AbstractEnvironmentDecrypt {
|
||||
}
|
||||
|
||||
}
|
||||
else if (source instanceof EnumerablePropertySource) {
|
||||
else if (source instanceof EnumerablePropertySource<?> enumerable) {
|
||||
Map<String, Object> otherCollectionProperties = new LinkedHashMap<>();
|
||||
boolean sourceHasDecryptedCollection = false;
|
||||
|
||||
EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
|
||||
for (String key : enumerable.getPropertyNames()) {
|
||||
Object property = source.getProperty(key);
|
||||
if (property != null) {
|
||||
|
||||
@@ -113,8 +113,7 @@ public class EnvironmentDecryptApplicationInitializer extends AbstractEnvironmen
|
||||
private void insert(ApplicationContext applicationContext, PropertySource<?> propertySource) {
|
||||
ApplicationContext parent = applicationContext;
|
||||
while (parent != null) {
|
||||
if (parent.getEnvironment() instanceof ConfigurableEnvironment) {
|
||||
ConfigurableEnvironment mutable = (ConfigurableEnvironment) parent.getEnvironment();
|
||||
if (parent.getEnvironment() instanceof ConfigurableEnvironment mutable) {
|
||||
insert(mutable.getPropertySources(), propertySource);
|
||||
}
|
||||
parent = parent.getParent();
|
||||
|
||||
@@ -35,8 +35,7 @@ public class OriginTrackedCompositePropertySource extends CompositePropertySourc
|
||||
@SuppressWarnings("unchecked")
|
||||
public Origin getOrigin(String name) {
|
||||
for (PropertySource<?> propertySource : getPropertySources()) {
|
||||
if (propertySource instanceof OriginLookup) {
|
||||
OriginLookup lookup = (OriginLookup) propertySource;
|
||||
if (propertySource instanceof OriginLookup lookup) {
|
||||
Origin origin = lookup.getOrigin(name);
|
||||
if (origin != null) {
|
||||
return origin;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class EnvironmentManager implements ApplicationEventPublisherAware {
|
||||
|
||||
private static final String MANAGER_PROPERTY_SOURCE = "manager";
|
||||
|
||||
private Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
private Map<String, Object> map = new LinkedHashMap<>();
|
||||
|
||||
private ConfigurableEnvironment environment;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class EnvironmentManager implements ApplicationEventPublisherAware {
|
||||
|
||||
@ManagedOperation
|
||||
public Map<String, Object> reset() {
|
||||
Map<String, Object> result = new LinkedHashMap<String, Object>(this.map);
|
||||
Map<String, Object> result = new LinkedHashMap<>(this.map);
|
||||
if (!this.map.isEmpty()) {
|
||||
this.map.clear();
|
||||
publish(new EnvironmentChangeEvent(this.publisher, result.keySet()));
|
||||
|
||||
@@ -57,9 +57,7 @@ public class ConfigurationPropertiesBeans implements BeanPostProcessor, Applicat
|
||||
this.beanFactory = (ConfigurableListableBeanFactory) applicationContext.getAutowireCapableBeanFactory();
|
||||
}
|
||||
if (applicationContext.getParent() != null && applicationContext.getParent()
|
||||
.getAutowireCapableBeanFactory() instanceof ConfigurableListableBeanFactory) {
|
||||
ConfigurableListableBeanFactory listable = (ConfigurableListableBeanFactory) applicationContext.getParent()
|
||||
.getAutowireCapableBeanFactory();
|
||||
.getAutowireCapableBeanFactory() instanceof ConfigurableListableBeanFactory listable) {
|
||||
String[] names = listable.getBeanNamesForType(ConfigurationPropertiesBeans.class);
|
||||
if (names.length == 1) {
|
||||
this.parent = (ConfigurationPropertiesBeans) listable.getBean(names[0]);
|
||||
@@ -105,7 +103,7 @@ public class ConfigurationPropertiesBeans implements BeanPostProcessor, Applicat
|
||||
}
|
||||
|
||||
public Set<String> getBeanNames() {
|
||||
return new HashSet<String>(this.beans.keySet());
|
||||
return new HashSet<>(this.beans.keySet());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public abstract class ContextRefresher {
|
||||
}
|
||||
|
||||
private Map<String, Object> changes(Map<String, Object> before, Map<String, Object> after) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
for (String key : before.keySet()) {
|
||||
if (!after.containsKey(key)) {
|
||||
result.put(key, null);
|
||||
@@ -162,8 +162,8 @@ public abstract class ContextRefresher {
|
||||
}
|
||||
|
||||
private Map<String, Object> extract(MutablePropertySources propertySources) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
List<PropertySource<?>> sources = new ArrayList<PropertySource<?>>();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<PropertySource<?>> sources = new ArrayList<>();
|
||||
for (PropertySource<?> source : propertySources) {
|
||||
sources.add(0, source);
|
||||
}
|
||||
@@ -178,7 +178,7 @@ public abstract class ContextRefresher {
|
||||
private void extract(PropertySource<?> parent, Map<String, Object> result) {
|
||||
if (parent instanceof CompositePropertySource) {
|
||||
try {
|
||||
List<PropertySource<?>> sources = new ArrayList<PropertySource<?>>();
|
||||
List<PropertySource<?>> sources = new ArrayList<>();
|
||||
for (PropertySource<?> source : ((CompositePropertySource) parent).getPropertySources()) {
|
||||
sources.add(0, source);
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ public class RestartEndpoint implements ApplicationListener<ApplicationPreparedE
|
||||
|
||||
@Override
|
||||
public void initialize(GenericApplicationContext context) {
|
||||
context.registerBean(PostProcessor.class, () -> new PostProcessor());
|
||||
context.registerBean(PostProcessor.class, PostProcessor::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class GenericScope
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
List<Throwable> errors = new ArrayList<Throwable>();
|
||||
List<Throwable> errors = new ArrayList<>();
|
||||
Collection<BeanLifecycleWrapper> wrappers = this.cache.clear();
|
||||
for (BeanLifecycleWrapper wrapper : wrappers) {
|
||||
try {
|
||||
@@ -243,8 +243,7 @@ public class GenericScope
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
|
||||
for (String name : registry.getBeanDefinitionNames()) {
|
||||
BeanDefinition definition = registry.getBeanDefinition(name);
|
||||
if (definition instanceof RootBeanDefinition) {
|
||||
RootBeanDefinition root = (RootBeanDefinition) definition;
|
||||
if (definition instanceof RootBeanDefinition root) {
|
||||
if (root.getDecoratedDefinition() != null && root.hasBeanClass()
|
||||
&& root.getBeanClass() == ScopedProxyFactoryBean.class) {
|
||||
if (getName().equals(root.getDecoratedDefinition().getBeanDefinition().getScope())) {
|
||||
@@ -321,7 +320,7 @@ public class GenericScope
|
||||
|
||||
public Collection<BeanLifecycleWrapper> clear() {
|
||||
Collection<Object> values = this.cache.clear();
|
||||
Collection<BeanLifecycleWrapper> wrappers = new LinkedHashSet<BeanLifecycleWrapper>();
|
||||
Collection<BeanLifecycleWrapper> wrappers = new LinkedHashSet<>();
|
||||
for (Object object : values) {
|
||||
wrappers.add((BeanLifecycleWrapper) object);
|
||||
}
|
||||
@@ -448,8 +447,7 @@ public class GenericScope
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
super.setBeanFactory(beanFactory);
|
||||
Object proxy = getObject();
|
||||
if (proxy instanceof Advised) {
|
||||
Advised advised = (Advised) proxy;
|
||||
if (proxy instanceof Advised advised) {
|
||||
advised.addAdvice(0, this);
|
||||
}
|
||||
}
|
||||
@@ -479,8 +477,7 @@ public class GenericScope
|
||||
Lock lock = readWriteLock.readLock();
|
||||
lock.lock();
|
||||
try {
|
||||
if (proxy instanceof Advised) {
|
||||
Advised advised = (Advised) proxy;
|
||||
if (proxy instanceof Advised advised) {
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
return ReflectionUtils.invokeMethod(method, advised.getTargetSource().getTarget(),
|
||||
invocation.getArguments());
|
||||
|
||||
@@ -29,14 +29,14 @@ import java.util.concurrent.ConcurrentMap;
|
||||
*/
|
||||
public class StandardScopeCache implements ScopeCache {
|
||||
|
||||
private final ConcurrentMap<String, Object> cache = new ConcurrentHashMap<String, Object>();
|
||||
private final ConcurrentMap<String, Object> cache = new ConcurrentHashMap<>();
|
||||
|
||||
public Object remove(String name) {
|
||||
return this.cache.remove(name);
|
||||
}
|
||||
|
||||
public Collection<Object> clear() {
|
||||
Collection<Object> values = new ArrayList<Object>(this.cache.values());
|
||||
Collection<Object> values = new ArrayList<>(this.cache.values());
|
||||
this.cache.clear();
|
||||
return values;
|
||||
}
|
||||
|
||||
@@ -29,11 +29,7 @@ import org.springframework.cloud.context.scope.ScopeCache;
|
||||
*/
|
||||
public class ThreadLocalScopeCache implements ScopeCache {
|
||||
|
||||
private ThreadLocal<ConcurrentMap<String, Object>> data = new ThreadLocal<ConcurrentMap<String, Object>>() {
|
||||
protected ConcurrentMap<String, Object> initialValue() {
|
||||
return new ConcurrentHashMap<String, Object>();
|
||||
}
|
||||
};
|
||||
private ThreadLocal<ConcurrentMap<String, Object>> data = ThreadLocal.withInitial(ConcurrentHashMap::new);
|
||||
|
||||
public Object remove(String name) {
|
||||
return this.data.get().remove(name);
|
||||
@@ -41,7 +37,7 @@ public class ThreadLocalScopeCache implements ScopeCache {
|
||||
|
||||
public Collection<Object> clear() {
|
||||
ConcurrentMap<String, Object> map = this.data.get();
|
||||
Collection<Object> values = new ArrayList<Object>(map.values());
|
||||
Collection<Object> values = new ArrayList<>(map.values());
|
||||
map.clear();
|
||||
return values;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class RefreshScopeHealthIndicator extends AbstractHealthIndicator {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doHealthCheck(Builder builder) throws Exception {
|
||||
protected void doHealthCheck(Builder builder) {
|
||||
RefreshScope refreshScope = this.scope.getIfAvailable();
|
||||
if (refreshScope != null) {
|
||||
Map<String, Exception> errors = new HashMap<>(refreshScope.getErrors());
|
||||
|
||||
@@ -67,7 +67,7 @@ public class LoggingRebinder implements ApplicationListener<EnvironmentChangeEve
|
||||
Map<String, String> levels = Binder.get(environment).bind("logging.level", STRING_STRING_MAP)
|
||||
.orElseGet(Collections::emptyMap);
|
||||
for (Entry<String, String> entry : levels.entrySet()) {
|
||||
setLogLevel(system, environment, entry.getKey(), entry.getValue().toString());
|
||||
setLogLevel(system, environment, entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class CachedRandomPropertySource extends PropertySource<PropertySource> {
|
||||
|
||||
CachedRandomPropertySource(PropertySource randomValuePropertySource, Map<String, Map<String, Object>> cache) {
|
||||
super(NAME, randomValuePropertySource);
|
||||
this.cache = cache;
|
||||
CachedRandomPropertySource.cache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -66,8 +66,8 @@ public class BootstrapOrderingCustomPropertySourceIntegrationTests {
|
||||
// This is added to bootstrap context as a source in bootstrap.properties
|
||||
protected static class PropertySourceConfiguration implements PropertySourceLocator {
|
||||
|
||||
public static Map<String, Object> MAP = new HashMap<String, Object>(Collections.<String, Object>singletonMap(
|
||||
"custom.foo", "{cipher}6154ca04d4bb6144d672c4e3d750b5147116dd381946d51fa44f8bc25dc256f4"));
|
||||
public static Map<String, Object> MAP = new HashMap<>(Collections.<String, Object>singletonMap("custom.foo",
|
||||
"{cipher}6154ca04d4bb6144d672c4e3d750b5147116dd381946d51fa44f8bc25dc256f4"));
|
||||
|
||||
@Override
|
||||
public PropertySource<?> locate(Environment environment) {
|
||||
|
||||
@@ -60,16 +60,10 @@ public class TestBootstrapConfiguration {
|
||||
|
||||
@Bean
|
||||
public ApplicationContextInitializer<ConfigurableApplicationContext> customInitializer() {
|
||||
return new ApplicationContextInitializer<ConfigurableApplicationContext>() {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
ConfigurableEnvironment environment = applicationContext.getEnvironment();
|
||||
environment.getPropertySources().addLast(
|
||||
new MapPropertySource("customProperties", Collections.<String, Object>singletonMap("custom.foo",
|
||||
environment.resolvePlaceholders("${spring.application.name:bar}"))));
|
||||
}
|
||||
|
||||
return applicationContext -> {
|
||||
ConfigurableEnvironment environment = applicationContext.getEnvironment();
|
||||
environment.getPropertySources().addLast(new MapPropertySource("customProperties", Collections
|
||||
.singletonMap("custom.foo", environment.resolvePlaceholders("${spring.application.name:bar}"))));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
@@ -108,12 +107,9 @@ public class BootstrapConfigurationTests {
|
||||
public void bootstrapPropertiesAvailableInInitializer() {
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties("spring.cloud.bootstrap.enabled=true").sources(BareConfiguration.class)
|
||||
.initializers(new ApplicationContextInitializer<ConfigurableApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
// This property is defined in bootstrap.properties
|
||||
then(applicationContext.getEnvironment().getProperty("info.name")).isEqualTo("child");
|
||||
}
|
||||
.initializers(applicationContext -> {
|
||||
// This property is defined in bootstrap.properties
|
||||
then(applicationContext.getEnvironment().getProperty("info.name")).isEqualTo("child");
|
||||
}).run();
|
||||
then(this.context.getEnvironment().getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap"))
|
||||
@@ -144,10 +140,9 @@ public class BootstrapConfigurationTests {
|
||||
@Test
|
||||
public void failsOnPropertySource() {
|
||||
System.setProperty("expected.fail", "true");
|
||||
Throwable throwable = Assertions.assertThrows(RuntimeException.class, () -> {
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties("spring.cloud.bootstrap.enabled=true").sources(BareConfiguration.class).run();
|
||||
});
|
||||
Throwable throwable = Assertions.assertThrows(RuntimeException.class,
|
||||
() -> this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties("spring.cloud.bootstrap.enabled=true").sources(BareConfiguration.class).run());
|
||||
then(throwable.getMessage().equals("Planned"));
|
||||
}
|
||||
|
||||
@@ -201,8 +196,8 @@ public class BootstrapConfigurationTests {
|
||||
PropertySourceConfiguration.MAP.put("spring.cloud.config.overrideNone", "true");
|
||||
PropertySourceConfiguration.MAP.put("spring.cloud.config.allowOverride", "true");
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
environment.getPropertySources().addLast(
|
||||
new MapPropertySource("last", Collections.<String, Object>singletonMap("bootstrap.foo", "splat")));
|
||||
environment.getPropertySources()
|
||||
.addLast(new MapPropertySource("last", Collections.singletonMap("bootstrap.foo", "splat")));
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties("spring.cloud.bootstrap.enabled=true").environment(environment)
|
||||
.sources(BareConfiguration.class).run();
|
||||
@@ -415,7 +410,7 @@ public class BootstrapConfigurationTests {
|
||||
// This is added to bootstrap context as a source in bootstrap.properties
|
||||
protected static class PropertySourceConfiguration implements PropertySourceLocator {
|
||||
|
||||
public static Map<String, Object> MAP = new HashMap<String, Object>(
|
||||
public static Map<String, Object> MAP = new HashMap<>(
|
||||
Collections.<String, Object>singletonMap("bootstrap.foo", "bar"));
|
||||
|
||||
private String name;
|
||||
@@ -456,9 +451,9 @@ public class BootstrapConfigurationTests {
|
||||
// This is added to bootstrap context as a source in bootstrap.properties
|
||||
protected static class CompositePropertySourceConfiguration implements PropertySourceLocator {
|
||||
|
||||
public static Map<String, Object> MAP1 = new HashMap<String, Object>();
|
||||
public static Map<String, Object> MAP1 = new HashMap<>();
|
||||
|
||||
public static Map<String, Object> MAP2 = new HashMap<String, Object>();
|
||||
public static Map<String, Object> MAP2 = new HashMap<>();
|
||||
|
||||
public CompositePropertySourceConfiguration() {
|
||||
MAP1.put("list.foo[0]", "hello");
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.bootstrap.encrypt;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -36,7 +36,7 @@ public class EncryptorFactoryTests {
|
||||
@Test
|
||||
public void testWithRsaPrivateKey() throws Exception {
|
||||
String key = StreamUtils.copyToString(new ClassPathResource("/example-test-rsa-private-key").getInputStream(),
|
||||
Charset.forName("ASCII"));
|
||||
StandardCharsets.US_ASCII);
|
||||
|
||||
TextEncryptor encryptor = new EncryptorFactory().create(key);
|
||||
String toEncrypt = "sample text to encrypt";
|
||||
@@ -47,11 +47,11 @@ public class EncryptorFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testWithInvalidRsaPrivateKey() {
|
||||
String key = "-----BEGIN RSA PRIVATE KEY-----\n"
|
||||
+ "MIIEowIBAAKCAQEAwClFgrRa/PUHPIJr9gvIPL6g6Rjp/TVZmVNOf2fL96DYbkj5\n";
|
||||
Assertions.assertThrows(RuntimeException.class, () -> {
|
||||
new EncryptorFactory().create(key);
|
||||
});
|
||||
String key = """
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEAwClFgrRa/PUHPIJr9gvIPL6g6Rjp/TVZmVNOf2fL96DYbkj5
|
||||
""";
|
||||
Assertions.assertThrows(RuntimeException.class, () -> new EncryptorFactory().create(key));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class EnvironmentManagerIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void coreWebExtensionAvailable() throws Exception {
|
||||
this.mvc.perform(get(BASE_PATH + "/env/" + UUID.randomUUID().toString())).andExpect(status().isNotFound());
|
||||
this.mvc.perform(get(BASE_PATH + "/env/" + UUID.randomUUID())).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ConfigurationPropertiesRebinderIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
public void testSimpleProperties() {
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
// Change the dynamic property source...
|
||||
@@ -70,7 +70,7 @@ public class ConfigurationPropertiesRebinderIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshInParent() throws Exception {
|
||||
public void testRefreshInParent() {
|
||||
then(this.config.getName()).isEqualTo("parent");
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("config.name=foo").applyTo(this.environment);
|
||||
@@ -81,7 +81,7 @@ public class ConfigurationPropertiesRebinderIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
public void testRefresh() {
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
@@ -94,7 +94,7 @@ public class ConfigurationPropertiesRebinderIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshByName() throws Exception {
|
||||
public void testRefreshByName() {
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ConfigurationPropertiesRebinderLifecycleIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
public void testRefresh() {
|
||||
then(this.properties.getCount()).isEqualTo(0);
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ConfigurationPropertiesRebinderProxyIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testAppendProperties() throws Exception {
|
||||
public void testAppendProperties() {
|
||||
// This comes out as a String not Integer if the rebinder processes the proxy
|
||||
// instead of the target
|
||||
then(this.properties.getExpiry().get("one")).isEqualTo(new Integer(168));
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ConfigurationPropertiesRebinderRefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
public void testSimpleProperties() {
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo").applyTo(this.environment);
|
||||
@@ -65,7 +65,7 @@ public class ConfigurationPropertiesRebinderRefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
public void testRefresh() {
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ContextRefresherIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
public void testSimpleProperties() {
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
this.properties.setMessage("Foo");
|
||||
@@ -58,7 +58,7 @@ public class ContextRefresherIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshBean() throws Exception {
|
||||
public void testRefreshBean() {
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
this.properties.setMessage("Foo");
|
||||
@@ -69,7 +69,7 @@ public class ContextRefresherIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testUpdateHikari() throws Exception {
|
||||
public void testUpdateHikari() {
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
TestPropertyValues.of("spring.datasource.hikari.read-only=true").applyTo(this.environment);
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
|
||||
@@ -42,7 +42,7 @@ public class RestartIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestartTwice() throws Exception {
|
||||
public void testRestartTwice() {
|
||||
|
||||
this.context = SpringApplication.run(TestConfiguration.class, "--management.endpoint.restart.enabled=true",
|
||||
"--server.port=0", "--spring.cloud.bootstrap.enabled=true",
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ImportRefreshScopeIntegrationTests {
|
||||
private ExampleService service;
|
||||
|
||||
@Test
|
||||
public void testSimpleProperties() throws Exception {
|
||||
public void testSimpleProperties() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.beanFactory.getBeanDefinition(ScopedProxyUtils.getTargetBeanName("service")).getScope())
|
||||
.isEqualTo("refresh");
|
||||
|
||||
@@ -68,7 +68,7 @@ public class MoreRefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
public void testSimpleProperties() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.service instanceof Advised).isTrue();
|
||||
// Change the dynamic property source...
|
||||
@@ -81,7 +81,7 @@ public class MoreRefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
public void testRefresh() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
@@ -98,7 +98,7 @@ public class MoreRefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshFails() throws Exception {
|
||||
public void testRefreshFails() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo", "delay:foo").applyTo(this.environment);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -72,17 +71,14 @@ public class RefreshScopeConcurrencyTests {
|
||||
this.properties.setMessage("Foo");
|
||||
this.properties.setDelay(500);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Future<String> result = this.executor.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
logger.debug("Background started.");
|
||||
try {
|
||||
return RefreshScopeConcurrencyTests.this.service.getMessage();
|
||||
}
|
||||
finally {
|
||||
latch.countDown();
|
||||
logger.debug("Background done.");
|
||||
}
|
||||
Future<String> result = this.executor.submit(() -> {
|
||||
logger.debug("Background started.");
|
||||
try {
|
||||
return RefreshScopeConcurrencyTests.this.service.getMessage();
|
||||
}
|
||||
finally {
|
||||
latch.countDown();
|
||||
logger.debug("Background done.");
|
||||
}
|
||||
});
|
||||
then(latch.await(15000, TimeUnit.MILLISECONDS)).isTrue();
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -81,25 +80,19 @@ public class RefreshScopeConfigurationScaleTests {
|
||||
final CountDownLatch latch = new CountDownLatch(n);
|
||||
List<Future<String>> results = new ArrayList<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
results.add(this.executor.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
logger.debug("Background started.");
|
||||
try {
|
||||
return RefreshScopeConfigurationScaleTests.this.service.getMessage();
|
||||
}
|
||||
finally {
|
||||
latch.countDown();
|
||||
logger.debug("Background done.");
|
||||
}
|
||||
results.add(this.executor.submit(() -> {
|
||||
logger.debug("Background started.");
|
||||
try {
|
||||
return RefreshScopeConfigurationScaleTests.this.service.getMessage();
|
||||
}
|
||||
finally {
|
||||
latch.countDown();
|
||||
logger.debug("Background done.");
|
||||
}
|
||||
}));
|
||||
this.executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logger.debug("Refreshing.");
|
||||
RefreshScopeConfigurationScaleTests.this.scope.refreshAll();
|
||||
}
|
||||
this.executor.submit(() -> {
|
||||
logger.debug("Refreshing.");
|
||||
RefreshScopeConfigurationScaleTests.this.scope.refreshAll();
|
||||
});
|
||||
}
|
||||
then(latch.await(15000, TimeUnit.MILLISECONDS)).isTrue();
|
||||
|
||||
@@ -63,7 +63,7 @@ public class RefreshScopeConfigurationTests {
|
||||
* See gh-43
|
||||
*/
|
||||
@Test
|
||||
public void configurationWithRefreshScope() throws Exception {
|
||||
public void configurationWithRefreshScope() {
|
||||
this.context = new AnnotationConfigApplicationContext(Application.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class,
|
||||
LifecycleMvcEndpointAutoConfiguration.class);
|
||||
@@ -77,7 +77,7 @@ public class RefreshScopeConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshScopeOnBean() throws Exception {
|
||||
public void refreshScopeOnBean() {
|
||||
this.context = new AnnotationConfigApplicationContext(ClientApp.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class,
|
||||
LifecycleMvcEndpointAutoConfiguration.class);
|
||||
@@ -89,7 +89,7 @@ public class RefreshScopeConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshScopeOnNested() throws Exception {
|
||||
public void refreshScopeOnNested() {
|
||||
this.context = new AnnotationConfigApplicationContext(NestedApp.class,
|
||||
PropertyPlaceholderAutoConfiguration.class, RefreshAutoConfiguration.class,
|
||||
LifecycleMvcEndpointAutoConfiguration.class);
|
||||
|
||||
@@ -68,7 +68,7 @@ public class RefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
public void testSimpleProperties() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.service instanceof Advised).isTrue();
|
||||
// Change the dynamic property source...
|
||||
@@ -81,7 +81,7 @@ public class RefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
public void testRefresh() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
@@ -99,7 +99,7 @@ public class RefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshBean() throws Exception {
|
||||
public void testRefreshBean() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
@@ -120,9 +120,7 @@ public class RefreshScopeIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCheckedException() {
|
||||
Assertions.assertThrows(ServiceException.class, () -> {
|
||||
this.service.throwsException();
|
||||
});
|
||||
Assertions.assertThrows(ServiceException.class, () -> this.service.throwsException());
|
||||
}
|
||||
|
||||
public interface Service {
|
||||
|
||||
@@ -70,7 +70,7 @@ public class RefreshScopeLazyIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
public void testSimpleProperties() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.service instanceof Advised).isTrue();
|
||||
// Change the dynamic property source...
|
||||
@@ -83,7 +83,7 @@ public class RefreshScopeLazyIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
public void testRefresh() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
@@ -101,7 +101,7 @@ public class RefreshScopeLazyIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshBean() throws Exception {
|
||||
public void testRefreshBean() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
|
||||
@@ -56,7 +56,7 @@ public class RefreshScopeListBindingIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testAppendProperties() throws Exception {
|
||||
public void testAppendProperties() {
|
||||
then("[one, two]").isEqualTo(this.properties.getMessages().toString());
|
||||
then(this.properties instanceof Advised).isTrue();
|
||||
TestPropertyValues.of("test.messages[0]:foo").applyTo(this.environment);
|
||||
@@ -66,7 +66,7 @@ public class RefreshScopeListBindingIntegrationTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testReplaceProperties() throws Exception {
|
||||
public void testReplaceProperties() {
|
||||
then("[one, two]").isEqualTo(this.properties.getMessages().toString());
|
||||
then(this.properties instanceof Advised).isTrue();
|
||||
Map<String, Object> map = findTestProperties();
|
||||
@@ -104,7 +104,7 @@ public class RefreshScopeListBindingIntegrationTests {
|
||||
@ManagedResource
|
||||
protected static class TestProperties {
|
||||
|
||||
private List<String> messages = new ArrayList<String>();
|
||||
private List<String> messages = new ArrayList<>();
|
||||
|
||||
public List<String> getMessages() {
|
||||
return this.messages;
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -72,25 +71,19 @@ public class RefreshScopePureScaleTests {
|
||||
final CountDownLatch latch = new CountDownLatch(n);
|
||||
List<Future<String>> results = new ArrayList<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
results.add(this.executor.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
logger.debug("Background started.");
|
||||
try {
|
||||
return RefreshScopePureScaleTests.this.service.getMessage();
|
||||
}
|
||||
finally {
|
||||
latch.countDown();
|
||||
logger.debug("Background done.");
|
||||
}
|
||||
results.add(this.executor.submit(() -> {
|
||||
logger.debug("Background started.");
|
||||
try {
|
||||
return RefreshScopePureScaleTests.this.service.getMessage();
|
||||
}
|
||||
finally {
|
||||
latch.countDown();
|
||||
logger.debug("Background done.");
|
||||
}
|
||||
}));
|
||||
this.executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logger.debug("Refreshing.");
|
||||
RefreshScopePureScaleTests.this.scope.refreshAll();
|
||||
}
|
||||
this.executor.submit(() -> {
|
||||
logger.debug("Refreshing.");
|
||||
RefreshScopePureScaleTests.this.scope.refreshAll();
|
||||
});
|
||||
}
|
||||
then(latch.await(15000, TimeUnit.MILLISECONDS)).isTrue();
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -77,17 +76,14 @@ public class RefreshScopeScaleTests {
|
||||
final CountDownLatch latch = new CountDownLatch(n);
|
||||
Future<String> result = null;
|
||||
for (int i = 0; i < n; i++) {
|
||||
result = this.executor.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
logger.debug("Background started.");
|
||||
try {
|
||||
return RefreshScopeScaleTests.this.service.getMessage();
|
||||
}
|
||||
finally {
|
||||
latch.countDown();
|
||||
logger.debug("Background done.");
|
||||
}
|
||||
result = this.executor.submit(() -> {
|
||||
logger.debug("Background started.");
|
||||
try {
|
||||
return RefreshScopeScaleTests.this.service.getMessage();
|
||||
}
|
||||
finally {
|
||||
latch.countDown();
|
||||
logger.debug("Background done.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,14 +33,14 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
public class RefreshScopeSerializationTests {
|
||||
|
||||
@Test
|
||||
public void defaultApplicationContextId() throws Exception {
|
||||
public void defaultApplicationContextId() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfiguration.class)
|
||||
.properties("spring.cloud.bootstrap.enabled=true").web(WebApplicationType.NONE).run();
|
||||
then(context.getId()).isEqualTo("application-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializationIdReproducible() throws Exception {
|
||||
public void serializationIdReproducible() {
|
||||
String first = getBeanFactory().getSerializationId();
|
||||
String second = getBeanFactory().getSerializationId();
|
||||
then(first).isNotNull();
|
||||
|
||||
@@ -55,13 +55,13 @@ public class RefreshScopeWebIntegrationTests {
|
||||
private ConfigurableListableBeanFactory beanFactory;
|
||||
|
||||
@Test
|
||||
public void scopeOnBeanDefinition() throws Exception {
|
||||
public void scopeOnBeanDefinition() {
|
||||
then(this.beanFactory.getBeanDefinition(ScopedProxyUtils.getTargetBeanName("application")).getScope())
|
||||
.isEqualTo("refresh");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanAccess() throws Exception {
|
||||
public void beanAccess() {
|
||||
this.application.hello();
|
||||
this.environmentManager.setProperty("message", "Hello Dave!");
|
||||
this.scope.refreshAll();
|
||||
|
||||
@@ -70,7 +70,7 @@ public class RefreshEndpointTests {
|
||||
|
||||
@Test
|
||||
@Disabled // FIXME: legacy
|
||||
public void keysComputedWhenAdded() throws Exception {
|
||||
public void keysComputedWhenAdded() {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.enabled=true", "spring.cloud.bootstrap.name:none").run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
@@ -84,7 +84,7 @@ public class RefreshEndpointTests {
|
||||
|
||||
@Test
|
||||
@Disabled // FIXME: legacy
|
||||
public void keysComputedWhenOveridden() throws Exception {
|
||||
public void keysComputedWhenOveridden() {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.enabled=true", "spring.cloud.bootstrap.name:none").run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
@@ -97,7 +97,7 @@ public class RefreshEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keysComputedWhenChangesInExternalProperties() throws Exception {
|
||||
public void keysComputedWhenChangesInExternalProperties() {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.name:none", "spring.cloud.bootstrap.enabled=true").run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
@@ -111,7 +111,7 @@ public class RefreshEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void springMainSourcesEmptyInRefreshCycle() throws Exception {
|
||||
public void springMainSourcesEmptyInRefreshCycle() {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.name:none").run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
@@ -128,7 +128,7 @@ public class RefreshEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventsPublishedInOrder() throws Exception {
|
||||
public void eventsPublishedInOrder() {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF)
|
||||
.run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
@@ -170,7 +170,7 @@ public class RefreshEndpointTests {
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
protected static class Empty implements SmartApplicationListener {
|
||||
|
||||
private List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
|
||||
private List<ApplicationEvent> events = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
|
||||
@@ -192,8 +192,7 @@ public class RefreshEndpointTests {
|
||||
|
||||
@Override
|
||||
public PropertySource<?> locate(Environment environment) {
|
||||
return new MapPropertySource("external",
|
||||
Collections.<String, Object>singletonMap("external.message", "I'm External"));
|
||||
return new MapPropertySource("external", Collections.singletonMap("external.message", "I'm External"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class CachedRandomPropertySourceTests {
|
||||
|
||||
private HashMap<String, Map<String, Object>> createCache(HashMap<String, AtomicInteger> keyCount,
|
||||
HashMap<Map<String, Object>, String> typeToKeyLookup, HashMap<String, AtomicInteger> typeCount) {
|
||||
return new HashMap<String, Map<String, Object>>() {
|
||||
return new HashMap<>() {
|
||||
@Override
|
||||
public Map<String, Object> computeIfAbsent(String key,
|
||||
Function<? super String, ? extends Map<String, Object>> mappingFunction) {
|
||||
@@ -96,7 +96,7 @@ public class CachedRandomPropertySourceTests {
|
||||
|
||||
private HashMap<String, Object> createTypeCache(HashMap<Map<String, Object>, String> typeToKeyLookup,
|
||||
HashMap<String, AtomicInteger> typeCount) {
|
||||
return new HashMap<String, Object>() {
|
||||
return new HashMap<>() {
|
||||
@Override
|
||||
public Object computeIfAbsent(String key, Function<? super String, ?> mappingFunction) {
|
||||
if (!containsKey(key)) {
|
||||
|
||||
@@ -82,7 +82,7 @@ public class LoadBalancerClientSpecification implements NamedContextFactory.Spec
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.name, this.configuration);
|
||||
return Objects.hash(this.name, Arrays.hashCode(this.configuration));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class CaffeineBasedLoadBalancerCacheManager extends CaffeineCacheManager
|
||||
|
||||
public CaffeineBasedLoadBalancerCacheManager(String cacheName, LoadBalancerCacheProperties properties) {
|
||||
super(cacheName);
|
||||
if (!StringUtils.isEmpty(properties.getCaffeine().getSpec())) {
|
||||
if (StringUtils.hasText(properties.getCaffeine().getSpec())) {
|
||||
setCacheSpecification(properties.getCaffeine().getSpec());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.loadbalancer.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@@ -77,8 +76,7 @@ public class HealthCheckServiceInstanceListSupplier extends DelegatingServiceIns
|
||||
.onlyIf(repeatContext -> this.healthCheck.getRefetchInstances())
|
||||
.fixedBackoff(healthCheck.getRefetchInstancesInterval());
|
||||
Flux<List<ServiceInstance>> aliveInstancesFlux = Flux.defer(delegate).repeatWhen(aliveInstancesReplayRepeat)
|
||||
.switchMap(serviceInstances -> healthCheckFlux(serviceInstances)
|
||||
.map(alive -> Collections.unmodifiableList(new ArrayList<>(alive))));
|
||||
.switchMap(serviceInstances -> healthCheckFlux(serviceInstances).map(alive -> List.copyOf(alive)));
|
||||
aliveInstancesReplay = aliveInstancesFlux.delaySubscription(healthCheck.getInitialDelay()).replay(1)
|
||||
.refCount(1);
|
||||
}
|
||||
@@ -94,8 +92,7 @@ public class HealthCheckServiceInstanceListSupplier extends DelegatingServiceIns
|
||||
.onlyIf(repeatContext -> this.healthCheck.getRefetchInstances())
|
||||
.fixedBackoff(healthCheck.getRefetchInstancesInterval());
|
||||
Flux<List<ServiceInstance>> aliveInstancesFlux = Flux.defer(delegate).repeatWhen(aliveInstancesReplayRepeat)
|
||||
.switchMap(serviceInstances -> healthCheckFlux(serviceInstances)
|
||||
.map(alive -> Collections.unmodifiableList(new ArrayList<>(alive))));
|
||||
.switchMap(serviceInstances -> healthCheckFlux(serviceInstances).map(alive -> List.copyOf(alive)));
|
||||
aliveInstancesReplay = aliveInstancesFlux.delaySubscription(healthCheck.getInitialDelay()).replay(1)
|
||||
.refCount(1);
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ public class RequestBasedStickySessionServiceInstanceListSupplier extends Delega
|
||||
for (ServiceInstance serviceInstance : serviceInstances) {
|
||||
if (cookie.equals(serviceInstance.getInstanceId())) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Returning the service instance: %s. Found for cookie: %s",
|
||||
serviceInstance.toString(), cookie));
|
||||
LOG.debug(String.format("Returning the service instance: %s. Found for cookie: %s", serviceInstance,
|
||||
cookie));
|
||||
}
|
||||
return Collections.singletonList(serviceInstance);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user