Implements ConsulServiceRegistry and auto registration
No longer create ConsulLifecycle bean by default. It is now deprecated. New auto registration is not created if user has created ConsulLifecycle bean.
This commit is contained in:
@@ -37,9 +37,9 @@ See the https://consul.io/intro/index.html[intro] for more information.
|
||||
1. Run `docker-compose up`
|
||||
2. Verify consul is running by visiting http://localhost:8500
|
||||
3. Run `mvn package` this will bring in the required spring cloud maven repositories and build
|
||||
4. Run `java -jar spring-cloud-consul-sample/target/spring-cloud-consul-sample-1.1.3.BUILD-SNAPSHOT.jar`
|
||||
4. Run `java -jar spring-cloud-consul-sample/target/spring-cloud-consul-sample-1.2.0.BUILD-SNAPSHOT.jar`
|
||||
5. visit http://localhost:8080, verify that `{"serviceId":"<yourhost>:8080","host":"<yourhost>","port":8080}` results
|
||||
6. run `java -jar spring-cloud-consul-sample/target/spring-cloud-consul-sample-1.1.3.BUILD-SNAPSHOT.jar --server.port=8081`
|
||||
6. run `java -jar spring-cloud-consul-sample/target/spring-cloud-consul-sample-1.2.0.BUILD-SNAPSHOT.jar --server.port=8081`
|
||||
7. visit http://localhost:8080 again, verify that `{"serviceId":"<yourhost>:8081","host":"<yourhost>","port":8081}` eventually shows up in the results in a round robbin fashion (may take a minute or so).
|
||||
|
||||
== Building
|
||||
@@ -212,4 +212,4 @@ added after the original pull request but before a merge.
|
||||
other target branch in the main project).
|
||||
* When writing a commit message please follow http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions],
|
||||
if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit
|
||||
message (where XXXX is the issue number).
|
||||
message (where XXXX is the issue number).
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-consul-docs</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -28,9 +28,9 @@ See the https://consul.io/intro/index.html[intro] for more information.
|
||||
1. Run `docker-compose up`
|
||||
2. Verify consul is running by visiting http://localhost:8500
|
||||
3. Run `mvn package` this will bring in the required spring cloud maven repositories and build
|
||||
4. Run `java -jar spring-cloud-consul-sample/target/spring-cloud-consul-sample-1.1.3.BUILD-SNAPSHOT.jar`
|
||||
4. Run `java -jar spring-cloud-consul-sample/target/spring-cloud-consul-sample-1.2.0.BUILD-SNAPSHOT.jar`
|
||||
5. visit http://localhost:8080, verify that `{"serviceId":"<yourhost>:8080","host":"<yourhost>","port":8080}` results
|
||||
6. run `java -jar spring-cloud-consul-sample/target/spring-cloud-consul-sample-1.1.3.BUILD-SNAPSHOT.jar --server.port=8081`
|
||||
6. run `java -jar spring-cloud-consul-sample/target/spring-cloud-consul-sample-1.2.0.BUILD-SNAPSHOT.jar --server.port=8081`
|
||||
7. visit http://localhost:8080 again, verify that `{"serviceId":"<yourhost>:8081","host":"<yourhost>","port":8081}` eventually shows up in the results in a round robbin fashion (may take a minute or so).
|
||||
|
||||
== Building
|
||||
|
||||
6
pom.xml
6
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Spring Cloud Consul</name>
|
||||
<description>Spring Cloud Consul</description>
|
||||
@@ -21,9 +21,9 @@
|
||||
|
||||
<properties>
|
||||
<spring-cloud-bus.version>1.2.2.BUILD-SNAPSHOT</spring-cloud-bus.version>
|
||||
<spring-cloud-commons.version>1.1.7.BUILD-SNAPSHOT</spring-cloud-commons.version>
|
||||
<spring-cloud-commons.version>1.2.0.BUILD-SNAPSHOT</spring-cloud-commons.version>
|
||||
<spring-cloud-config.version>1.2.3.BUILD-SNAPSHOT</spring-cloud-config.version>
|
||||
<spring-cloud-netflix.version>1.2.4.BUILD-SNAPSHOT</spring-cloud-netflix.version>
|
||||
<spring-cloud-netflix.version>1.3.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
|
||||
<spring-cloud-deployer.version>1.0.4.BUILD-SNAPSHOT</spring-cloud-deployer.version>
|
||||
<spring-cloud-stream.version>Brooklyn.BUILD-SNAPSHOT</spring-cloud-stream.version>
|
||||
</properties>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-consul-dependencies</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>spring-cloud-consul-dependencies</name>
|
||||
<description>Spring Cloud Consul Dependencies</description>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -34,11 +34,11 @@ import com.ecwid.consul.v1.agent.model.Self;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import com.ecwid.consul.v1.health.model.HealthService;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
|
||||
import static org.springframework.cloud.consul.discovery.ConsulServerUtils.findHost;
|
||||
import static org.springframework.cloud.consul.discovery.ConsulServerUtils.getMetadata;
|
||||
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Joe Athman
|
||||
@@ -46,19 +46,38 @@ import static org.springframework.cloud.consul.discovery.ConsulServerUtils.getMe
|
||||
@CommonsLog
|
||||
public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
private final ConsulLifecycle lifecycle;
|
||||
interface LocalResolver {
|
||||
String getServiceId();
|
||||
Integer getPort();
|
||||
}
|
||||
|
||||
private final ConsulClient client;
|
||||
|
||||
private final ConsulDiscoveryProperties properties;
|
||||
private final LocalResolver localResolver;
|
||||
|
||||
private ServerProperties serverProperties;
|
||||
|
||||
public ConsulDiscoveryClient(ConsulClient client, ConsulLifecycle lifecycle,
|
||||
ConsulDiscoveryProperties properties) {
|
||||
@Deprecated
|
||||
public ConsulDiscoveryClient(ConsulClient client, final ConsulLifecycle lifecycle,
|
||||
ConsulDiscoveryProperties properties) {
|
||||
this(client, properties, new LocalResolver() {
|
||||
@Override
|
||||
public String getServiceId() {
|
||||
return lifecycle.getServiceId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPort() {
|
||||
return lifecycle.getConfiguredPort();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ConsulDiscoveryClient(ConsulClient client, ConsulDiscoveryProperties properties,
|
||||
LocalResolver localResolver) {
|
||||
this.client = client;
|
||||
this.lifecycle = lifecycle;
|
||||
this.properties = properties;
|
||||
this.localResolver = localResolver;
|
||||
}
|
||||
|
||||
public void setServerProperties(ServerProperties serverProperties) {
|
||||
@@ -73,7 +92,7 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
@Override
|
||||
public ServiceInstance getLocalServiceInstance() {
|
||||
Response<Map<String, Service>> agentServices = client.getAgentServices();
|
||||
Service service = agentServices.getValue().get(lifecycle.getServiceId());
|
||||
Service service = agentServices.getValue().get(localResolver.getServiceId());
|
||||
String serviceId;
|
||||
Integer port;
|
||||
Map<String, String> metadata;
|
||||
@@ -88,10 +107,10 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
} else {
|
||||
// possibly called before registration, use configuration or best guess
|
||||
log.warn("Unable to locate service in consul agent: "
|
||||
+ lifecycle.getServiceId());
|
||||
+ localResolver.getServiceId());
|
||||
|
||||
serviceId = lifecycle.getServiceId();
|
||||
port = lifecycle.getConfiguredPort();
|
||||
serviceId = localResolver.getServiceId();
|
||||
port = localResolver.getPort();
|
||||
if (port == 0 && serverProperties != null
|
||||
&& serverProperties.getPort() != null) {
|
||||
port = serverProperties.getPort();
|
||||
|
||||
@@ -16,21 +16,21 @@
|
||||
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.cloud.consul.ConditionalOnConsulEnabled;
|
||||
import org.springframework.cloud.consul.serviceregistry.ConsulRegistration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -46,57 +46,77 @@ public class ConsulDiscoveryClientConfiguration {
|
||||
@Autowired(required = false)
|
||||
private ServerProperties serverProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private TtlScheduler ttlScheduler;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ServletContext servletContext;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
|
||||
public ConsulLifecycle consulLifecycle(ConsulDiscoveryProperties discoveryProperties,
|
||||
HeartbeatProperties heartbeatProperties) {
|
||||
ConsulLifecycle lifecycle = new ConsulLifecycle(consulClient, discoveryProperties, heartbeatProperties);
|
||||
if (this.ttlScheduler != null) {
|
||||
lifecycle.setTtlScheduler(this.ttlScheduler);
|
||||
}
|
||||
if (this.servletContext != null) {
|
||||
lifecycle.setServletContext(this.servletContext);
|
||||
}
|
||||
if (this.serverProperties != null && this.serverProperties.getPort() != null && this.serverProperties.getPort() > 0) {
|
||||
// no need to wait for events for this to start since the user has explicitly set the port.
|
||||
lifecycle.setPort(this.serverProperties.getPort());
|
||||
}
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty("spring.cloud.consul.discovery.heartbeat.enabled")
|
||||
//TODO: move to service-registry for Edgware
|
||||
public TtlScheduler ttlScheduler(HeartbeatProperties heartbeatProperties) {
|
||||
return new TtlScheduler(heartbeatProperties, consulClient);
|
||||
}
|
||||
|
||||
@Bean
|
||||
//TODO: move to service-registry for Edgware
|
||||
public HeartbeatProperties heartbeatProperties() {
|
||||
return new HeartbeatProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
//TODO: Split appropriate values to service-registry for Edgware
|
||||
public ConsulDiscoveryProperties consulDiscoveryProperties(InetUtils inetUtils) {
|
||||
return new ConsulDiscoveryProperties(inetUtils);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulDiscoveryClient consulDiscoveryClient(ConsulLifecycle consulLifecycle,
|
||||
ConsulDiscoveryProperties discoveryProperties) {
|
||||
public ConsulDiscoveryClient consulDiscoveryClient(ConsulDiscoveryProperties discoveryProperties, final ApplicationContext context) {
|
||||
ConsulDiscoveryClient discoveryClient = new ConsulDiscoveryClient(consulClient,
|
||||
consulLifecycle, discoveryProperties);
|
||||
discoveryProperties, new LifecycleRegistrationResolver(context));
|
||||
discoveryClient.setServerProperties(serverProperties); //null ok
|
||||
return discoveryClient;
|
||||
}
|
||||
|
||||
class LifecycleRegistrationResolver implements ConsulDiscoveryClient.LocalResolver {
|
||||
private ApplicationContext context;
|
||||
|
||||
public LifecycleRegistrationResolver(ApplicationContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServiceId() {
|
||||
ConsulRegistration registration = getBean(ConsulRegistration.class);
|
||||
if (registration != null) {
|
||||
return registration.getServiceId();
|
||||
}
|
||||
ConsulLifecycle lifecycle = getBean(ConsulLifecycle.class);
|
||||
if (lifecycle != null) {
|
||||
return lifecycle.getServiceId();
|
||||
}
|
||||
throw new IllegalStateException("Must have one of ConsulRegistration or ConsulLifecycle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPort() {
|
||||
ConsulRegistration registration = getBean(ConsulRegistration.class);
|
||||
if (registration != null) {
|
||||
return registration.getService().getPort();
|
||||
}
|
||||
ConsulLifecycle lifecycle = getBean(ConsulLifecycle.class);
|
||||
if (lifecycle != null) {
|
||||
return lifecycle.getConfiguredPort();
|
||||
}
|
||||
throw new IllegalStateException("Must have one of ConsulRegistration or ConsulLifecycle");
|
||||
}
|
||||
|
||||
<T> T getBean(Class<T> type) {
|
||||
try {
|
||||
return context.getBean(type);
|
||||
} catch (NoSuchBeanDefinitionException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(name = "spring.cloud.consul.discovery.catalogServicesWatch.enabled", matchIfMissing = true)
|
||||
|
||||
@@ -191,7 +191,7 @@ public class ConsulDiscoveryProperties {
|
||||
}
|
||||
|
||||
@Data
|
||||
public class Lifecycle {
|
||||
public static class Lifecycle {
|
||||
private boolean enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,18 @@
|
||||
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.cloud.client.discovery.AbstractDiscoveryLifecycle;
|
||||
import org.springframework.cloud.consul.serviceregistry.ConsulRegistration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecwid.consul.ConsulException;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
@@ -36,8 +38,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Venil Noronha
|
||||
*
|
||||
* @deprecated See {@link org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistration}
|
||||
*/
|
||||
@Slf4j
|
||||
@Deprecated
|
||||
public class ConsulLifecycle extends AbstractDiscoveryLifecycle {
|
||||
|
||||
public static final char SEPARATOR = '-';
|
||||
@@ -55,6 +60,7 @@ public class ConsulLifecycle extends AbstractDiscoveryLifecycle {
|
||||
private NewService service = new NewService();
|
||||
|
||||
private String instanceId;
|
||||
private RelaxedPropertyResolver propertyResolver;
|
||||
|
||||
public ConsulLifecycle(ConsulClient client, ConsulDiscoveryProperties properties, HeartbeatProperties ttlConfig) {
|
||||
this.client = client;
|
||||
@@ -70,6 +76,12 @@ public class ConsulLifecycle extends AbstractDiscoveryLifecycle {
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
super.setApplicationContext(applicationContext);
|
||||
this.propertyResolver = new RelaxedPropertyResolver(applicationContext.getEnvironment());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getConfiguredPort() {
|
||||
return service.getPort() == null? 0 : service.getPort();
|
||||
@@ -97,60 +109,24 @@ public class ConsulLifecycle extends AbstractDiscoveryLifecycle {
|
||||
return;
|
||||
}
|
||||
Assert.notNull(service.getPort(), "service.port has not been set");
|
||||
String appName = getAppName();
|
||||
service.setId(getServiceId());
|
||||
if(!properties.isPreferAgentAddress()) {
|
||||
service.setAddress(properties.getHostname());
|
||||
}
|
||||
service.setName(normalizeForDns(appName));
|
||||
service.setTags(createTags());
|
||||
|
||||
// If an alternate external port is specified, register using it instead
|
||||
if (properties.getPort() != null) {
|
||||
service.setPort(properties.getPort());
|
||||
}
|
||||
|
||||
if (this.properties.isRegisterHealthCheck()) {
|
||||
Integer checkPort;
|
||||
if (shouldRegisterManagement()) {
|
||||
checkPort = getManagementPort();
|
||||
} else {
|
||||
checkPort = service.getPort();
|
||||
}
|
||||
service.setCheck(createCheck(checkPort));
|
||||
ConsulRegistration registration = ConsulRegistration.lifecycleRegistration(service.getPort(), this.properties, getContext(), this.servletContext, this.ttlConfig);
|
||||
if (registration.getService().getPort() == null) { // not set by properties
|
||||
registration.initializePort(service.getPort());
|
||||
}
|
||||
this.service = registration.getService();
|
||||
|
||||
register(service);
|
||||
}
|
||||
|
||||
private NewService.Check createCheck(Integer port) {
|
||||
NewService.Check check = new NewService.Check();
|
||||
if (ttlConfig.isEnabled()) {
|
||||
check.setTtl(ttlConfig.getTtl());
|
||||
return check;
|
||||
}
|
||||
|
||||
if (properties.getHealthCheckUrl() != null) {
|
||||
check.setHttp(properties.getHealthCheckUrl());
|
||||
} else {
|
||||
check.setHttp(String.format("%s://%s:%s%s", properties.getScheme(),
|
||||
properties.getHostname(), port,
|
||||
properties.getHealthCheckPath()));
|
||||
}
|
||||
check.setInterval(properties.getHealthCheckInterval());
|
||||
check.setTimeout(properties.getHealthCheckTimeout());
|
||||
return check;
|
||||
return ConsulRegistration.createCheck(port, this.ttlConfig, this.properties);
|
||||
}
|
||||
|
||||
public String getServiceId() {
|
||||
// cache instanceId, so on refresh this won't get recomputed
|
||||
// this is a problem if ${random.value} is used
|
||||
if (this.instanceId == null) {
|
||||
if (!StringUtils.hasText(properties.getInstanceId())) {
|
||||
this.instanceId = normalizeForDns(getContext().getId());
|
||||
} else {
|
||||
this.instanceId = normalizeForDns(properties.getInstanceId());
|
||||
}
|
||||
this.instanceId = ConsulRegistration.getServiceId(properties, getContext());
|
||||
}
|
||||
return this.instanceId;
|
||||
}
|
||||
@@ -160,15 +136,10 @@ public class ConsulLifecycle extends AbstractDiscoveryLifecycle {
|
||||
if (!this.properties.isRegister()) {
|
||||
return;
|
||||
}
|
||||
NewService management = new NewService();
|
||||
management.setId(getManagementServiceId());
|
||||
management.setAddress(properties.getHostname());
|
||||
management.setName(getManagementServiceName());
|
||||
management.setPort(getManagementPort());
|
||||
management.setTags(properties.getManagementTags());
|
||||
management.setCheck(createCheck(getManagementPort()));
|
||||
|
||||
register(management);
|
||||
ConsulRegistration registration = ConsulRegistration.managementRegistration(this.properties, getContext(), this.ttlConfig);
|
||||
|
||||
register(registration.getService());
|
||||
}
|
||||
|
||||
protected void register(NewService newService) {
|
||||
@@ -204,19 +175,7 @@ public class ConsulLifecycle extends AbstractDiscoveryLifecycle {
|
||||
}
|
||||
|
||||
private List<String> createTags() {
|
||||
List<String> tags = new LinkedList<>(properties.getTags());
|
||||
if(servletContext != null
|
||||
&& StringUtils.hasText(servletContext.getContextPath())
|
||||
&& StringUtils.hasText(servletContext.getContextPath().replaceAll("/", ""))) {
|
||||
tags.add("contextPath=" + servletContext.getContextPath());
|
||||
}
|
||||
if (!StringUtils.isEmpty(properties.getInstanceZone())) {
|
||||
tags.add(properties.getDefaultZoneMetadataName() + "=" + properties.getInstanceZone());
|
||||
}
|
||||
if (!StringUtils.isEmpty(properties.getInstanceGroup())) {
|
||||
tags.add("group=" + properties.getInstanceGroup());
|
||||
}
|
||||
return tags;
|
||||
return ConsulRegistration.createTags(this.properties, this.servletContext);
|
||||
}
|
||||
|
||||
private void deregister(String serviceId) {
|
||||
@@ -237,56 +196,35 @@ public class ConsulLifecycle extends AbstractDiscoveryLifecycle {
|
||||
|
||||
@Override
|
||||
protected String getAppName() {
|
||||
String appName = properties.getServiceName();
|
||||
return StringUtils.isEmpty(appName) ? super.getAppName() : appName;
|
||||
return ConsulRegistration.getAppName(this.properties, this.propertyResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the serviceId of the Management Service
|
||||
*/
|
||||
public String getManagementServiceId() {
|
||||
return normalizeForDns(getContext().getId()) + SEPARATOR + properties.getManagementSuffix();
|
||||
return ConsulRegistration.normalizeForDns(getContext().getId()) + SEPARATOR + properties.getManagementSuffix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the service name of the Management Service
|
||||
*/
|
||||
public String getManagementServiceName() {
|
||||
return normalizeForDns(getAppName()) + SEPARATOR + properties.getManagementSuffix();
|
||||
return ConsulRegistration.normalizeForDns(getAppName()) + SEPARATOR + properties.getManagementSuffix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the port of the Management Service
|
||||
*/
|
||||
protected Integer getManagementPort() {
|
||||
// If an alternate external port is specified, use it instead
|
||||
if (properties.getManagementPort() != null) {
|
||||
return properties.getManagementPort();
|
||||
}
|
||||
return super.getManagementPort();
|
||||
return ConsulRegistration.getManagementPort(this.properties, getContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated See {@link org.springframework.cloud.consul.serviceregistry.ConsulRegistration#normalizeForDns(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static String normalizeForDns(String s) {
|
||||
if (s == null || !Character.isLetter(s.charAt(0))
|
||||
|| !Character.isLetterOrDigit(s.charAt(s.length()-1))) {
|
||||
throw new IllegalArgumentException("Consul service ids must not be empty, must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen");
|
||||
}
|
||||
|
||||
StringBuilder normalized = new StringBuilder();
|
||||
Character prev = null;
|
||||
for (char curr : s.toCharArray()) {
|
||||
Character toAppend = null;
|
||||
if (Character.isLetterOrDigit(curr)) {
|
||||
toAppend = curr;
|
||||
} else if (prev == null || !(prev == SEPARATOR)) {
|
||||
toAppend = SEPARATOR;
|
||||
}
|
||||
if (toAppend != null) {
|
||||
normalized.append(toAppend);
|
||||
prev = toAppend;
|
||||
}
|
||||
}
|
||||
|
||||
return normalized.toString();
|
||||
return ConsulRegistration.normalizeForDns(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.discovery;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Configuration
|
||||
public class TestConsulLifecycleConfiguration {
|
||||
@Autowired(required = false)
|
||||
private ServerProperties serverProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private TtlScheduler ttlScheduler;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ServletContext servletContext;
|
||||
|
||||
@Bean
|
||||
public ConsulLifecycle consulLifecycle(ConsulClient consulClient, ConsulDiscoveryProperties discoveryProperties,
|
||||
HeartbeatProperties heartbeatProperties) {
|
||||
ConsulLifecycle lifecycle = new ConsulLifecycle(consulClient, discoveryProperties, heartbeatProperties);
|
||||
if (this.ttlScheduler != null) {
|
||||
lifecycle.setTtlScheduler(this.ttlScheduler);
|
||||
}
|
||||
if (this.servletContext != null) {
|
||||
lifecycle.setServletContext(this.servletContext);
|
||||
}
|
||||
if (this.serverProperties != null && this.serverProperties.getPort() != null && this.serverProperties.getPort() > 0) {
|
||||
// no need to wait for events for this to start since the user has explicitly set the port.
|
||||
lifecycle.setPort(this.serverProperties.getPort());
|
||||
}
|
||||
return lifecycle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.retry.annotation.Retryable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class ConsulAutoServiceRegistration extends AbstractAutoServiceRegistration<ConsulRegistration> {
|
||||
|
||||
private static Log log = LogFactory.getLog(ConsulAutoServiceRegistration.class);
|
||||
|
||||
private ConsulDiscoveryProperties properties;
|
||||
private ConsulRegistration registration;
|
||||
|
||||
public ConsulAutoServiceRegistration(ConsulServiceRegistry serviceRegistry, ConsulDiscoveryProperties properties,
|
||||
ConsulRegistration registration) {
|
||||
super(serviceRegistry);
|
||||
this.properties = properties;
|
||||
this.registration = registration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getConfiguredPort() {
|
||||
return this.registration.getService().getPort() == null? 0 : this.registration.getService().getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setConfiguredPort(int port) {
|
||||
this.registration.initializePort(port);
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
getPort().set(port);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConsulRegistration getRegistration() {
|
||||
Assert.notNull(this.registration.getService().getPort(), "service.port has not been set");
|
||||
return this.registration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConsulRegistration getManagementRegistration() {
|
||||
return this.registration.managementRegistration();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Retryable(interceptor = "consulRetryInterceptor")
|
||||
public void start() {
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void register() {
|
||||
if (!this.properties.isRegister()) {
|
||||
log.debug("Registration disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
super.register();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void registerManagement() {
|
||||
if (!this.properties.isRegister()) {
|
||||
return;
|
||||
}
|
||||
super.registerManagement();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getConfiguration() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void deregister() {
|
||||
if (!this.properties.isRegister()) {
|
||||
return;
|
||||
}
|
||||
super.deregister();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void deregisterManagement() {
|
||||
if (!this.properties.isRegister()) {
|
||||
return;
|
||||
}
|
||||
super.deregisterManagement();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled() {
|
||||
return this.properties.getLifecycle().isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAppName() {
|
||||
String appName = properties.getServiceName();
|
||||
return StringUtils.isEmpty(appName) ? super.getAppName() : appName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.cloud.consul.discovery.HeartbeatProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
|
||||
@ConditionalOnMissingBean(type = "org.springframework.cloud.consul.discovery.ConsulLifecycle")
|
||||
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
|
||||
@AutoConfigureAfter(ConsulServiceRegistryAutoConfiguration.class)
|
||||
public class ConsulAutoServiceRegistrationAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulAutoServiceRegistration consulAutoServiceRegistration(ConsulServiceRegistry registry, ConsulDiscoveryProperties properties, ConsulRegistration consulRegistration) {
|
||||
return new ConsulAutoServiceRegistration(registry, properties, consulRegistration);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulRegistration consulRegistration(ConsulDiscoveryProperties properties, ApplicationContext applicationContext,
|
||||
ServletContext servletContext, HeartbeatProperties heartbeatProperties) {
|
||||
return ConsulRegistration.registration(properties, applicationContext, servletContext, heartbeatProperties);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.cloud.client.discovery.ManagementServerPortUtils;
|
||||
import org.springframework.cloud.client.serviceregistry.Registration;
|
||||
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.cloud.consul.discovery.HeartbeatProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecwid.consul.v1.agent.model.NewService;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class ConsulRegistration implements Registration {
|
||||
|
||||
public static final char SEPARATOR = '-';
|
||||
|
||||
private final NewService service;
|
||||
private final ConsulDiscoveryProperties properties;
|
||||
private final ApplicationContext context;
|
||||
private final HeartbeatProperties heartbeatProperties;
|
||||
private String instanceId;
|
||||
|
||||
public ConsulRegistration(NewService service, ConsulDiscoveryProperties properties, ApplicationContext context, HeartbeatProperties heartbeatProperties) {
|
||||
this.service = service;
|
||||
this.properties = properties;
|
||||
this.context = context;
|
||||
this.heartbeatProperties = heartbeatProperties;
|
||||
|
||||
// cache instanceId, so on refresh this won't get recomputed
|
||||
// this is a problem if ${random.value} is used
|
||||
this.instanceId = ConsulRegistration.getServiceId(properties, context);
|
||||
}
|
||||
|
||||
public String getInstanceId() {
|
||||
return this.instanceId;
|
||||
}
|
||||
|
||||
public void initializePort(int knownPort) {
|
||||
if (getService().getPort() == null) {
|
||||
// not set by properties
|
||||
getService().setPort(knownPort);
|
||||
}
|
||||
// we might not have a port until now, so this is the earliest we
|
||||
// can create a check
|
||||
|
||||
setCheck(this.service, this.properties, this.context, this.heartbeatProperties);
|
||||
}
|
||||
|
||||
public ConsulRegistration managementRegistration() {
|
||||
return managementRegistration(this.properties, this.context, this.heartbeatProperties);
|
||||
}
|
||||
|
||||
public static ConsulRegistration registration(ConsulDiscoveryProperties properties, ApplicationContext context,
|
||||
ServletContext servletContext, HeartbeatProperties heartbeatProperties) {
|
||||
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(context.getEnvironment());
|
||||
|
||||
NewService service = new NewService();
|
||||
String appName = getAppName(properties, propertyResolver);
|
||||
service.setId(getServiceId(properties, context));
|
||||
if(!properties.isPreferAgentAddress()) {
|
||||
service.setAddress(properties.getHostname());
|
||||
}
|
||||
service.setName(normalizeForDns(appName));
|
||||
service.setTags(createTags(properties, servletContext));
|
||||
|
||||
if (properties.getPort() != null) {
|
||||
service.setPort(properties.getPort());
|
||||
}
|
||||
|
||||
return new ConsulRegistration(service, properties, context, heartbeatProperties);
|
||||
}
|
||||
|
||||
@Deprecated //TODO: do I need this here, or should I just copy what I need back into lifecycle?
|
||||
public static ConsulRegistration lifecycleRegistration(Integer port, ConsulDiscoveryProperties properties, ApplicationContext context,
|
||||
ServletContext servletContext, HeartbeatProperties heartbeatProperties) {
|
||||
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(context.getEnvironment());
|
||||
|
||||
NewService service = new NewService();
|
||||
String appName = getAppName(properties, propertyResolver);
|
||||
service.setId(getServiceId(properties, context));
|
||||
if(!properties.isPreferAgentAddress()) {
|
||||
service.setAddress(properties.getHostname());
|
||||
}
|
||||
service.setName(normalizeForDns(appName));
|
||||
service.setTags(createTags(properties, servletContext));
|
||||
|
||||
// If an alternate external port is specified, register using it instead
|
||||
if (properties.getPort() != null) {
|
||||
service.setPort(properties.getPort());
|
||||
} else {
|
||||
service.setPort(port);
|
||||
}
|
||||
|
||||
Assert.notNull(service.getPort(), "service.port may not be null");
|
||||
|
||||
setCheck(service, properties, context, heartbeatProperties);
|
||||
|
||||
return new ConsulRegistration(service, properties, context, heartbeatProperties);
|
||||
}
|
||||
|
||||
public static void setCheck(NewService service, ConsulDiscoveryProperties properties, ApplicationContext context, HeartbeatProperties heartbeatProperties) {
|
||||
if (properties.isRegisterHealthCheck()) {
|
||||
Integer checkPort;
|
||||
if (shouldRegisterManagement(properties, context)) {
|
||||
checkPort = getManagementPort(properties, context);
|
||||
} else {
|
||||
checkPort = service.getPort();
|
||||
}
|
||||
Assert.notNull(checkPort, "checkPort may not be null");
|
||||
service.setCheck(createCheck(checkPort, heartbeatProperties, properties));
|
||||
}
|
||||
}
|
||||
|
||||
public static ConsulRegistration managementRegistration(ConsulDiscoveryProperties properties, ApplicationContext context,
|
||||
HeartbeatProperties heartbeatProperties) {
|
||||
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(context.getEnvironment());
|
||||
NewService management = new NewService();
|
||||
management.setId(getManagementServiceId(properties, context));
|
||||
management.setAddress(properties.getHostname());
|
||||
management.setName(getManagementServiceName(properties, propertyResolver));
|
||||
management.setPort(getManagementPort(properties, context));
|
||||
management.setTags(properties.getManagementTags());
|
||||
if (properties.isRegisterHealthCheck()) {
|
||||
management.setCheck(createCheck(getManagementPort(properties, context), heartbeatProperties, properties));
|
||||
}
|
||||
return new ConsulRegistration(management, properties, context, heartbeatProperties);
|
||||
}
|
||||
|
||||
public String getServiceId() {
|
||||
return this.service.getId();
|
||||
}
|
||||
|
||||
public static String getServiceId(ConsulDiscoveryProperties properties, ApplicationContext context) {
|
||||
if (!StringUtils.hasText(properties.getInstanceId())) {
|
||||
return normalizeForDns(context.getId());
|
||||
} else {
|
||||
return normalizeForDns(properties.getInstanceId());
|
||||
}
|
||||
}
|
||||
|
||||
public static String normalizeForDns(String s) {
|
||||
if (s == null || !Character.isLetter(s.charAt(0))
|
||||
|| !Character.isLetterOrDigit(s.charAt(s.length()-1))) {
|
||||
throw new IllegalArgumentException("Consul service ids must not be empty, must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen");
|
||||
}
|
||||
|
||||
StringBuilder normalized = new StringBuilder();
|
||||
Character prev = null;
|
||||
for (char curr : s.toCharArray()) {
|
||||
Character toAppend = null;
|
||||
if (Character.isLetterOrDigit(curr)) {
|
||||
toAppend = curr;
|
||||
} else if (prev == null || !(prev == SEPARATOR)) {
|
||||
toAppend = SEPARATOR;
|
||||
}
|
||||
if (toAppend != null) {
|
||||
normalized.append(toAppend);
|
||||
prev = toAppend;
|
||||
}
|
||||
}
|
||||
|
||||
return normalized.toString();
|
||||
}
|
||||
|
||||
|
||||
public static List<String> createTags(ConsulDiscoveryProperties properties, ServletContext servletContext) {
|
||||
List<String> tags = new LinkedList<>(properties.getTags());
|
||||
if(servletContext != null
|
||||
&& StringUtils.hasText(servletContext.getContextPath())
|
||||
&& StringUtils.hasText(servletContext.getContextPath().replaceAll("/", ""))) {
|
||||
tags.add("contextPath=" + servletContext.getContextPath());
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
public static NewService.Check createCheck(Integer port, HeartbeatProperties ttlConfig,
|
||||
ConsulDiscoveryProperties properties) {
|
||||
NewService.Check check = new NewService.Check();
|
||||
if (ttlConfig.isEnabled()) {
|
||||
check.setTtl(ttlConfig.getTtl());
|
||||
return check;
|
||||
}
|
||||
|
||||
Assert.notNull(port, "createCheck port must not be null");
|
||||
Assert.isTrue(port > 0, "createCheck port must be greater than 0");
|
||||
|
||||
if (properties.getHealthCheckUrl() != null) {
|
||||
check.setHttp(properties.getHealthCheckUrl());
|
||||
} else {
|
||||
check.setHttp(String.format("%s://%s:%s%s", properties.getScheme(),
|
||||
properties.getHostname(), port,
|
||||
properties.getHealthCheckPath()));
|
||||
}
|
||||
check.setInterval(properties.getHealthCheckInterval());
|
||||
check.setTimeout(properties.getHealthCheckTimeout());
|
||||
return check;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the app name, currently the spring.application.name property
|
||||
*/
|
||||
public static String getAppName(ConsulDiscoveryProperties properties, RelaxedPropertyResolver propertyResolver) {
|
||||
String appName = properties.getServiceName();
|
||||
if (!StringUtils.isEmpty(appName)) {
|
||||
return appName;
|
||||
}
|
||||
return propertyResolver.getProperty("spring.application.name", "application");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the management service should be registered with the {@link ServiceRegistry}
|
||||
*/
|
||||
public static boolean shouldRegisterManagement(ConsulDiscoveryProperties properties, ApplicationContext context) {
|
||||
return getManagementPort(properties, context) != null && ManagementServerPortUtils.isDifferent(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the serviceId of the Management Service
|
||||
*/
|
||||
public static String getManagementServiceId(ConsulDiscoveryProperties properties, ApplicationContext context) {
|
||||
return normalizeForDns(context.getId()) + SEPARATOR + properties.getManagementSuffix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the service name of the Management Service
|
||||
*/
|
||||
public static String getManagementServiceName(ConsulDiscoveryProperties properties, RelaxedPropertyResolver propertyResolver) {
|
||||
return normalizeForDns(getAppName(properties, propertyResolver)) + SEPARATOR + properties.getManagementSuffix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the port of the Management Service
|
||||
*/
|
||||
public static Integer getManagementPort(ConsulDiscoveryProperties properties, ApplicationContext context) {
|
||||
// If an alternate external port is specified, use it instead
|
||||
if (properties.getManagementPort() != null) {
|
||||
return properties.getManagementPort();
|
||||
}
|
||||
return ManagementServerPortUtils.getPort(context);
|
||||
}
|
||||
|
||||
public NewService getService() {
|
||||
return service;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import com.ecwid.consul.ConsulException;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.cloud.consul.discovery.HeartbeatProperties;
|
||||
import org.springframework.cloud.consul.discovery.TtlScheduler;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class ConsulServiceRegistry implements ServiceRegistry<ConsulRegistration> {
|
||||
|
||||
private static Log log = LogFactory.getLog(ConsulServiceRegistry.class);
|
||||
|
||||
private final ConsulClient client;
|
||||
|
||||
private final ConsulDiscoveryProperties properties;
|
||||
|
||||
private final TtlScheduler ttlScheduler;
|
||||
|
||||
private final HeartbeatProperties heartbeatProperties;
|
||||
|
||||
public ConsulServiceRegistry(ConsulClient client, ConsulDiscoveryProperties properties, TtlScheduler ttlScheduler, HeartbeatProperties heartbeatProperties) {
|
||||
this.client = client;
|
||||
this.properties = properties;
|
||||
this.ttlScheduler = ttlScheduler;
|
||||
this.heartbeatProperties = heartbeatProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ConsulRegistration reg) {
|
||||
log.info("Registering service with consul: " + reg.getService());
|
||||
try {
|
||||
client.agentServiceRegister(reg.getService(), properties.getAclToken());
|
||||
if (heartbeatProperties.isEnabled() && ttlScheduler != null) {
|
||||
ttlScheduler.add(reg.getService());
|
||||
}
|
||||
}
|
||||
catch (ConsulException e) {
|
||||
if (this.properties.isFailFast()) {
|
||||
log.error("Error registering service with consul: " + reg.getService(), e);
|
||||
ReflectionUtils.rethrowRuntimeException(e);
|
||||
}
|
||||
log.warn("Failfast is false. Error registering service with consul: " + reg.getService(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deregister(ConsulRegistration reg) {
|
||||
if (ttlScheduler != null) {
|
||||
ttlScheduler.remove(reg.getServiceId());
|
||||
}
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("Deregistering service with consul: " + reg.getServiceId());
|
||||
}
|
||||
client.agentServiceDeregister(reg.getServiceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(ConsulRegistration registration, String status) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getStatus(ConsulRegistration registration) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.cloud.consul.discovery.HeartbeatProperties;
|
||||
import org.springframework.cloud.consul.discovery.TtlScheduler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value = "spring.cloud.service-registry.enabled", matchIfMissing = true)
|
||||
public class ConsulServiceRegistryAutoConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
private TtlScheduler ttlScheduler;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulServiceRegistry consulServiceRegistry(ConsulClient consulClient, ConsulDiscoveryProperties properties,
|
||||
HeartbeatProperties heartbeatProperties) {
|
||||
return new ConsulServiceRegistry(consulClient, properties, ttlScheduler, heartbeatProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty("spring.cloud.consul.discovery.heartbeat.enabled")
|
||||
public TtlScheduler ttlScheduler(ConsulClient consulClient, HeartbeatProperties heartbeatProperties) {
|
||||
return new TtlScheduler(heartbeatProperties, consulClient);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public HeartbeatProperties heartbeatProperties() {
|
||||
return new HeartbeatProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ConsulDiscoveryProperties consulDiscoveryProperties(InetUtils inetUtils) {
|
||||
return new ConsulDiscoveryProperties(inetUtils);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.consul.discovery.RibbonConsulAutoConfiguration,\
|
||||
org.springframework.cloud.consul.discovery.configclient.ConsulConfigServerAutoConfiguration
|
||||
org.springframework.cloud.consul.discovery.configclient.ConsulConfigServerAutoConfiguration,\
|
||||
org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistrationAutoConfiguration,\
|
||||
org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistryAutoConfiguration
|
||||
|
||||
# Discovery Client Configuration
|
||||
org.springframework.cloud.client.discovery.EnableDiscoveryClient=\
|
||||
|
||||
@@ -22,26 +22,27 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = ConsulDiscoveryClientAclTests.MyTestConfig.class)
|
||||
@WebIntegrationTest(value = {"spring.application.name=testConsulDiscoveryAcl",
|
||||
"spring.cloud.consul.discovery.preferIpAddress=true",
|
||||
"consul.token=2d2e6b3b-1c82-40ab-8171-54609d8ad304"}, randomPort = true)
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConsulDiscoveryClientAclTests.MyTestConfig.class,
|
||||
properties = {"spring.application.name=testConsulDiscoveryAcl",
|
||||
"spring.cloud.consul.discovery.preferIpAddress=true",
|
||||
"consul.token=2d2e6b3b-1c82-40ab-8171-54609d8ad304"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulDiscoveryClientAclTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -45,6 +45,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
properties = { "spring.application.name=testConsulDiscovery2",
|
||||
"spring.cloud.consul.discovery.instanceId=testConsulDiscovery2Id",
|
||||
"spring.cloud.consul.discovery.hostname=testConsulDiscovery2Host",
|
||||
"spring.cloud.consul.discovery.registerHealthCheck=false",
|
||||
"spring.cloud.consul.discovery.tags=plaintag,foo=bar,foo2=bar2=baz2" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulDiscoveryClientCustomizedTests {
|
||||
|
||||
@@ -19,29 +19,29 @@ package org.springframework.cloud.consul.discovery;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.ecwid.consul.transport.RawResponse;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Member;
|
||||
import com.ecwid.consul.v1.agent.model.Self;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.MOCK;
|
||||
import com.ecwid.consul.transport.RawResponse;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Member;
|
||||
import com.ecwid.consul.v1.agent.model.Self;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.MOCK;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -142,14 +142,14 @@ public class ConsulDiscoveryClientLocalServiceInstanceTests {
|
||||
given(this.lifecycle.getConfiguredPort()).willReturn(port);
|
||||
given(this.properties.getTags()).willReturn(Arrays.asList(TAG));
|
||||
given(this.properties.getHostname()).willReturn(address);
|
||||
given(this.properties.getLifecycle()).willReturn(new ConsulDiscoveryProperties.Lifecycle());
|
||||
|
||||
given(this.consul.getAgentServices()).willReturn(new Response<>(Collections.<String, Service>emptyMap(), RAW_RESPONSE));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableDiscoveryClient
|
||||
@EnableAutoConfiguration
|
||||
@Import({ ConsulDiscoveryClientConfiguration.class })
|
||||
@ImportAutoConfiguration({ ConsulDiscoveryClientConfiguration.class })
|
||||
protected static class LocalServiceTestConfig {
|
||||
|
||||
}
|
||||
|
||||
@@ -16,37 +16,38 @@
|
||||
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @deprecated remove in Edgware
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@SpringApplicationConfiguration(classes = TestPropsConfig.class)
|
||||
@WebIntegrationTest(value = { "spring.application.name=myTestService-A",
|
||||
@Deprecated
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestPropsConfig.class,
|
||||
properties = { "spring.application.name=myTestService-A",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-A",
|
||||
"spring.cloud.consul.discovery.serviceName=myprefix-${spring.application.name}",
|
||||
"spring.cloud.consul.discovery.preferAgentAddress=true"}, randomPort = true)
|
||||
"spring.cloud.consul.discovery.preferAgentAddress=true"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulLifecycleCustomizedAgentAddressTests {
|
||||
|
||||
@Autowired
|
||||
@@ -72,4 +73,4 @@ public class ConsulLifecycleCustomizedAgentAddressTests {
|
||||
assertEquals("service name was wrong", "myprefix-myTestService-A", service.getService());
|
||||
assertTrue("service address must be empty", StringUtils.isEmpty(service.getAddress()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Aleksandr Tarasov (aatarasov)
|
||||
* @author Alex Antonov (aantonov)
|
||||
* @deprecated remove in Edgware
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@SpringApplicationConfiguration(classes = TestConfig.class)
|
||||
@WebIntegrationTest(value = {"spring.application.name=myTestService-G",
|
||||
@Deprecated
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfig.class,
|
||||
properties = {"spring.application.name=myTestService-G",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-G",
|
||||
"spring.cloud.consul.discovery.managementPort=4452", "management.port=0"}, randomPort = true)
|
||||
"spring.cloud.consul.discovery.registerHealthCheck=false",
|
||||
"spring.cloud.consul.discovery.managementPort=4452", "management.port=0"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulLifecycleCustomizedManagementServicePortTests {
|
||||
@Autowired
|
||||
ConsulLifecycle lifecycle;
|
||||
@@ -59,11 +59,4 @@ public class ConsulLifecycleCustomizedManagementServicePortTests {
|
||||
assertEquals("service address must equals hostname from discovery properties", discoveryProperties.getHostname(), service.getAddress());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@Import({ConsulAutoConfiguration.class,
|
||||
ConsulDiscoveryClientConfiguration.class})
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,27 +16,25 @@
|
||||
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.QueryParams;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import com.ecwid.consul.v1.health.model.Check;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
@@ -44,21 +42,24 @@ import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Venil Noronha
|
||||
* @deprecated remove in Edgware
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@SpringApplicationConfiguration(classes = TestPropsConfig.class)
|
||||
@WebIntegrationTest(value = { "spring.application.name=myTestService-B",
|
||||
@Deprecated
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestPropsConfig.class,
|
||||
properties = { "spring.application.name=myTestService-B",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-B",
|
||||
"spring.cloud.consul.discovery.port=4452",
|
||||
"spring.cloud.consul.discovery.hostname=myhost",
|
||||
"spring.cloud.consul.discovery.ipAddress=10.0.0.1",
|
||||
"spring.cloud.consul.discovery.registerHealthCheck=false",
|
||||
"spring.cloud.consul.discovery.failFast=false" }, randomPort = true)
|
||||
"spring.cloud.consul.discovery.failFast=false" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulLifecycleCustomizedPropsTests {
|
||||
|
||||
@Autowired
|
||||
@@ -79,7 +80,7 @@ public class ConsulLifecycleCustomizedPropsTests {
|
||||
Map<String, Service> services = response.getValue();
|
||||
Service service = services.get("myTestService1-B");
|
||||
assertThat("service was null", service, is(notNullValue()));
|
||||
assertThat("service port is discovery port", 4452, equalTo(service.getPort()));
|
||||
assertThat("service port is discovery port", service.getPort(), equalTo(4452));
|
||||
assertThat("service id was wrong", "myTestService1-B", equalTo(service.getId()));
|
||||
assertThat("service name was wrong", "myTestService-B", equalTo(service.getService()));
|
||||
assertThat("property hostname was wrong", "myhost", equalTo(this.properties.getHostname()));
|
||||
@@ -100,7 +101,7 @@ public class ConsulLifecycleCustomizedPropsTests {
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@Import({ ConsulAutoConfiguration.class, ConsulDiscoveryClientConfiguration.class })
|
||||
@ImportAutoConfiguration({ TestConsulLifecycleConfiguration.class, ConsulAutoConfiguration.class, ConsulDiscoveryClientConfiguration.class })
|
||||
class TestPropsConfig {
|
||||
|
||||
}
|
||||
|
||||
@@ -16,34 +16,35 @@
|
||||
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @deprecated remove in Edgware
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@SpringApplicationConfiguration(classes = TestPropsConfig.class)
|
||||
@WebIntegrationTest(value = { "spring.application.name=myTestService-C",
|
||||
@Deprecated
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestPropsConfig.class,
|
||||
properties = { "spring.application.name=myTestService-C",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-C",
|
||||
"spring.cloud.consul.discovery.serviceName=myprefix-${spring.application.name}"}, randomPort = true)
|
||||
"spring.cloud.consul.discovery.serviceName=myprefix-${spring.application.name}"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulLifecycleCustomizedServiceNameTests {
|
||||
|
||||
@Autowired
|
||||
@@ -65,4 +66,4 @@ public class ConsulLifecycleCustomizedServiceNameTests {
|
||||
assertEquals("service id was wrong", "myTestService1-C", service.getId());
|
||||
assertEquals("service name was wrong", "myprefix-myTestService-C", service.getService());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,30 +18,33 @@ package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Marcin Biegan
|
||||
* @deprecated remove in Edgware
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = ConsulLifecycleCustomizedTests.MyTestConfig.class)
|
||||
@WebIntegrationTest(value = { "spring.application.name=testCustomLifecycle", "spring.cloud.consul.discovery.instanceId=foo" }, randomPort = true)
|
||||
@Deprecated
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConsulLifecycleCustomizedTests.MyTestConfig.class,
|
||||
properties = { "spring.application.name=testCustomLifecycle", "spring.cloud.consul.discovery.instanceId=foo" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulLifecycleCustomizedTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -16,29 +16,33 @@
|
||||
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.Map;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @deprecated remove in Edgware
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = TestPropsConfig.class)
|
||||
@WebIntegrationTest(value = { "spring.application.name=myTestService2-D",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService2-D", }, randomPort = true)
|
||||
@Deprecated
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestPropsConfig.class,
|
||||
properties = { "spring.application.name=myTestService2-D",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService2-D", },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulLifecycleDefaultPortTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,36 +1,35 @@
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Aleksandr Tarasov (aatarasov)
|
||||
* @deprecated remove in Edgware
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@SpringApplicationConfiguration(classes = TestConfig.class)
|
||||
@WebIntegrationTest(value = {"spring.application.name=myTestService-E",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-E", "management.port=0"}, randomPort = true)
|
||||
@Deprecated
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfig.class, properties =
|
||||
{"spring.application.name=myTestService-E",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-E",
|
||||
"spring.cloud.consul.discovery.registerHealthCheck=false",
|
||||
"management.port=0"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulLifecycleManagementServiceTests {
|
||||
@Autowired
|
||||
ConsulLifecycle lifecycle;
|
||||
@@ -53,12 +52,4 @@ public class ConsulLifecycleManagementServiceTests {
|
||||
assertFalse("service address must not be empty", StringUtils.isEmpty(service.getAddress()));
|
||||
assertEquals("service address must equals hostname from discovery properties", discoveryProperties.getHostname(), service.getAddress());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@Import({ConsulAutoConfiguration.class,
|
||||
ConsulDiscoveryClientConfiguration.class})
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,29 +18,29 @@ package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @deprecated remove in Edgware
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@SpringApplicationConfiguration(classes = TestPropsConfig.class)
|
||||
@WebIntegrationTest(value = { "spring.application.name=myTestNotRegisteredService",
|
||||
"spring.cloud.consul.discovery.register=false"}, randomPort = true)
|
||||
@Deprecated
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestPropsConfig.class,
|
||||
properties = { "spring.application.name=myTestNotRegisteredService",
|
||||
"spring.cloud.consul.discovery.register=false"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulLifecycleRegistrationDisabledTests {
|
||||
@Autowired
|
||||
private ConsulClient consul;
|
||||
@@ -52,4 +52,4 @@ public class ConsulLifecycleRegistrationDisabledTests {
|
||||
Service service = services.get("myTestNotRegisteredService");
|
||||
assertNull("service was registered", service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,42 +16,46 @@
|
||||
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import com.ecwid.consul.ConsulException;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.NewService;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import com.ecwid.consul.ConsulException;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.NewService;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Venil Noronha
|
||||
* @deprecated remove in Edgware
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@Deprecated
|
||||
@RunWith(SpringRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@SpringApplicationConfiguration(classes = TestConfig.class)
|
||||
@WebIntegrationTest(value = { "spring.application.name=myTestService1-F::something",
|
||||
"spring.cloud.consul.discovery.failFast=true" }, randomPort = true)
|
||||
@SpringBootTest(classes = TestConfig.class,
|
||||
properties = { "spring.application.name=myTestService1-F::something",
|
||||
"spring.cloud.consul.discovery.failFast=true" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulLifecycleTests {
|
||||
|
||||
@Autowired
|
||||
@@ -110,7 +114,7 @@ public class ConsulLifecycleTests {
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@Import({ ConsulAutoConfiguration.class, ConsulDiscoveryClientConfiguration.class })
|
||||
@Import({ TestConsulLifecycleConfiguration.class, ConsulAutoConfiguration.class, ConsulDiscoveryClientConfiguration.class })
|
||||
class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
@@ -2,19 +2,16 @@ package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.QueryParams;
|
||||
@@ -25,17 +22,18 @@ import static com.ecwid.consul.v1.health.model.Check.CheckStatus.CRITICAL;
|
||||
import static com.ecwid.consul.v1.health.model.Check.CheckStatus.PASSING;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Stéphane Leroy
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@SpringApplicationConfiguration(classes = TtlSchedulerRemoveTestConfig.class)
|
||||
@WebIntegrationTest(value = { "spring.application.name=ttlSchedulerRemove",
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TtlSchedulerRemoveTest.TtlSchedulerRemoveTestConfig.class,
|
||||
properties = { "spring.application.name=ttlSchedulerRemove",
|
||||
"spring.cloud.consul.discovery.instanceId=ttlSchedulerRemove-id",
|
||||
"spring.cloud.consul.discovery.heartbeat.enabled=true",
|
||||
"spring.cloud.consul.discovery.heartbeat.ttlValue=2" }, randomPort = true)
|
||||
"spring.cloud.consul.discovery.heartbeat.ttlValue=2" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class TtlSchedulerRemoveTest {
|
||||
|
||||
@Autowired
|
||||
@@ -68,12 +66,10 @@ public class TtlSchedulerRemoveTest {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableDiscoveryClient(autoRegister = false) //FIXME: this is weird because we're testing the deprecated lifecycle, not autoconfiguration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ TestConsulLifecycleConfiguration.class, ConsulAutoConfiguration.class, ConsulDiscoveryClientConfiguration.class })
|
||||
public static class TtlSchedulerRemoveTestConfig { }
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableDiscoveryClient
|
||||
@EnableAutoConfiguration
|
||||
@Import({ ConsulAutoConfiguration.class, ConsulDiscoveryClientConfiguration.class })
|
||||
class TtlSchedulerRemoveTestConfig {
|
||||
|
||||
}
|
||||
|
||||
@@ -2,19 +2,16 @@ package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.QueryParams;
|
||||
@@ -24,17 +21,18 @@ import com.ecwid.consul.v1.health.model.Check;
|
||||
import static com.ecwid.consul.v1.health.model.Check.CheckStatus.PASSING;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Stéphane Leroy
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@SpringApplicationConfiguration(classes = TtlSchedulerTestConfig.class)
|
||||
@WebIntegrationTest(value = { "spring.application.name=ttlScheduler",
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TtlSchedulerTest.TtlSchedulerTestConfig.class,
|
||||
properties = { "spring.application.name=ttlScheduler",
|
||||
"spring.cloud.consul.discovery.instanceId=ttlScheduler-id",
|
||||
"spring.cloud.consul.discovery.heartbeat.enabled=true",
|
||||
"spring.cloud.consul.discovery.heartbeat.ttlValue=2", "management.port=0" }, randomPort = true)
|
||||
"spring.cloud.consul.discovery.heartbeat.ttlValue=2", "management.port=0" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class TtlSchedulerTest {
|
||||
|
||||
@Autowired
|
||||
@@ -62,12 +60,11 @@ public class TtlSchedulerTest {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableDiscoveryClient(autoRegister = false) //FIXME:
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ TestConsulLifecycleConfiguration.class, ConsulAutoConfiguration.class, ConsulDiscoveryClientConfiguration.class })
|
||||
public static class TtlSchedulerTestConfig { }
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableDiscoveryClient
|
||||
@EnableAutoConfiguration
|
||||
@Import({ ConsulAutoConfiguration.class, ConsulDiscoveryClientConfiguration.class })
|
||||
class TtlSchedulerTestConfig {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConsulAutoServiceRegistrationCustomizedAgentAddressTests.TestConfig.class,
|
||||
properties = { "spring.application.name=myTestService-AA",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-AA",
|
||||
"spring.cloud.consul.discovery.serviceName=myprefix-${spring.application.name}",
|
||||
"spring.cloud.consul.discovery.preferAgentAddress=true"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulAutoServiceRegistrationCustomizedAgentAddressTests {
|
||||
|
||||
@Autowired
|
||||
ConsulClient consul;
|
||||
|
||||
@Autowired
|
||||
ConsulDiscoveryProperties discoveryProperties;
|
||||
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
Response<Map<String, Service>> response = consul.getAgentServices();
|
||||
Map<String, Service> services = response.getValue();
|
||||
Service service = services.get("myTestService1-AA");
|
||||
assertNotNull("service was null", service);
|
||||
assertNotEquals("service port is 0", 0, service.getPort().intValue());
|
||||
assertEquals("service id was wrong", "myTestService1-AA", service.getId());
|
||||
assertEquals("service name was wrong", "myprefix-myTestService-AA", service.getService());
|
||||
assertTrue("service address must be empty", StringUtils.isEmpty(service.getAddress()));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class, ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
public static class TestConfig { }
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Aleksandr Tarasov (aatarasov)
|
||||
* @author Alex Antonov (aantonov)
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConsulAutoServiceRegistrationCustomizedManagementServicePortTests.TestConfig.class,
|
||||
properties = {"spring.application.name=myTestService-GG",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-GG",
|
||||
"spring.cloud.consul.discovery.registerHealthCheck=false",
|
||||
"spring.cloud.consul.discovery.managementPort=4452", "management.port=0"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulAutoServiceRegistrationCustomizedManagementServicePortTests {
|
||||
@Autowired
|
||||
ConsulClient consul;
|
||||
|
||||
@Autowired
|
||||
ConsulDiscoveryProperties discoveryProperties;
|
||||
|
||||
@Autowired
|
||||
ManagementServerProperties managementServerProperties;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
Response<Map<String, Service>> response = consul.getAgentServices();
|
||||
Map<String, Service> services = response.getValue();
|
||||
Service service = services.get("myTestService-GG-0-management");
|
||||
assertNotNull("service was null", service);
|
||||
assertEquals("service port is not 4452", 4452, service.getPort().intValue());
|
||||
assertEquals("management port is not 0", 0, managementServerProperties.getPort().intValue());
|
||||
assertEquals("service id was wrong", "myTestService-GG-0-management", service.getId());
|
||||
assertEquals("service name was wrong", "myTestService-GG-management", service.getService());
|
||||
assertFalse("service address must not be empty", StringUtils.isEmpty(service.getAddress()));
|
||||
assertEquals("service address must equals hostname from discovery properties", discoveryProperties.getHostname(), service.getAddress());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class, ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
public static class TestConfig { }
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.QueryParams;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
import com.ecwid.consul.v1.health.model.Check;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Venil Noronha
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConsulAutoServiceRegistrationCustomizedPropsTests.TestPropsConfig.class,
|
||||
properties = { "spring.application.name=myTestService-B",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-B",
|
||||
"spring.cloud.consul.discovery.port=4452",
|
||||
"spring.cloud.consul.discovery.hostname=myhost",
|
||||
"spring.cloud.consul.discovery.ipAddress=10.0.0.1",
|
||||
"spring.cloud.consul.discovery.registerHealthCheck=false",
|
||||
"spring.cloud.consul.discovery.failFast=false" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulAutoServiceRegistrationCustomizedPropsTests {
|
||||
|
||||
@Autowired
|
||||
ConsulClient consul;
|
||||
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
ConsulDiscoveryProperties properties;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
Response<Map<String, Service>> response = consul.getAgentServices();
|
||||
Map<String, Service> services = response.getValue();
|
||||
Service service = services.get("myTestService1-B");
|
||||
assertThat("service was null", service, is(notNullValue()));
|
||||
assertThat("service port is discovery port", service.getPort(), equalTo(4452));
|
||||
assertThat("service id was wrong", "myTestService1-B", equalTo(service.getId()));
|
||||
assertThat("service name was wrong", "myTestService-B", equalTo(service.getService()));
|
||||
assertThat("property hostname was wrong", "myhost", equalTo(this.properties.getHostname()));
|
||||
assertThat("property ipAddress was wrong", "10.0.0.1", equalTo(this.properties.getIpAddress()));
|
||||
assertThat("service address was wrong", "myhost", equalTo(service.getAddress()));
|
||||
|
||||
Response<List<Check>> checkResponse = consul.getHealthChecksForService("myTestService-B", QueryParams.DEFAULT);
|
||||
List<Check> checks = checkResponse.getValue();
|
||||
assertThat("checks was wrong size", checks, hasSize(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailFastDisabled() {
|
||||
assertFalse("property failFast was wrong", this.properties.isFailFast());
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class, ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
public static class TestPropsConfig { }
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConsulAutoServiceRegistrationCustomizedServiceNameTests.TestConfig.class,
|
||||
properties = { "spring.application.name=myTestService-CC",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-CC",
|
||||
"spring.cloud.consul.discovery.serviceName=myprefix-${spring.application.name}"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulAutoServiceRegistrationCustomizedServiceNameTests {
|
||||
@Autowired
|
||||
ConsulClient consul;
|
||||
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
Response<Map<String, Service>> response = consul.getAgentServices();
|
||||
Map<String, Service> services = response.getValue();
|
||||
Service service = services.get("myTestService1-CC");
|
||||
assertNotNull("service was null", service);
|
||||
assertNotEquals("service port is 0", 0, service.getPort().intValue());
|
||||
assertEquals("service id was wrong", "myTestService1-CC", service.getId());
|
||||
assertEquals("service name was wrong", "myprefix-myTestService-CC", service.getService());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class, ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
public static class TestConfig { }
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Marcin Biegan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConsulAutoServiceRegistrationCustomizedTests.MyTestConfig.class,
|
||||
properties = { "spring.application.name=testCustomAutoServiceRegistration"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulAutoServiceRegistrationCustomizedTests {
|
||||
|
||||
@Autowired
|
||||
private ConsulAutoServiceRegistration registration1;
|
||||
|
||||
@Autowired
|
||||
private CustomAutoRegistration registration2;
|
||||
|
||||
@Test
|
||||
public void usesCustomConsulLifecycle() {
|
||||
assertEquals("configuration is not customized", "customconfiguration", registration1.getConfiguration());
|
||||
assertEquals("configuration is not customized", "customconfiguration", registration2.getConfiguration());
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class, ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
public static class MyTestConfig {
|
||||
@Bean
|
||||
public CustomAutoRegistration consulAutoServiceRegistration(ConsulServiceRegistry serviceRegistry, ConsulDiscoveryProperties properties,
|
||||
ConsulRegistration registration) {
|
||||
return new CustomAutoRegistration(serviceRegistry, properties, registration);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomAutoRegistration extends ConsulAutoServiceRegistration {
|
||||
|
||||
@Autowired
|
||||
public CustomAutoRegistration(ConsulServiceRegistry serviceRegistry, ConsulDiscoveryProperties properties,
|
||||
ConsulRegistration registration) {
|
||||
super(serviceRegistry, properties, registration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getConfiguration() {
|
||||
return "customconfiguration";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConsulAutoServiceRegistrationDefaultPortTests.TestConfig.class,
|
||||
properties = { "spring.application.name=myTestService2-DD",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService2-DD", },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulAutoServiceRegistrationDefaultPortTests {
|
||||
|
||||
@Autowired
|
||||
ConsulClient consul;
|
||||
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
Response<Map<String, Service>> response = consul.getAgentServices();
|
||||
Map<String, Service> services = response.getValue();
|
||||
Service service = services.get("myTestService2-DD");
|
||||
assertNotNull("service was null", service);
|
||||
assertNotEquals("service port is 0", 0, service.getPort().intValue());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class, ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
public static class TestConfig { }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConsulAutoServiceRegistrationDisabledTests.TestConfig.class,
|
||||
properties = { "spring.application.name=myTestNotRegisteredService2",
|
||||
"spring.cloud.service-registry.auto-registration.enabled=false"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulAutoServiceRegistrationDisabledTests {
|
||||
@Autowired
|
||||
private ConsulClient consul;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ConsulAutoServiceRegistration autoServiceRegistration;
|
||||
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
assertNull("ConsulAutoServiceRegistration was created", autoServiceRegistration);
|
||||
|
||||
Response<Map<String, Service>> response = consul.getAgentServices();
|
||||
Map<String, Service> services = response.getValue();
|
||||
Service service = services.get("myTestNotRegisteredService2");
|
||||
assertNull("service was registered", service);
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class,
|
||||
ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
public static class TestConfig { }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import com.ecwid.consul.ConsulException;
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Venil Noronha
|
||||
*/
|
||||
public class ConsulAutoServiceRegistrationFailFastTests {
|
||||
|
||||
@Test(expected = ConsulException.class)
|
||||
public void testFailFastEnabled() {
|
||||
new SpringApplicationBuilder(TestConfig.class).properties("server.port=0", "spring.cloud.consul.discovery.failFast=true").run();
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class, ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
protected static class TestConfig {
|
||||
|
||||
@Bean
|
||||
public ConsulClient consulClient() {
|
||||
return new ConsulClient("localhost", 4321);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Aleksandr Tarasov (aatarasov)
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConsulAutoServiceRegistrationManagementServiceTests.TestConfig.class, properties =
|
||||
{"spring.application.name=myTestService-EE",
|
||||
"spring.cloud.consul.discovery.instanceId=myTestService1-EE",
|
||||
"spring.cloud.consul.discovery.registerHealthCheck=false",
|
||||
"management.port=0"},
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulAutoServiceRegistrationManagementServiceTests {
|
||||
@Autowired
|
||||
ConsulClient consul;
|
||||
|
||||
@Autowired
|
||||
ConsulDiscoveryProperties discoveryProperties;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
Response<Map<String, Service>> response = consul.getAgentServices();
|
||||
Map<String, Service> services = response.getValue();
|
||||
Service service = services.get("myTestService-EE-0-management");
|
||||
assertNotNull("service was null", service);
|
||||
assertEquals("service port is not 0", 0, service.getPort().intValue());
|
||||
assertEquals("service id was wrong", "myTestService-EE-0-management", service.getId());
|
||||
assertEquals("service name was wrong", "myTestService-EE-management", service.getService());
|
||||
assertFalse("service address must not be empty", StringUtils.isEmpty(service.getAddress()));
|
||||
assertEquals("service address must equals hostname from discovery properties", discoveryProperties.getHostname(), service.getAddress());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class, ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
public static class TestConfig { }
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.agent.model.Service;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
import static org.springframework.cloud.consul.serviceregistry.ConsulRegistration.normalizeForDns;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
* @author Venil Noronha
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(properties = { "spring.application.name=myTestService1-FF::something" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulAutoServiceRegistrationTests {
|
||||
|
||||
@Autowired
|
||||
private ConsulAutoServiceRegistration autoRegistration;
|
||||
|
||||
@Autowired
|
||||
private ConsulRegistration registration;
|
||||
|
||||
@Autowired
|
||||
private ConsulClient consul;
|
||||
|
||||
@Autowired
|
||||
private ConsulDiscoveryProperties discoveryProperties;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
Response<Map<String, Service>> response = consul.getAgentServices();
|
||||
Map<String, Service> services = response.getValue();
|
||||
Service service = services.get(registration.getServiceId());
|
||||
assertNotNull("service was null", service);
|
||||
assertNotEquals("service port is 0", 0, service.getPort().intValue());
|
||||
assertFalse("service id contained invalid character: " + service.getId(), service.getId().contains(":"));
|
||||
assertEquals("service id was wrong", registration.getServiceId(), service.getId());
|
||||
assertEquals("service name was wrong", "myTestService1-FF-something", service.getService());
|
||||
assertFalse("service address must not be empty", StringUtils.isEmpty(service.getAddress()));
|
||||
assertEquals("service address must equals hostname from discovery properties", discoveryProperties.getHostname(), service.getAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeForDnsWorks() {
|
||||
assertEquals("abc1", normalizeForDns("abc1"));
|
||||
assertEquals("ab-c1", normalizeForDns("ab:c1"));
|
||||
assertEquals("ab-c1", normalizeForDns("ab::c1"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void normalizedFailsIfFirstCharIsNumber() {
|
||||
normalizeForDns("9abc");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void normalizedFailsIfFirstCharIsNotAlpha() {
|
||||
normalizeForDns(":abc");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void normalizedFailsIfLastCharIsNotAlphaNumeric() {
|
||||
normalizeForDns("abc:");
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class, ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
protected static class TestConfig { }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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
|
||||
*
|
||||
* http://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.consul.serviceregistry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration;
|
||||
import org.springframework.cloud.consul.ConsulAutoConfiguration;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.cloud.consul.discovery.ConsulLifecycle;
|
||||
import org.springframework.cloud.consul.discovery.HeartbeatProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(properties = { "spring.application.name=myTestService2-UU" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class ConsulAutoServiceRegistrationWithLifecycleTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
private ConsulRegistration consulRegistration;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ConsulAutoServiceRegistration autoServiceRegistration;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ConsulServiceRegistry consulServiceRegistry;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
assertNull("consulRegistration was created by mistake", consulRegistration);
|
||||
assertNull("autoServiceRegistration was created by mistake", autoServiceRegistration);
|
||||
assertNotNull("consulServiceRegistry was not created", consulServiceRegistry);
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
@ImportAutoConfiguration({ AutoServiceRegistrationConfiguration.class, ConsulAutoConfiguration.class, ConsulAutoServiceRegistrationAutoConfiguration.class })
|
||||
protected static class TestConfig {
|
||||
@Bean
|
||||
public ConsulLifecycle consulLifecycle(ConsulClient client, ConsulDiscoveryProperties properties, HeartbeatProperties heartbeatProperties) {
|
||||
return new ConsulLifecycle(client, properties, heartbeatProperties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-consul-all</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-consul-bus</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-consul-config</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-consul</artifactId>
|
||||
<version>1.1.3.BUILD-SNAPSHOT</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-consul</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user