Remove deprecations and unused code. Refactor (#4134)

This commit is contained in:
Olga Maciaszek-Sharma
2022-11-07 16:44:21 +01:00
committed by GitHub
parent a03a87636a
commit 48b08d6fc9
50 changed files with 155 additions and 252 deletions
@@ -28,9 +28,9 @@ import org.springframework.context.ConfigurableApplicationContext;
public class AppRunner implements AutoCloseable {
private Class<?> appClass;
private final Class<?> appClass;
private Map<String, String> props;
private final Map<String, String> props;
private ConfigurableApplicationContext app;
@@ -56,6 +56,7 @@ abstract class BaseCertTest {
protected BaseCertTest() {
}
@SuppressWarnings("rawtypes")
static EurekaServerRunner startEurekaServer(Class config) {
EurekaServerRunner server = new EurekaServerRunner(config);
server.enableTls();
@@ -70,6 +71,7 @@ abstract class BaseCertTest {
server.stop();
}
@SuppressWarnings("rawtypes")
static EurekaClientRunner startService(EurekaServerRunner server, Class config) {
EurekaClientRunner service = new EurekaClientRunner(config, server, "testservice");
enableTlsClient(service);
@@ -153,9 +155,7 @@ abstract class BaseCertTest {
EurekaClientRunner client = createEurekaClient();
enableTlsClient(client);
client.setKeyStore(clientCert, WRONG_PASSWORD, WRONG_PASSWORD);
Assertions.assertThrows(BeanCreationException.class, () -> {
client.start();
});
Assertions.assertThrows(BeanCreationException.class, client::start);
}
@Test
@@ -163,9 +163,7 @@ abstract class BaseCertTest {
EurekaClientRunner client = createEurekaClient();
enableTlsClient(client);
client.setKeyStore(new File("nonExistFile"));
Assertions.assertThrows(BeanCreationException.class, () -> {
client.start();
});
Assertions.assertThrows(BeanCreationException.class, client::start);
}
@Test
@@ -183,7 +181,7 @@ abstract class BaseCertTest {
}
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 {
@@ -72,13 +72,13 @@ public class EurekaClientRunner extends AppRunner {
}
public void waitServiceViaEureka(int seconds) {
assertInSeconds(() -> foundServiceViaEureka(), seconds);
assertInSeconds(this::foundServiceViaEureka, seconds);
}
private void assertInSeconds(BooleanSupplier assertion, int seconds) {
long start = System.currentTimeMillis();
long limit = 1000L * seconds;
long duration = 0;
long duration;
do {
if (assertion.getAsBoolean()) {
@@ -98,8 +98,9 @@ public class EurekaClientRunner extends AppRunner {
return !discovery.getServices().isEmpty();
}
@SuppressWarnings("unchecked")
public AbstractDiscoveryClientOptionalArgs<Void> discoveryClientOptionalArgs() {
return this.getBean(AbstractDiscoveryClientOptionalArgs.class);
return getBean(AbstractDiscoveryClientOptionalArgs.class);
}
}
@@ -25,9 +25,9 @@ import java.security.cert.X509Certificate;
public class KeyAndCert {
private KeyPair keyPair;
private final KeyPair keyPair;
private X509Certificate certificate;
private final X509Certificate certificate;
public KeyAndCert(KeyPair keyPair, X509Certificate certificate) {
this.keyPair = keyPair;
@@ -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);
}
@@ -56,9 +56,7 @@ public class KeyTool {
public KeyAndCert signCertificate(KeyPair keyPair, String subject, KeyAndCert signer) throws Exception {
X509Certificate certificate = createCert(keyPair.getPublic(), signer.privateKey(), signer.subject(), subject);
KeyAndCert result = new KeyAndCert(keyPair, certificate);
return result;
return new KeyAndCert(keyPair, certificate);
}
public KeyPair createKeyPair() throws Exception {
@@ -48,13 +48,13 @@ public class CloudEurekaClient extends DiscoveryClient {
private final AtomicLong cacheRefreshedCount = new AtomicLong(0);
private ApplicationEventPublisher publisher;
private final ApplicationEventPublisher publisher;
private Field eurekaTransportField;
private final Field eurekaTransportField;
private ApplicationInfoManager applicationInfoManager;
private final ApplicationInfoManager applicationInfoManager;
private AtomicReference<EurekaHttpClient> eurekaHttpClient = new AtomicReference<>();
private final AtomicReference<EurekaHttpClient> eurekaHttpClient = new AtomicReference<>();
public CloudEurekaClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config,
ApplicationEventPublisher publisher) {
@@ -1,42 +0,0 @@
/*
* Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.netflix.eureka;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Convenience annotation for clients to enable Eureka discovery configuration
* (specifically). Use this (optionally) in case you want discovery and know for sure that
* it is Eureka you want. All it does is turn on discovery and let the autoconfiguration
* find the eureka classes if they are available (i.e. you need Eureka on the classpath as
* well).
*
* @author Dave Syer
* @author Spencer Gibb
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface EnableEurekaClient {
}
@@ -115,7 +115,7 @@ import static org.springframework.cloud.commons.util.IdUtils.getDefaultInstanceI
"org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration" })
public class EurekaClientAutoConfiguration {
private ConfigurableEnvironment env;
private final ConfigurableEnvironment env;
public EurekaClientAutoConfiguration(ConfigurableEnvironment env) {
this.env = env;
@@ -473,7 +473,7 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
if (serviceUrls == null || serviceUrls.isEmpty()) {
serviceUrls = this.serviceUrl.get(DEFAULT_ZONE);
}
if (!StringUtils.isEmpty(serviceUrls)) {
if (StringUtils.hasText(serviceUrls)) {
final String[] serviceUrlsSplit = StringUtils.commaDelimitedListToStringArray(serviceUrls);
List<String> eurekaServiceUrls = new ArrayList<>(serviceUrlsSplit.length);
for (String eurekaServiceUrl : serviceUrlsSplit) {
@@ -67,7 +67,7 @@ import org.springframework.util.Assert;
public class EurekaHealthCheckHandler
implements HealthCheckHandler, ApplicationContextAware, InitializingBean, Ordered, Lifecycle {
private static final Map<Status, InstanceInfo.InstanceStatus> STATUS_MAPPING = new HashMap<Status, InstanceInfo.InstanceStatus>() {
private static final Map<Status, InstanceInfo.InstanceStatus> STATUS_MAPPING = new HashMap<>() {
{
put(Status.UNKNOWN, InstanceStatus.UNKNOWN);
put(Status.OUT_OF_SERVICE, InstanceStatus.DOWN);
@@ -76,18 +76,18 @@ public class EurekaHealthCheckHandler
}
};
private StatusAggregator statusAggregator;
private final StatusAggregator statusAggregator;
private ApplicationContext applicationContext;
private Map<String, HealthContributor> healthContributors = new HashMap<>();
private final Map<String, HealthContributor> healthContributors = new HashMap<>();
/**
* {@code true} until the context is stopped.
*/
private boolean running = true;
private Map<String, ReactiveHealthContributor> reactiveHealthContributors = new HashMap<>();
private final Map<String, ReactiveHealthContributor> reactiveHealthContributors = new HashMap<>();
public EurekaHealthCheckHandler(StatusAggregator statusAggregator) {
this.statusAggregator = statusAggregator;
@@ -110,8 +110,7 @@ public class EurekaHealthCheckHandler
for (Map.Entry<String, HealthContributor> entry : healthContributors.entrySet()) {
// ignore EurekaHealthIndicator and flatten the rest of the composite
// otherwise there is a never ending cycle of down. See gh-643
if (entry.getValue() instanceof DiscoveryCompositeHealthContributor) {
DiscoveryCompositeHealthContributor indicator = (DiscoveryCompositeHealthContributor) entry.getValue();
if (entry.getValue() instanceof DiscoveryCompositeHealthContributor indicator) {
indicator.getIndicators().forEach((name, discoveryHealthIndicator) -> {
if (!(discoveryHealthIndicator instanceof EurekaHealthIndicator)) {
this.healthContributors.put(name, (HealthIndicator) discoveryHealthIndicator::health);
@@ -92,7 +92,7 @@ public class EurekaHealthIndicator implements DiscoveryHealthIndicator {
if (AopUtils.isAopProxy(eurekaClient)) {
discoveryClient = ProxyUtils.getTargetObject(eurekaClient);
}
else if (DiscoveryClient.class.isInstance(eurekaClient)) {
else if (eurekaClient instanceof DiscoveryClient) {
discoveryClient = (DiscoveryClient) eurekaClient;
}
return discoveryClient;
@@ -607,7 +607,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, Envi
leaseExpirationDurationInSeconds, virtualHostName, instanceId, secureVirtualHostName, aSGName,
metadataMap, dataCenterInfo, ipAddress, statusPageUrlPath, statusPageUrl, homePageUrlPath, homePageUrl,
healthCheckUrlPath, healthCheckUrl, secureHealthCheckUrl, namespace, hostname, preferIpAddress,
initialStatus, defaultAddressResolutionOrder, environment);
initialStatus, Arrays.hashCode(defaultAddressResolutionOrder), environment);
}
@Override
@@ -39,7 +39,7 @@ import static com.netflix.appinfo.InstanceInfo.PortType.SECURE;
*/
public class EurekaServiceInstance implements ServiceInstance {
private InstanceInfo instance;
private final InstanceInfo instance;
public EurekaServiceInstance(InstanceInfo instance) {
Assert.notNull(instance, "Service instance required");
@@ -31,13 +31,4 @@ public class RestTemplateDiscoveryClientOptionalArgs extends AbstractDiscoveryCl
setTransportClientFactories(new RestTemplateTransportClientFactories(this));
}
/**
* @deprecated - use
* {@link RestTemplateDiscoveryClientOptionalArgs#RestTemplateDiscoveryClientOptionalArgs(EurekaClientHttpRequestFactorySupplier)}
*/
@Deprecated
public RestTemplateDiscoveryClientOptionalArgs() {
this(new DefaultEurekaClientHttpRequestFactorySupplier());
}
}
@@ -50,7 +50,7 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
protected final Log logger = LogFactory.getLog(getClass());
private RestTemplate restTemplate;
private final RestTemplate restTemplate;
private String serviceUrl;
@@ -77,7 +77,7 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.POST, new HttpEntity<>(info, headers),
Void.class);
return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
return anEurekaHttpResponse(response.getStatusCode().value()).headers(headersOf(response)).build();
}
@Override
@@ -86,7 +86,7 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.DELETE, null, Void.class);
return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
return anEurekaHttpResponse(response.getStatusCode().value()).headers(headersOf(response)).build();
}
@Override
@@ -100,7 +100,7 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
InstanceInfo.class);
EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse(
response.getStatusCodeValue(), InstanceInfo.class).headers(headersOf(response));
response.getStatusCode().value(), InstanceInfo.class).headers(headersOf(response));
if (response.hasBody()) {
eurekaResponseBuilder.entity(response.getBody());
@@ -117,7 +117,7 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.PUT, null, Void.class);
return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
return anEurekaHttpResponse(response.getStatusCode().value()).headers(headersOf(response)).build();
}
@Override
@@ -127,7 +127,7 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.DELETE, null, Void.class);
return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
return anEurekaHttpResponse(response.getStatusCode().value()).headers(headersOf(response)).build();
}
@Override
@@ -171,10 +171,10 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
ResponseEntity<Application> response = restTemplate.exchange(urlPath, HttpMethod.GET, null, Application.class);
Application application = response.getStatusCodeValue() == HttpStatus.OK.value() && response.hasBody()
Application application = response.getStatusCode().value() == HttpStatus.OK.value() && response.hasBody()
? response.getBody() : null;
return anEurekaHttpResponse(response.getStatusCodeValue(), application).headers(headersOf(response)).build();
return anEurekaHttpResponse(response.getStatusCode().value(), application).headers(headersOf(response)).build();
}
@Override
@@ -193,8 +193,8 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath, HttpMethod.GET, null,
InstanceInfo.class);
return anEurekaHttpResponse(response.getStatusCodeValue(),
response.getStatusCodeValue() == HttpStatus.OK.value() && response.hasBody() ? response.getBody()
return anEurekaHttpResponse(response.getStatusCode().value(),
response.getStatusCode().value() == HttpStatus.OK.value() && response.hasBody() ? response.getBody()
: null).headers(headersOf(response)).build();
}
@@ -27,7 +27,7 @@ import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
@@ -139,13 +139,13 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
* serialized or deserialized. Achived with
* {@link SerializationFeature#WRAP_ROOT_VALUE} and
* {@link DeserializationFeature#UNWRAP_ROOT_VALUE}.
* {@link PropertyNamingStrategy.SnakeCaseStrategy} is applied to the underlying
* {@link PropertyNamingStrategies.SnakeCaseStrategy} is applied to the underlying
* {@link ObjectMapper}.
* @return a {@link MappingJackson2HttpMessageConverter} object
*/
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE));
converter.setObjectMapper(new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE));
SimpleModule jsonModule = new SimpleModule();
jsonModule.setSerializerModifier(createJsonSerializerModifier()); // keyFormatter,
@@ -28,8 +28,6 @@ import com.netflix.discovery.shared.transport.EurekaHttpClient;
import com.netflix.discovery.shared.transport.EurekaHttpResponse;
import com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder;
import com.netflix.discovery.util.StringUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -46,9 +44,7 @@ import static com.netflix.discovery.shared.transport.EurekaHttpResponse.anEureka
*/
public class WebClientEurekaHttpClient implements EurekaHttpClient {
protected final Log logger = LogFactory.getLog(getClass());
private WebClient webClient;
private final WebClient webClient;
public WebClientEurekaHttpClient(WebClient webClient) {
this.webClient = webClient;
@@ -206,8 +202,7 @@ public class WebClientEurekaHttpClient implements EurekaHttpClient {
return Collections.emptyMap();
}
Map<String, String> headers = new HashMap<>();
asHeaders.entrySet().stream()
.forEach(entry -> entry.getValue().stream().forEach(v -> headers.put(entry.getKey(), v)));
asHeaders.entrySet().forEach(entry -> entry.getValue().forEach(v -> headers.put(entry.getKey(), v)));
return headers;
}
@@ -24,7 +24,7 @@ import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
@@ -122,13 +122,13 @@ public class WebClientTransportClientFactory implements TransportClientFactory {
* serialized or deserialized. Achieved with
* {@link SerializationFeature#WRAP_ROOT_VALUE} and
* {@link DeserializationFeature#UNWRAP_ROOT_VALUE}.
* {@link PropertyNamingStrategy.SnakeCaseStrategy} is applied to the underlying
* {@link PropertyNamingStrategies.SnakeCaseStrategy} is applied to the underlying
* {@link ObjectMapper}.
* @return a {@link ObjectMapper} object
*/
private ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
SimpleModule jsonModule = new SimpleModule();
jsonModule.setSerializerModifier(createJsonSerializerModifier());
@@ -147,7 +147,7 @@ public class WebClientTransportClientFactory implements TransportClientFactory {
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
// literally 400 pass the tests, not 4xxClientError
if (clientResponse.statusCode().value() == 400) {
ClientResponse newResponse = ClientResponse.from(clientResponse).statusCode(HttpStatus.OK).build();
ClientResponse newResponse = clientResponse.mutate().statusCode(HttpStatus.OK).build();
newResponse.body((clientHttpResponse, context) -> clientHttpResponse.getBody());
return Mono.just(newResponse);
}
@@ -65,11 +65,11 @@ public class EurekaLoadBalancerClientConfiguration {
@PostConstruct
public void postprocess() {
if (!StringUtils.isEmpty(zoneConfig.getZone())) {
if (StringUtils.hasText(zoneConfig.getZone())) {
return;
}
String zone = getZoneFromEureka();
if (!StringUtils.isEmpty(zone)) {
if (StringUtils.hasText(zone)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Setting the value of '" + LOADBALANCER_ZONE + "' to " + zone);
}
@@ -85,7 +85,7 @@ public class EurekaLoadBalancerClientConfiguration {
}
else {
zone = eurekaConfig == null ? null : eurekaConfig.getMetadataMap().get("zone");
if (StringUtils.isEmpty(zone) && clientConfig != null) {
if (!StringUtils.hasText(zone) && clientConfig != null) {
String[] zones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
// Pick the first one from the regions we want to connect to
zone = zones != null && zones.length > 0 ? zones[0] : null;
@@ -44,17 +44,17 @@ public class EurekaAutoServiceRegistration
private static final Log log = LogFactory.getLog(EurekaAutoServiceRegistration.class);
private AtomicBoolean running = new AtomicBoolean(false);
private final AtomicBoolean running = new AtomicBoolean(false);
private int order = 0;
private final int order = 0;
private AtomicInteger port = new AtomicInteger(0);
private final AtomicInteger port = new AtomicInteger(0);
private ApplicationContext context;
private final ApplicationContext context;
private EurekaServiceRegistry serviceRegistry;
private final EurekaServiceRegistry serviceRegistry;
private EurekaRegistration registration;
private final EurekaRegistration registration;
public EurekaAutoServiceRegistration(ApplicationContext context, EurekaServiceRegistry serviceRegistry,
EurekaRegistration registration) {
@@ -86,6 +86,7 @@ public class EurekaServiceRegistry implements ServiceRegistry<EurekaRegistration
registration.getEurekaClient().setStatus(newStatus, info);
}
@SuppressWarnings("unchecked")
@Override
public Object getStatus(EurekaRegistration registration) {
String appname = registration.getApplicationInfoManager().getInfo().getAppName();
@@ -73,7 +73,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.fail;
*/
class EurekaClientAutoConfigurationTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@AfterEach
void after() {
@@ -94,7 +94,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void shouldSetManagementPortInMetadataMapIfEqualToServerPort() throws Exception {
void shouldSetManagementPortInMetadataMapIfEqualToServerPort() {
TestPropertyValues.of("server.port=8989").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -104,7 +104,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void shouldNotSetManagementAndJmxPortsInMetadataMap() throws Exception {
void shouldNotSetManagementAndJmxPortsInMetadataMap() {
TestPropertyValues.of("server.port=8989", "management.server.port=0").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -115,7 +115,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void shouldSetManagementAndJmxPortsInMetadataMap() throws Exception {
void shouldSetManagementAndJmxPortsInMetadataMap() {
TestPropertyValues.of("management.server.port=9999", "com.sun.management.jmxremote.port=6789")
.applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -126,7 +126,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void shouldNotResetManagementAndJmxPortsInMetadataMap() throws Exception {
void shouldNotResetManagementAndJmxPortsInMetadataMap() {
TestPropertyValues.of("management.server.port=9999", "eureka.instance.metadata-map.jmx.port=9898",
"eureka.instance.metadata-map.management.port=7878").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -201,7 +201,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void statusPageUrl_and_healthCheckUrl_do_not_contain_server_context_path() throws Exception {
void statusPageUrl_and_healthCheckUrl_do_not_contain_server_context_path() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "server.contextPath=/service")
.applyTo(this.context);
@@ -214,7 +214,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void statusPageUrl_and_healthCheckUrl_contain_management_context_path() throws Exception {
void statusPageUrl_and_healthCheckUrl_contain_management_context_path() {
TestPropertyValues.of("server.port=8989", "management.server.servlet.context-path=/management")
.applyTo(this.context);
@@ -227,7 +227,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void statusPageUrl_and_healthCheckUrl_contain_management_context_path_random_port() throws Exception {
void statusPageUrl_and_healthCheckUrl_contain_management_context_path_random_port() {
TestPropertyValues.of("server.port=0", "management.server.servlet.context-path=/management")
.applyTo(this.context);
@@ -286,7 +286,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void statusPageUrl_and_healthCheckUrl_contain_management_base_path() throws Exception {
void statusPageUrl_and_healthCheckUrl_contain_management_base_path() {
TestPropertyValues.of("server.port=8989", "management.server.base-path=/management").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -298,7 +298,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void statusPageUrl_and_healthCheckUrl_contain_management_base_path_random_port() throws Exception {
void statusPageUrl_and_healthCheckUrl_contain_management_base_path_random_port() {
TestPropertyValues.of("server.port=0", "management.server.base-path=/management").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -510,7 +510,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void testDefaultAppName() throws Exception {
void testDefaultAppName() {
setupContext();
assertThat(getInstanceConfig().getAppname()).isEqualTo("unknown");
assertThat(getInstanceConfig().getVirtualHostName()).isEqualTo("unknown");
@@ -518,7 +518,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void testAppName() throws Exception {
void testAppName() {
TestPropertyValues.of("spring.application.name=mytest").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getAppname()).isEqualTo("mytest");
@@ -527,7 +527,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void testAppNameUpper() throws Exception {
void testAppNameUpper() {
addSystemEnvironment(this.context.getEnvironment(), "SPRING_APPLICATION_NAME=mytestupper");
setupContext();
assertThat(getInstanceConfig().getAppname()).isEqualTo("mytestupper");
@@ -569,7 +569,7 @@ class EurekaClientAutoConfigurationTests {
}
@Test
void testInstanceNamePreferred() throws Exception {
void testInstanceNamePreferred() {
addSystemEnvironment(this.context.getEnvironment(), "SPRING_APPLICATION_NAME=mytestspringappname");
TestPropertyValues.of("eureka.instance.appname=mytesteurekaappname").applyTo(this.context);
setupContext();
@@ -615,6 +615,7 @@ class EurekaClientAutoConfigurationTests {
});
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void assertBeanNotPresent(Class beanClass) {
try {
context.getBean(beanClass);
@@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class EurekaClientConfigBeanTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@AfterEach
void init() {
@@ -67,7 +67,7 @@ class EurekaClientConfigBeanTests {
void serviceUrlWithCompositePropertySource() {
CompositePropertySource source = new CompositePropertySource("composite");
this.context.getEnvironment().getPropertySources().addFirst(source);
source.addPropertySource(new MapPropertySource("config", Collections.<String, Object>singletonMap(
source.addPropertySource(new MapPropertySource("config", Collections.singletonMap(
"eureka.client.serviceUrl.defaultZone",
"https://example.com,https://example2.com, https://www.hugedomains.com/domain_profile.cfm?d=example3&e=com")));
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
@@ -321,7 +321,7 @@ class EurekaHealthCheckHandlerTests {
@Override
public Iterator<NamedContributor<HealthContributor>> iterator() {
Iterator<Map.Entry<String, HealthContributor>> iterator = contributorMap.entrySet().iterator();
return new Iterator<NamedContributor<HealthContributor>>() {
return new Iterator<>() {
@Override
public boolean hasNext() {
@@ -18,11 +18,9 @@ package org.springframework.cloud.netflix.eureka;
import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -46,14 +44,14 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class EurekaInstanceConfigBeanTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
private String hostName;
private String ipAddress;
@BeforeEach
void init() throws Exception {
void init() {
try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
InetUtils.HostInfo hostInfo = utils.findFirstNonLoopbackHostInfo();
this.hostName = hostInfo.getHostname();
@@ -158,13 +156,6 @@ class EurekaInstanceConfigBeanTests {
assertThat(getInstanceConfig().getInitialStatus()).as("initialStatus wrong").isEqualTo(InstanceStatus.UP);
}
void testBadInitialStatus() {
TestPropertyValues.of("eureka.instance.initial-status:FOO").applyTo(this.context);
Assertions.assertThrows(BeanCreationException.class, () -> {
setupContext();
});
}
@Test
void testCustomInitialStatus() {
TestPropertyValues.of("eureka.instance.initial-status:STARTING").applyTo(this.context);
@@ -173,7 +164,7 @@ class EurekaInstanceConfigBeanTests {
}
@Test
void testPreferIpAddress() throws Exception {
void testPreferIpAddress() {
TestPropertyValues.of("eureka.instance.preferIpAddress:true").applyTo(this.context);
setupContext();
EurekaInstanceConfigBean instance = getInstanceConfig();
@@ -183,7 +174,7 @@ class EurekaInstanceConfigBeanTests {
}
@Test
void testDefaultVirtualHostName() throws Exception {
void testDefaultVirtualHostName() {
TestPropertyValues.of("spring.application.name:myapp").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getVirtualHostName()).as("virtualHostName wrong").isEqualTo("myapp");
@@ -192,7 +183,7 @@ class EurekaInstanceConfigBeanTests {
}
@Test
void testCustomVirtualHostName() throws Exception {
void testCustomVirtualHostName() {
TestPropertyValues.of("spring.application.name:myapp", "eureka.instance.virtualHostName=myvirthost",
"eureka.instance.secureVirtualHostName=mysecurevirthost").applyTo(this.context);
setupContext();
@@ -203,7 +194,7 @@ class EurekaInstanceConfigBeanTests {
}
@Test
void testDefaultAppName() throws Exception {
void testDefaultAppName() {
setupContext();
assertThat(getInstanceConfig().getAppname()).as("default app name is wrong").isEqualTo("unknown");
assertThat(getInstanceConfig().getVirtualHostName()).as("default virtual hostname is wrong")
@@ -213,21 +204,21 @@ class EurekaInstanceConfigBeanTests {
}
@Test
void testCustomInstanceId() throws Exception {
void testCustomInstanceId() {
TestPropertyValues.of("eureka.instance.instanceId=myinstance").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getInstanceId()).as("instance id is wrong").isEqualTo("myinstance");
}
@Test
void testCustomInstanceIdWithMetadata() throws Exception {
void testCustomInstanceIdWithMetadata() {
TestPropertyValues.of("eureka.instance.metadataMap.instanceId=myinstance").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getInstanceId()).as("instance id is wrong").isEqualTo("myinstance");
}
@Test
void testDefaultInstanceId() throws Exception {
void testDefaultInstanceId() {
setupContext();
assertThat(getInstanceConfig().getInstanceId()).as("default instance id is wrong").isEqualTo(null);
}
@@ -16,8 +16,6 @@
package org.springframework.cloud.netflix.eureka;
import java.io.IOException;
import com.netflix.appinfo.InstanceInfo;
import org.junit.jupiter.api.Test;
@@ -34,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
class InstanceInfoFactoryTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@Test
void instanceIdIsHostNameByDefault() throws IOException {
void instanceIdIsHostNameByDefault() {
InstanceInfo instanceInfo = setupInstance();
try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
assertThat(instanceInfo.getId()).isEqualTo(utils.findFirstNonLoopbackHostInfo().getHostname());
@@ -45,7 +43,7 @@ class InstanceInfoFactoryTests {
}
@Test
void instanceIdIsIpWhenIpPreferred() throws Exception {
void instanceIdIsIpWhenIpPreferred() {
InstanceInfo instanceInfo = setupInstance("eureka.instance.preferIpAddress:true");
assertThat(instanceInfo.getId().matches("(\\d+\\.){3}\\d+")).isTrue();
}
@@ -36,9 +36,8 @@ class EurekaClientConfigServerAutoConfigurationTests {
@Test
void offByDefault() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class)).run(c -> {
assertThat(c.getBeanNamesForType(EurekaInstanceConfigBean.class).length).isEqualTo(0);
});
.withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class))
.run(c -> assertThat(c.getBeanNamesForType(EurekaInstanceConfigBean.class).length).isEqualTo(0));
}
@Test
@@ -63,63 +63,50 @@ public class EurekaConfigServerBootstrapConfigurationTests {
public void offByDefault() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.run(context -> {
assertEurekaBeansNotPresent(context);
});
.run(this::assertEurekaBeansNotPresent);
}
@Test
public void properBeansCreatedWhenDiscoveryEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true").run(context -> {
assertEurekaBeansPresent(context);
});
.withPropertyValues("spring.cloud.config.discovery.enabled=true").run(this::assertEurekaBeansPresent);
}
@Test
public void beansNotCreatedWhenDiscoveryNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=false").run(context -> {
assertEurekaBeansNotPresent(context);
});
.withPropertyValues("spring.cloud.config.discovery.enabled=false")
.run(this::assertEurekaBeansNotPresent);
}
@Test
public void beansNotCreatedWhenDiscoveryDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.disabled").run(context -> {
assertEurekaBeansNotPresent(context);
});
.withPropertyValues("spring.cloud.config.discovery.disabled").run(this::assertEurekaBeansNotPresent);
}
@Test
public void beansNotCreatedWhenEurekaClientEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("eureka.client.enabled=true").run(context -> {
assertEurekaBeansNotPresent(context);
});
.withPropertyValues("eureka.client.enabled=true").run(this::assertEurekaBeansNotPresent);
}
@Test
public void beansNotCreatedWhenEurekaClientNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("eureka.client.enabled=false").run(context -> {
assertEurekaBeansNotPresent(context);
});
.withPropertyValues("eureka.client.enabled=false").run(this::assertEurekaBeansNotPresent);
}
@Test
public void beansNotCreatedWhenEurekaClientDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("eureka.client.disabled").run(context -> {
assertEurekaBeansNotPresent(context);
});
.withPropertyValues("eureka.client.disabled").run(this::assertEurekaBeansNotPresent);
}
@Test
@@ -127,9 +114,7 @@ public class EurekaConfigServerBootstrapConfigurationTests {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true")
.run(context -> {
assertEurekaBeansPresent(context);
});
.run(this::assertEurekaBeansPresent);
}
@Test
@@ -137,9 +122,7 @@ public class EurekaConfigServerBootstrapConfigurationTests {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=false")
.run(context -> {
assertEurekaBeansNotPresent(context);
});
.run(this::assertEurekaBeansNotPresent);
}
@Test
@@ -147,9 +130,7 @@ public class EurekaConfigServerBootstrapConfigurationTests {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=false", "eureka.client.enabled=true")
.run(context -> {
assertEurekaBeansNotPresent(context);
});
.run(this::assertEurekaBeansNotPresent);
}
@Test
@@ -157,9 +138,7 @@ public class EurekaConfigServerBootstrapConfigurationTests {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=false", "eureka.client.enabled=false")
.run(context -> {
assertEurekaBeansNotPresent(context);
});
.run(this::assertEurekaBeansNotPresent);
}
@Test
@@ -171,9 +150,8 @@ public class EurekaConfigServerBootstrapConfigurationTests {
"eureka.client.use-dns-for-fetching-service-urls=true",
"eureka.client.eureka-server-d-n-s-name=myeurekahost",
"eureka.client.eureka-server-u-r-l-context=eureka", "eureka.client.eureka-server-port=30000")
.run(context -> {
assertThat(output).contains("Cannot get cnames bound to the region:txt.us-east-1.myeurekahost");
});
.run(context -> assertThat(output)
.contains("Cannot get cnames bound to the region:txt.us-east-1.myeurekahost"));
}
@Test
@@ -66,16 +66,12 @@ class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
@GetMapping("/")
public String hello() {
StringBuilder s = new StringBuilder();
for (int i = 0; i < 300000; i++) {
s.append(".");
}
return s.toString();
return ".".repeat(300000);
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll().and().csrf().disable();
http.authorizeHttpRequests().anyRequest().permitAll().and().csrf().disable();
return http.build();
}
@@ -40,7 +40,6 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
public class EurekaHttpClientsOptionalArgsConfigurationNoWebfluxTest {
@Test
@SuppressWarnings("unchecked")
public void contextFailsWithoutWebClient() {
ConfigurableApplicationContext ctx = null;
@@ -28,7 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Haytham Mohamed
**/
abstract class AbstractEurekaHttpClientTest {
abstract class AbstractEurekaHttpClientTests {
protected EurekaHttpClient eurekaHttpClient;
@@ -36,7 +36,7 @@ import org.springframework.test.annotation.DirtiesContext;
"eureka.client.register-with-eureka=false", "logging.level.org.springframework=INFO" },
webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
class RestTemplateEurekaHttpClientTest extends AbstractEurekaHttpClientTest {
class RestTemplateEurekaHttpClientTests extends AbstractEurekaHttpClientTests {
@Autowired
private InetUtils inetUtils;
@@ -37,7 +37,7 @@ import org.springframework.web.reactive.function.client.WebClient;
"eureka.client.fetch-registry=false", "eureka.client.register-with-eureka=false" },
webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
class WebClientEurekaHttpClientTest extends AbstractEurekaHttpClientTest {
class WebClientEurekaHttpClientTests extends AbstractEurekaHttpClientTests {
@Autowired
private InetUtils inetUtils;
@@ -35,16 +35,16 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class EurekaLoadBalancerClientConfigurationTests {
private EurekaClientConfigBean eurekaClientConfig = new EurekaClientConfigBean();
private final EurekaClientConfigBean eurekaClientConfig = new EurekaClientConfigBean();
private EurekaInstanceConfigBean eurekaInstanceConfig = new EurekaInstanceConfigBean(
private final EurekaInstanceConfigBean eurekaInstanceConfig = new EurekaInstanceConfigBean(
new InetUtils(new InetUtilsProperties()));
private LoadBalancerZoneConfig zoneConfig = new LoadBalancerZoneConfig(null);
private final LoadBalancerZoneConfig zoneConfig = new LoadBalancerZoneConfig(null);
private EurekaLoadBalancerProperties eurekaLoadBalancerProperties = new EurekaLoadBalancerProperties();
private final EurekaLoadBalancerProperties eurekaLoadBalancerProperties = new EurekaLoadBalancerProperties();
private EurekaLoadBalancerClientConfiguration postprocessor = new EurekaLoadBalancerClientConfiguration(
private final EurekaLoadBalancerClientConfiguration postprocessor = new EurekaLoadBalancerClientConfiguration(
eurekaClientConfig, eurekaInstanceConfig, zoneConfig, eurekaLoadBalancerProperties);
@Test
@@ -33,7 +33,7 @@ class DefaultManagementMetadataProviderTest {
private final ManagementMetadataProvider provider = new DefaultManagementMetadataProvider();
@BeforeEach
void setUp() throws Exception {
void setUp() {
when(INSTANCE.getHostname()).thenReturn("host");
when(INSTANCE.getHealthCheckUrlPath()).thenReturn("health");
when(INSTANCE.getStatusPageUrlPath()).thenReturn("info");
@@ -41,7 +41,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void serverPortIsRandomAndManagementPortIsNull() throws Exception {
void serverPortIsRandomAndManagementPortIsNull() {
int serverPort = 0;
String serverContextPath = "/";
String managementContextPath = null;
@@ -53,7 +53,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void managementPortIsRandom() throws Exception {
void managementPortIsRandom() {
int serverPort = 0;
String serverContextPath = "/";
String managementContextPath = null;
@@ -65,7 +65,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void serverPort() throws Exception {
void serverPort() {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = null;
@@ -80,7 +80,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void serverPortManagementPort() throws Exception {
void serverPortManagementPort() {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = null;
@@ -95,7 +95,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void serverPortManagementPortServerContextPath() throws Exception {
void serverPortManagementPortServerContextPath() {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = null;
@@ -110,7 +110,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void serverPortManagementPortServerContextPathManagementContextPath() throws Exception {
void serverPortManagementPortServerContextPathManagementContextPath() {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = "/Management";
@@ -125,7 +125,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void serverPortServerContextPathManagementContextPath() throws Exception {
void serverPortServerContextPathManagementContextPath() {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = "/Management";
@@ -140,7 +140,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void serverPortManagementContextPath() throws Exception {
void serverPortManagementContextPath() {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = "/Management";
@@ -155,7 +155,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void serverPortServerContextPath() throws Exception {
void serverPortServerContextPath() {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = null;
@@ -170,7 +170,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void serverPortManagementPortManagementContextPath() throws Exception {
void serverPortManagementPortManagementContextPath() {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = "/Management";
@@ -186,7 +186,7 @@ class DefaultManagementMetadataProviderTest {
}
@Test
void setSecureHealthCheckUrl() throws Exception {
void setSecureHealthCheckUrl() {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = "/Management";
@@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class EurekaReactiveDiscoveryClientConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
ReactiveCommonsClientAutoConfiguration.class, EurekaClientAutoConfiguration.class,
DiscoveryClientOptionalArgsConfiguration.class, EurekaReactiveDiscoveryClientConfiguration.class));
@@ -18,7 +18,6 @@ package org.springframework.cloud.netflix.eureka.reactive;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.Application;
import com.netflix.discovery.shared.Applications;
import org.junit.jupiter.api.Test;
@@ -47,9 +46,6 @@ class EurekaReactiveDiscoveryClientTests {
@Mock
private EurekaClient eurekaClient;
@Mock
private EurekaClientConfig clientConfig;
@InjectMocks
private EurekaReactiveDiscoveryClient client;
@@ -17,7 +17,6 @@
package org.springframework.cloud.netflix.eureka.sample;
import java.io.Closeable;
import java.io.IOException;
import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.appinfo.InstanceInfo;
@@ -103,7 +102,7 @@ public class EurekaSampleApplication implements ApplicationContextAware, Closeab
}
@Override
public void close() throws IOException {
public void close() {
deregister();
}
@@ -62,6 +62,7 @@ class EurekaServiceRegistryTests {
verifyNoInteractions(eurekaClient);
}
@SuppressWarnings("unchecked")
@Test
void eurekaClientGetStatus() {
EurekaServiceRegistry registry = new EurekaServiceRegistry();
@@ -98,6 +99,7 @@ class EurekaServiceRegistryTests {
OUT_OF_SERVICE.toString());
}
@SuppressWarnings("unchecked")
@Test
void eurekaClientGetStatusNoInstance() {
EurekaServiceRegistry registry = new EurekaServiceRegistry();
@@ -65,7 +65,7 @@ public class CloudJacksonJson extends LegacyJacksonJson {
}
@Override
public <T> String encode(T object) throws IOException {
public <T> String encode(T object) {
return this.codec.writeToString(object);
}
@@ -56,7 +56,7 @@ public class EurekaController {
@Value("${eureka.dashboard.path:/}")
private String dashboardPath = "";
private ApplicationInfoManager applicationInfoManager;
private final ApplicationInfoManager applicationInfoManager;
private final EurekaProperties eurekaProperties;
@@ -174,6 +174,7 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
return Jersey3TransportClientFactories.getInstance();
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
public EurekaHttpClient eurekaHttpClient(TransportClientFactories transportClientFactories, Environment env) {
return transportClientFactories
@@ -337,7 +338,7 @@ public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
@Bean
@ConditionalOnBean(name = "httpTraceFilter")
public FilterRegistrationBean<?> traceFilterRegistration(@Qualifier("httpTraceFilter") Filter filter) {
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<Filter>();
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
bean.setFilter(filter);
bean.setOrder(Ordered.LOWEST_PRECEDENCE - 10);
return bean;
@@ -1049,11 +1049,11 @@ public class EurekaServerConfigBean implements EurekaServerConfig {
registrySyncRetryWaitMs, remoteRegionAppWhitelist, remoteRegionConnectTimeoutMs,
remoteRegionConnectionIdleTimeoutSeconds, remoteRegionFetchThreadPoolSize, remoteRegionReadTimeoutMs,
remoteRegionRegistryFetchInterval, remoteRegionTotalConnections, remoteRegionTotalConnectionsPerHost,
remoteRegionTrustStore, remoteRegionTrustStorePassword, remoteRegionUrls, remoteRegionUrlsWithName,
renewalPercentThreshold, renewalThresholdUpdateIntervalMs, responseCacheAutoExpirationInSeconds,
responseCacheUpdateIntervalMs, retentionTimeInMSInDeltaQueue, route53BindRebindRetries,
route53BindingRetryIntervalMs, route53DomainTTL, syncWhenTimestampDiffers, useReadOnlyResponseCache,
waitTimeInMsWhenSyncEmpty, xmlCodecName, initialCapacityOfResponseCache,
remoteRegionTrustStore, remoteRegionTrustStorePassword, Arrays.hashCode(remoteRegionUrls),
remoteRegionUrlsWithName, renewalPercentThreshold, renewalThresholdUpdateIntervalMs,
responseCacheAutoExpirationInSeconds, responseCacheUpdateIntervalMs, retentionTimeInMSInDeltaQueue,
route53BindRebindRetries, route53BindingRetryIntervalMs, route53DomainTTL, syncWhenTimestampDiffers,
useReadOnlyResponseCache, waitTimeInMsWhenSyncEmpty, xmlCodecName, initialCapacityOfResponseCache,
expectedClientRenewalIntervalSeconds, useAwsAsgApi, myUrl);
}
@@ -52,7 +52,7 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
private boolean running;
private int order = 1;
private final int order = 1;
@Override
public void setServletContext(ServletContext servletContext) {
@@ -46,7 +46,7 @@ public class InstanceRegistry extends PeerAwareInstanceRegistryImpl implements A
private ApplicationContext ctxt;
private int defaultOpenForTrafficCount;
private final int defaultOpenForTrafficCount;
public InstanceRegistry(EurekaServerConfig serverConfig, EurekaClientConfig clientConfig, ServerCodecs serverCodecs,
EurekaClient eurekaClient, EurekaHttpClient eurekaHttpClient, int expectedNumberOfClientsSendingRenews,
@@ -27,7 +27,7 @@ import java.util.LinkedHashSet;
*/
public class ReplicationClientAdditionalFilters {
private Collection<?> filters;
private final Collection<?> filters;
public ReplicationClientAdditionalFilters(Collection<?> filters) {
this.filters = new LinkedHashSet<>(filters);
@@ -52,7 +52,7 @@ class EurekaControllerReplicasTests {
String totalNoAutoList = combinationNoAuthList1 + "," + combinationNoAuthList2;
String empty = new String();
String empty = "";
private ApplicationInfoManager original;
@@ -72,7 +72,7 @@ class EurekaControllerReplicasTests {
}
@Test
void testFilterReplicasNoAuth() throws Exception {
void testFilterReplicasNoAuth() {
Map<String, Object> model = new HashMap<>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().add("registered-replicas", empty)
.add("available-replicas", noAuthList1).add("unavailable-replicas", noAuthList2)
@@ -90,7 +90,7 @@ class EurekaControllerReplicasTests {
}
@Test
void testFilterReplicasAuth() throws Exception {
void testFilterReplicasAuth() {
Map<String, Object> model = new HashMap<>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().add("registered-replicas", authList2)
.add("available-replicas", authList1).add("unavailable-replicas", empty).withInstanceInfo(instanceInfo)
@@ -108,7 +108,7 @@ class EurekaControllerReplicasTests {
}
@Test
void testFilterReplicasAuthWithCombinationList() throws Exception {
void testFilterReplicasAuthWithCombinationList() {
Map<String, Object> model = new HashMap<>();
StatusInfo statusInfo = StatusInfo.Builder.newBuilder().add("registered-replicas", totalAutoList)
.add("available-replicas", combinationAuthList1).add("unavailable-replicas", combinationAuthList2)
@@ -93,7 +93,7 @@ class EurekaControllerTests {
}
@Test
void testStatus() throws Exception {
void testStatus() {
Map<String, Object> model = new HashMap<>();
EurekaController controller = new EurekaController(infoManager, new EurekaProperties());
@@ -71,7 +71,7 @@ class InstanceRegistryTests {
private TestEvents testEvents;
@Test
void testRegister() throws Exception {
void testRegister() {
// creating instance info
final LeaseInfo leaseInfo = getLeaseInfo();
final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, leaseInfo);
@@ -90,7 +90,7 @@ class InstanceRegistryTests {
}
@Test
void testDefaultLeaseDurationRegisterEvent() throws Exception {
void testDefaultLeaseDurationRegisterEvent() {
// creating instance info
final InstanceInfo instanceInfo = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, null);
// calling tested method
@@ -102,7 +102,7 @@ class InstanceRegistryTests {
}
@Test
void testInternalCancel() throws Exception {
void testInternalCancel() {
// calling tested method
instanceRegistry.internalCancel(APP_NAME, HOST_NAME, false);
// event of proper type is registered
@@ -118,7 +118,7 @@ class InstanceRegistryTests {
}
@Test
void testRenew() throws Exception {
void testRenew() {
// Creating two instances of the app
final InstanceInfo instanceInfo1 = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, null);
final InstanceInfo instanceInfo2 = getInstanceInfo(APP_NAME, HOST_NAME, "my-host-name:8009", 8009, null);
@@ -48,8 +48,10 @@ class RefreshablePeerEurekaNodesWithCustomFiltersTests {
assertThat(peerEurekaNodes instanceof RefreshablePeerEurekaNodes)
.as("PeerEurekaNodes should be an instance of RefreshablePeerEurekaNodes").isTrue();
ReplicationClientAdditionalFilters filters = getField(RefreshablePeerEurekaNodes.class,
(RefreshablePeerEurekaNodes) peerEurekaNodes, "replicationClientAdditionalFilters");
// ReplicationClientAdditionalFilters filters =
// getField(RefreshablePeerEurekaNodes.class,
// (RefreshablePeerEurekaNodes) peerEurekaNodes,
// "replicationClientAdditionalFilters");
// assertThat(filters.getFilters())
// .as("PeerEurekaNodes'should have only one filter set on
// replicationClientAdditionalFilters").hasSize(1);