Added checkstyle
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -42,14 +42,16 @@ import org.springframework.cloud.cloudfoundry.CloudFoundryService;
|
||||
public class CloudFoundryDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
private final CloudFoundryService cloudFoundryService;
|
||||
|
||||
private final CloudFoundryOperations cloudFoundryOperations;
|
||||
|
||||
private final CloudFoundryDiscoveryProperties properties;
|
||||
|
||||
private final String description = "Cloud Foundry " + DiscoveryClient.class.getName() + " implementation";
|
||||
private final String description = "Cloud Foundry " + DiscoveryClient.class.getName()
|
||||
+ " implementation";
|
||||
|
||||
CloudFoundryDiscoveryClient(CloudFoundryOperations cloudFoundryOperations,
|
||||
CloudFoundryService svc,
|
||||
CloudFoundryDiscoveryProperties properties) {
|
||||
CloudFoundryService svc, CloudFoundryDiscoveryProperties properties) {
|
||||
this.cloudFoundryService = svc;
|
||||
this.cloudFoundryOperations = cloudFoundryOperations;
|
||||
this.properties = properties;
|
||||
@@ -62,37 +64,30 @@ public class CloudFoundryDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
@Override
|
||||
public List<ServiceInstance> getInstances(String serviceId) {
|
||||
return cloudFoundryService
|
||||
.getApplicationInstances(serviceId)
|
||||
.map(tuple -> {
|
||||
ApplicationDetail applicationDetail = tuple.getT1();
|
||||
InstanceDetail instanceDetail = tuple.getT2();
|
||||
return this.cloudFoundryService.getApplicationInstances(serviceId).map(tuple -> {
|
||||
ApplicationDetail applicationDetail = tuple.getT1();
|
||||
InstanceDetail instanceDetail = tuple.getT2();
|
||||
|
||||
String applicationId = applicationDetail.getId();
|
||||
String applicationIndex = instanceDetail.getIndex();
|
||||
String name = applicationDetail.getName();
|
||||
String url = applicationDetail.getUrls().size() > 0 ? applicationDetail.getUrls().get(0) : null;
|
||||
boolean secure = (url + "").toLowerCase().startsWith("https");
|
||||
String applicationId = applicationDetail.getId();
|
||||
String applicationIndex = instanceDetail.getIndex();
|
||||
String name = applicationDetail.getName();
|
||||
String url = applicationDetail.getUrls().size() > 0
|
||||
? applicationDetail.getUrls().get(0) : null;
|
||||
boolean secure = (url + "").toLowerCase().startsWith("https");
|
||||
|
||||
HashMap<String, String> metadata = new HashMap<>();
|
||||
metadata.put("applicationId", applicationId);
|
||||
metadata.put("instanceId", applicationIndex);
|
||||
HashMap<String, String> metadata = new HashMap<>();
|
||||
metadata.put("applicationId", applicationId);
|
||||
metadata.put("instanceId", applicationIndex);
|
||||
|
||||
return (ServiceInstance) new DefaultServiceInstance(name, url, 80, secure, metadata);
|
||||
})
|
||||
.collectList()
|
||||
.blockOptional()
|
||||
.orElse(new ArrayList<>());
|
||||
return (ServiceInstance) new DefaultServiceInstance(name, url, 80, secure,
|
||||
metadata);
|
||||
}).collectList().blockOptional().orElse(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getServices() {
|
||||
return this.cloudFoundryOperations
|
||||
.applications()
|
||||
.list()
|
||||
.map(ApplicationSummary::getName)
|
||||
.collectList()
|
||||
.blockOptional()
|
||||
return this.cloudFoundryOperations.applications().list()
|
||||
.map(ApplicationSummary::getName).collectList().blockOptional()
|
||||
.orElse(new ArrayList<>());
|
||||
}
|
||||
|
||||
@@ -100,4 +95,5 @@ public class CloudFoundryDiscoveryClient implements DiscoveryClient {
|
||||
public int getOrder() {
|
||||
return this.properties.getOrder();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -44,7 +44,9 @@ public class CloudFoundryDiscoveryClientConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CloudFoundryHeartbeatSender cloudFoundryHeartbeatSender(CloudFoundryDiscoveryClient client) {
|
||||
public CloudFoundryHeartbeatSender cloudFoundryHeartbeatSender(
|
||||
CloudFoundryDiscoveryClient client) {
|
||||
return new CloudFoundryHeartbeatSender(client);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -21,7 +21,7 @@ import org.springframework.core.Ordered;
|
||||
|
||||
/**
|
||||
* Properties used for configuring the CloudFoundry implementation of
|
||||
* {@link org.springframework.cloud.client.discovery.DiscoveryClient}
|
||||
* {@link org.springframework.cloud.client.discovery.DiscoveryClient}.
|
||||
*
|
||||
* @author Olga Maciaszek-Sharma
|
||||
*/
|
||||
@@ -37,4 +37,5 @@ public class CloudFoundryDiscoveryClientProperties {
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -41,12 +41,13 @@ public class CloudFoundryDiscoveryProperties {
|
||||
private int defaultServerPort = 80;
|
||||
|
||||
/**
|
||||
* Order of the discovery client used by `CompositeDiscoveryClient` for sorting available clients.
|
||||
* Order of the discovery client used by `CompositeDiscoveryClient` for sorting
|
||||
* available clients.
|
||||
*/
|
||||
private int order = 0;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
@@ -62,7 +63,7 @@ public class CloudFoundryDiscoveryProperties {
|
||||
}
|
||||
|
||||
public int getDefaultServerPort() {
|
||||
return defaultServerPort;
|
||||
return this.defaultServerPort;
|
||||
}
|
||||
|
||||
public void setDefaultServerPort(int defaultServerPort) {
|
||||
@@ -70,7 +71,7 @@ public class CloudFoundryDiscoveryProperties {
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
@@ -79,11 +80,10 @@ public class CloudFoundryDiscoveryProperties {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CloudFoundryDiscoveryProperties{" +
|
||||
"enabled=" + enabled +
|
||||
", heartbeatFrequency=" + heartbeatFrequency +
|
||||
", defaultServerPort=" + defaultServerPort +
|
||||
", order=" + order +
|
||||
'}';
|
||||
return "CloudFoundryDiscoveryProperties{" + "enabled=" + this.enabled
|
||||
+ ", heartbeatFrequency=" + this.heartbeatFrequency
|
||||
+ ", defaultServerPort=" + this.defaultServerPort + ", order="
|
||||
+ this.order + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -35,6 +35,7 @@ import org.springframework.stereotype.Component;
|
||||
public class CloudFoundryHeartbeatSender implements ApplicationEventPublisherAware {
|
||||
|
||||
private final CloudFoundryDiscoveryClient client;
|
||||
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
public CloudFoundryHeartbeatSender(CloudFoundryDiscoveryClient client) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -18,6 +18,9 @@ package org.springframework.cloud.cloudfoundry.discovery;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import com.netflix.client.config.IClientConfig;
|
||||
import com.netflix.loadbalancer.ServerList;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
|
||||
import org.springframework.cloud.netflix.ribbon.RibbonClientName;
|
||||
@@ -25,9 +28,6 @@ import org.springframework.cloud.netflix.ribbon.RibbonUtils;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.netflix.client.config.IClientConfig;
|
||||
import com.netflix.loadbalancer.ServerList;
|
||||
|
||||
/**
|
||||
* @author Josh Long
|
||||
*/
|
||||
@@ -47,8 +47,9 @@ public class CloudFoundryRibbonClientConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ServerList<?> ribbonServerList(CloudFoundryService svc, IClientConfig config,
|
||||
CloudFoundryDiscoveryProperties properties) {
|
||||
CloudFoundryServerList cloudFoundryServerList = new CloudFoundryServerList(svc, properties);
|
||||
CloudFoundryDiscoveryProperties properties) {
|
||||
CloudFoundryServerList cloudFoundryServerList = new CloudFoundryServerList(svc,
|
||||
properties);
|
||||
cloudFoundryServerList.initWithNiwsConfig(config);
|
||||
return cloudFoundryServerList;
|
||||
}
|
||||
@@ -58,4 +59,4 @@ public class CloudFoundryRibbonClientConfiguration {
|
||||
RibbonUtils.initializeRibbonDefaults(this.serviceId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -54,4 +54,5 @@ public class CloudFoundryServer extends Server {
|
||||
public MetaInfo getMetaInfo() {
|
||||
return this.metaInfo;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -19,24 +19,28 @@ package org.springframework.cloud.cloudfoundry.discovery;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.netflix.client.config.IClientConfig;
|
||||
import com.netflix.loadbalancer.AbstractServerList;
|
||||
|
||||
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
|
||||
import org.springframework.cloud.netflix.ribbon.RibbonProperties;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.netflix.client.config.IClientConfig;
|
||||
import com.netflix.loadbalancer.AbstractServerList;
|
||||
|
||||
/**
|
||||
* @author Josh Long
|
||||
*/
|
||||
public class CloudFoundryServerList extends AbstractServerList<CloudFoundryServer> {
|
||||
|
||||
private final CloudFoundryService cloudFoundryService;
|
||||
|
||||
private final CloudFoundryDiscoveryProperties properties;
|
||||
|
||||
private IClientConfig clientConfig;
|
||||
|
||||
private String serviceId;
|
||||
|
||||
CloudFoundryServerList(CloudFoundryService svc, CloudFoundryDiscoveryProperties properties) {
|
||||
CloudFoundryServerList(CloudFoundryService svc,
|
||||
CloudFoundryDiscoveryProperties properties) {
|
||||
this.cloudFoundryService = svc;
|
||||
this.properties = properties;
|
||||
}
|
||||
@@ -60,7 +64,7 @@ public class CloudFoundryServerList extends AbstractServerList<CloudFoundryServe
|
||||
private List<CloudFoundryServer> cloudFoundryServers() {
|
||||
Assert.notNull(this.clientConfig, "clientConfig may not be null");
|
||||
|
||||
RibbonProperties ribbon = RibbonProperties.from(clientConfig);
|
||||
RibbonProperties ribbon = RibbonProperties.from(this.clientConfig);
|
||||
|
||||
Boolean secure = ribbon.getSecure();
|
||||
Integer securePort = ribbon.getSecurePort();
|
||||
@@ -69,21 +73,23 @@ public class CloudFoundryServerList extends AbstractServerList<CloudFoundryServe
|
||||
final int port;
|
||||
if (secure != null && secure && securePort != null) {
|
||||
port = securePort;
|
||||
} else if (nonSecurePort != null) {
|
||||
}
|
||||
else if (nonSecurePort != null) {
|
||||
port = nonSecurePort;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
port = this.properties.getDefaultServerPort();
|
||||
}
|
||||
|
||||
return cloudFoundryService
|
||||
.getApplicationInstances(this.serviceId)
|
||||
.map(tpl -> new CloudFoundryServer(tpl.getT1().getName(), tpl.getT1().getUrls().get(0), port))
|
||||
.collectList()
|
||||
.blockOptional()
|
||||
.orElse(new ArrayList<>());
|
||||
return this.cloudFoundryService.getApplicationInstances(this.serviceId)
|
||||
.map(tpl -> new CloudFoundryServer(tpl.getT1().getName(),
|
||||
tpl.getT1().getUrls().get(0), port))
|
||||
.collectList().blockOptional().orElse(new ArrayList<>());
|
||||
}
|
||||
|
||||
/** for testing */ String getServiceId() {
|
||||
return serviceId;
|
||||
// for testing
|
||||
String getServiceId() {
|
||||
return this.serviceId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -26,9 +26,10 @@ import java.lang.annotation.Target;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* Convenience annotation for clients to enable Cloud Foundry discovery configuration (specifically).
|
||||
* Use this (optionally) in case you want discovery and know for sure that it is Cloud Foundry you want.
|
||||
* All it does is turn on discovery and let the auto-configuration find the Cloud Foundry classes.
|
||||
* Convenience annotation for clients to enable Cloud Foundry discovery configuration
|
||||
* (specifically). Use this (optionally) in case you want discovery and know for sure that
|
||||
* it is Cloud Foundry you want. All it does is turn on discovery and let the
|
||||
* auto-configuration find the Cloud Foundry classes.
|
||||
*
|
||||
* @author Josh Long
|
||||
*/
|
||||
@@ -38,4 +39,5 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
@Inherited
|
||||
@EnableDiscoveryClient
|
||||
public @interface EnableCloudFoundryClient {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.cloudfoundry.discovery;
|
||||
|
||||
import com.netflix.client.IClient;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -26,8 +28,11 @@ import org.springframework.cloud.netflix.ribbon.RibbonClients;
|
||||
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.netflix.client.IClient;
|
||||
|
||||
/**
|
||||
* Auto configuration for Ribbon.
|
||||
*
|
||||
* @author Josh Long
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
@ConditionalOnClass(IClient.class)
|
||||
@@ -36,4 +41,5 @@ import com.netflix.client.IClient;
|
||||
@AutoConfigureAfter(RibbonAutoConfiguration.class)
|
||||
@RibbonClients(defaultConfiguration = CloudFoundryRibbonClientConfiguration.class)
|
||||
public class RibbonCloudFoundryAutoConfiguration {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.cloudfoundry.discovery.RibbonCloudFoundryAutoConfiguration
|
||||
|
||||
# Discovery Client Configuration
|
||||
org.springframework.cloud.client.discovery.EnableDiscoveryClient=\
|
||||
org.springframework.cloud.cloudfoundry.discovery.CloudFoundryDiscoveryClientConfiguration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -27,7 +27,7 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({CloudFoundryServerListTest.class})
|
||||
@SuiteClasses({ CloudFoundryServerListTest.class })
|
||||
@Ignore
|
||||
public class AdhocTestSuite {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.cloud.cloudfoundry.discovery;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.cloudfoundry.operations.CloudFoundryOperations;
|
||||
@@ -23,20 +26,17 @@ import org.cloudfoundry.operations.applications.ApplicationDetail;
|
||||
import org.cloudfoundry.operations.applications.ApplicationSummary;
|
||||
import org.cloudfoundry.operations.applications.Applications;
|
||||
import org.cloudfoundry.operations.applications.InstanceDetail;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuples;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
@@ -45,60 +45,53 @@ import static org.mockito.Mockito.mock;
|
||||
public class CloudFoundryDiscoveryClientTest {
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private CloudFoundryDiscoveryClient cloudFoundryDiscoveryClient;
|
||||
|
||||
private String hiServiceServiceId = "hi-service";
|
||||
|
||||
private CloudFoundryOperations ops;
|
||||
|
||||
private CloudFoundryService svc;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.ops = mock(CloudFoundryOperations.class);
|
||||
this.svc = mock(CloudFoundryService.class);
|
||||
this.cloudFoundryDiscoveryClient = new CloudFoundryDiscoveryClient(this.ops, this.svc,
|
||||
new CloudFoundryDiscoveryProperties());
|
||||
this.cloudFoundryDiscoveryClient = new CloudFoundryDiscoveryClient(this.ops,
|
||||
this.svc, new CloudFoundryDiscoveryProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServiceResolution() {
|
||||
Applications apps = mock(Applications.class);
|
||||
ApplicationSummary s = ApplicationSummary.builder()
|
||||
.id(UUID.randomUUID().toString())
|
||||
.instances(2)
|
||||
.memoryLimit(1024)
|
||||
.requestedState("requestedState")
|
||||
.diskQuota(1024)
|
||||
.name(this.hiServiceServiceId)
|
||||
.runningInstances(2)
|
||||
.build();
|
||||
.id(UUID.randomUUID().toString()).instances(2).memoryLimit(1024)
|
||||
.requestedState("requestedState").diskQuota(1024)
|
||||
.name(this.hiServiceServiceId).runningInstances(2).build();
|
||||
Mockito.when(apps.list()).thenReturn(Flux.just(s));
|
||||
Mockito.when(this.ops.applications()).thenReturn(apps);
|
||||
List<String> serviceNames = this.cloudFoundryDiscoveryClient.getServices();
|
||||
Assert.assertTrue("there should be one registered service.", serviceNames.contains(this.hiServiceServiceId));
|
||||
serviceNames.forEach(serviceName -> this.log.debug("\t discovered serviceName: " + serviceName));
|
||||
assertThat(serviceNames.contains(this.hiServiceServiceId))
|
||||
.as("there should be one registered service.").isTrue();
|
||||
serviceNames.forEach(serviceName -> this.log
|
||||
.debug("\t discovered serviceName: " + serviceName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstances() {
|
||||
ApplicationDetail applicationDetail = ApplicationDetail
|
||||
.builder()
|
||||
.instances(2)
|
||||
.name("my-app")
|
||||
.stack("stack")
|
||||
.memoryLimit(1024)
|
||||
.id("id")
|
||||
.requestedState("requestedState")
|
||||
.runningInstances(2)
|
||||
.url("http://my-app.cfapps.io")
|
||||
.diskQuota(20)
|
||||
.build();
|
||||
InstanceDetail instanceDetail = InstanceDetail
|
||||
.builder()
|
||||
.index("0")
|
||||
.build();
|
||||
Tuple2<ApplicationDetail, InstanceDetail> tuple2 = Tuples.of(applicationDetail, instanceDetail);
|
||||
Mockito.when(svc.getApplicationInstances(this.hiServiceServiceId)).thenReturn(Flux.just(tuple2));
|
||||
ApplicationDetail applicationDetail = ApplicationDetail.builder().instances(2)
|
||||
.name("my-app").stack("stack").memoryLimit(1024).id("id")
|
||||
.requestedState("requestedState").runningInstances(2)
|
||||
.url("http://my-app.cfapps.io").diskQuota(20).build();
|
||||
InstanceDetail instanceDetail = InstanceDetail.builder().index("0").build();
|
||||
Tuple2<ApplicationDetail, InstanceDetail> tuple2 = Tuples.of(applicationDetail,
|
||||
instanceDetail);
|
||||
Mockito.when(this.svc.getApplicationInstances(this.hiServiceServiceId))
|
||||
.thenReturn(Flux.just(tuple2));
|
||||
List<ServiceInstance> instances = this.cloudFoundryDiscoveryClient
|
||||
.getInstances(this.hiServiceServiceId);
|
||||
assertEquals("Wrong instances: " + instances, 1, instances.size());
|
||||
assertThat(instances.size()).as("Wrong instances: " + instances).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -18,36 +18,35 @@ package org.springframework.cloud.cloudfoundry.discovery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.netflix.client.config.CommonClientConfigKey;
|
||||
import com.netflix.client.config.IClientConfig;
|
||||
import org.cloudfoundry.operations.applications.ApplicationDetail;
|
||||
import org.cloudfoundry.operations.applications.InstanceDetail;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuples;
|
||||
|
||||
import com.netflix.client.config.CommonClientConfigKey;
|
||||
import com.netflix.client.config.IClientConfig;
|
||||
import org.springframework.cloud.cloudfoundry.CloudFoundryService;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuples;
|
||||
|
||||
/**
|
||||
* @author Josh Long
|
||||
*/
|
||||
public class CloudFoundryServerListTest {
|
||||
|
||||
private CloudFoundryServerList cloudFoundryServerList;
|
||||
|
||||
private String serviceId = "foo-service";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
IClientConfig iClientConfig = IClientConfig.Builder.newBuilder(this.serviceId)
|
||||
.withSecure(true)
|
||||
.build();
|
||||
.withSecure(true).build();
|
||||
iClientConfig.set(CommonClientConfigKey.SecurePort, 443);
|
||||
|
||||
Tuple2<ApplicationDetail, InstanceDetail> tuple2 = getInstanceDetail();
|
||||
@@ -55,7 +54,8 @@ public class CloudFoundryServerListTest {
|
||||
CloudFoundryService cfs = mock(CloudFoundryService.class);
|
||||
when(cfs.getApplicationInstances(this.serviceId)).thenReturn(Flux.just(tuple2));
|
||||
|
||||
this.cloudFoundryServerList = new CloudFoundryServerList(cfs, new CloudFoundryDiscoveryProperties());
|
||||
this.cloudFoundryServerList = new CloudFoundryServerList(cfs,
|
||||
new CloudFoundryDiscoveryProperties());
|
||||
this.cloudFoundryServerList.initWithNiwsConfig(iClientConfig);
|
||||
}
|
||||
|
||||
@@ -85,8 +85,10 @@ public class CloudFoundryServerListTest {
|
||||
|
||||
@Test
|
||||
public void testListOfServers() {
|
||||
List<CloudFoundryServer> initialListOfServers = this.cloudFoundryServerList.getInitialListOfServers();
|
||||
List<CloudFoundryServer> updatedListOfServers = this.cloudFoundryServerList.getUpdatedListOfServers();
|
||||
List<CloudFoundryServer> initialListOfServers = this.cloudFoundryServerList
|
||||
.getInitialListOfServers();
|
||||
List<CloudFoundryServer> updatedListOfServers = this.cloudFoundryServerList
|
||||
.getUpdatedListOfServers();
|
||||
assertThat(initialListOfServers)
|
||||
.containsExactly(updatedListOfServers.toArray(new CloudFoundryServer[0]))
|
||||
.hasSize(1);
|
||||
@@ -105,7 +107,8 @@ public class CloudFoundryServerListTest {
|
||||
CloudFoundryService cfs = mock(CloudFoundryService.class);
|
||||
when(cfs.getApplicationInstances(this.serviceId)).thenReturn(Flux.just(tuple2));
|
||||
|
||||
CloudFoundryServerList serverList = new CloudFoundryServerList(cfs, new CloudFoundryDiscoveryProperties());
|
||||
CloudFoundryServerList serverList = new CloudFoundryServerList(cfs,
|
||||
new CloudFoundryDiscoveryProperties());
|
||||
serverList.initWithNiwsConfig(iClientConfig);
|
||||
|
||||
CloudFoundryServer server = serverList.getInitialListOfServers().get(0);
|
||||
|
||||
Reference in New Issue
Block a user