diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryAppServiceDiscoveryClient.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryAppServiceDiscoveryClient.java index 8e73127..4d397bb 100644 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryAppServiceDiscoveryClient.java +++ b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryAppServiceDiscoveryClient.java @@ -33,7 +33,6 @@ import org.springframework.cloud.cloudfoundry.CloudFoundryService; * Discovery. * * @author Toshiaki Maki - * * @see CF App Service * Discovery Release * @see getInstances(String serviceId) { return getCloudFoundryService() - .getApplicationInstances(serviceId) - .filter(tuple -> tuple.getT1().getUrls().stream() - .anyMatch(this::isInternalDomain)) + .getApplicationInstances(serviceId).filter(tuple -> tuple.getT1() + .getUrls().stream().anyMatch(this::isInternalDomain)) .map(tuple -> { ApplicationDetail applicationDetail = tuple.getT1(); InstanceDetail instanceDetail = tuple.getT2(); @@ -67,21 +66,18 @@ public class CloudFoundryAppServiceDiscoveryClient extends CloudFoundryDiscovery String applicationIndex = instanceDetail.getIndex(); String name = applicationDetail.getName(); String url = applicationDetail.getUrls().stream() - .filter(this::isInternalDomain) - .findFirst() - .map(x -> instanceDetail.getIndex() + "." + x) - .get(); + .filter(this::isInternalDomain).findFirst() + .map(x -> instanceDetail.getIndex() + "." + x).get(); HashMap metadata = new HashMap<>(); metadata.put("applicationId", applicationId); metadata.put("instanceId", applicationIndex); return (ServiceInstance) new DefaultServiceInstance(name, url, 8080, false, metadata); - }) - .collectList() - .block(); + }).collectList().block(); } private boolean isInternalDomain(String url) { return url != null && url.endsWith(INTERNAL_DOMAIN); } + } diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClient.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClient.java index 1e19c88..6160cb7 100644 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClient.java +++ b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClient.java @@ -101,4 +101,5 @@ public class CloudFoundryDiscoveryClient implements DiscoveryClient { CloudFoundryService getCloudFoundryService() { return this.cloudFoundryService; } + } diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfiguration.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfiguration.java index 8860ca2..1649c21 100644 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfiguration.java +++ b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfiguration.java @@ -35,7 +35,8 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @ConditionalOnClass(CloudFoundryOperations.class) -@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.enabled", matchIfMissing = true) +@ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.enabled", + matchIfMissing = true) @EnableConfigurationProperties(CloudFoundryDiscoveryProperties.class) public class CloudFoundryDiscoveryClientConfiguration { @@ -47,24 +48,30 @@ public class CloudFoundryDiscoveryClientConfiguration { } @Configuration - @ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-dns", havingValue = "false", matchIfMissing = true) + @ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-dns", + havingValue = "false", matchIfMissing = true) public static class CloudFoundryDiscoveryClientConfig { + @Bean @ConditionalOnMissingBean(DiscoveryClient.class) - public CloudFoundryDiscoveryClient cloudFoundryDiscoveryClient(CloudFoundryOperations cf, - CloudFoundryService svc, + public CloudFoundryDiscoveryClient cloudFoundryDiscoveryClient( + CloudFoundryOperations cf, CloudFoundryService svc, CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties) { return new CloudFoundryDiscoveryClient(cf, svc, cloudFoundryDiscoveryProperties); } + } @Configuration - @ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-dns", havingValue = "true") + @ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-dns", + havingValue = "true") public static class DnsBasedCloudFoundryDiscoveryClientConfig { @Bean - @ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "true") + @ConditionalOnProperty( + value = "spring.cloud.cloudfoundry.discovery.use-container-ip", + havingValue = "true") @ConditionalOnMissingBean(DiscoveryClient.class) public SimpleDnsBasedDiscoveryClient discoveryClient( ObjectProvider provider, @@ -75,7 +82,9 @@ public class CloudFoundryDiscoveryClientConfiguration { } @Bean - @ConditionalOnProperty(value = "spring.cloud.cloudfoundry.discovery.use-container-ip", havingValue = "false", matchIfMissing = true) + @ConditionalOnProperty( + value = "spring.cloud.cloudfoundry.discovery.use-container-ip", + havingValue = "false", matchIfMissing = true) @ConditionalOnMissingBean(DiscoveryClient.class) public CloudFoundryAppServiceDiscoveryClient cloudFoundryDiscoveryClient( CloudFoundryOperations cf, CloudFoundryService svc, diff --git a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryHeartbeatSender.java b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryHeartbeatSender.java index e859f73..cac7c85 100644 --- a/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryHeartbeatSender.java +++ b/spring-cloud-cloudfoundry-discovery/src/main/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryHeartbeatSender.java @@ -42,7 +42,8 @@ public class CloudFoundryHeartbeatSender implements ApplicationEventPublisherAwa this.client = client; } - @Scheduled(fixedDelayString = "${spring.cloud.cloudfoundry.discovery.heartbeatFrequency:5000}") + @Scheduled( + fixedDelayString = "${spring.cloud.cloudfoundry.discovery.heartbeatFrequency:5000}") public void poll() { if (this.publisher != null) { List services = this.client.getServices(); diff --git a/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryAppServiceDiscoveryClientTest.java b/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryAppServiceDiscoveryClientTest.java index 1599f7f..8803a18 100644 --- a/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryAppServiceDiscoveryClientTest.java +++ b/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryAppServiceDiscoveryClientTest.java @@ -39,8 +39,11 @@ import static org.mockito.Mockito.mock; * @author Toshiaki Maki */ public class CloudFoundryAppServiceDiscoveryClientTest { + private CloudFoundryAppServiceDiscoveryClient discoveryClient; + private CloudFoundryOperations cloudFoundryOperations; + private CloudFoundryService cloudFoundryService; @Before @@ -129,4 +132,5 @@ public class CloudFoundryAppServiceDiscoveryClientTest { assertThat(instances).isEmpty(); } + } diff --git a/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfigurationTest.java b/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfigurationTest.java index b8a8e8c..41e2cec 100644 --- a/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfigurationTest.java +++ b/spring-cloud-cloudfoundry-discovery/src/test/java/org/springframework/cloud/cloudfoundry/discovery/CloudFoundryDiscoveryClientConfigurationTest.java @@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link CloudFoundryDiscoveryClientConfiguration}. + * * @author Toshiaki Maki */ public class CloudFoundryDiscoveryClientConfigurationTest { @@ -102,6 +103,7 @@ public class CloudFoundryDiscoveryClientConfigurationTest { @Configuration public static class CloudFoundryConfig { + @Bean public CloudFoundryOperations cloudFoundryOperations() { return Mockito.mock(CloudFoundryOperations.class); @@ -111,5 +113,7 @@ public class CloudFoundryDiscoveryClientConfigurationTest { public CloudFoundryService cloudFoundryService() { return Mockito.mock(CloudFoundryService.class); } + } + }