use of com.ecwid.consul.v1.health.model.HealthService.Service in project motan by weibocom.
the class ConsulEcwidClient method registerService.
@Override
public void registerService(ConsulService service) {
NewService newService = convertService(service);
client.agentServiceRegister(newService);
}
use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.
the class ConsulHeartbeatTaskTests method enableReRegistrationWithCustomPredicate.
@Test
public void enableReRegistrationWithCustomPredicate() {
TtlScheduler ttlScheduler = new TtlScheduler(heartbeatProperties, discoveryProperties, consulClient, e -> e.getStatusContent().endsWith("does not have associated TTL"));
ConsulHeartbeatTask consulHeartbeatTask = new ConsulHeartbeatTask(serviceId, ttlScheduler);
heartbeatProperties.setReregisterServiceOnFailure(true);
NewService service = new NewService();
service.setId(serviceId);
ttlScheduler.add(service);
given(consulClient.agentCheckPass("service:" + serviceId)).willThrow(new OperationException(400, "Internal Server Error", "CheckID \"service:service-A\" does not have associated TTL"));
consulHeartbeatTask.run();
ArgumentCaptor<NewService> serviceCaptor = ArgumentCaptor.forClass(NewService.class);
ArgumentCaptor<String> tokenCaptor = ArgumentCaptor.forClass(String.class);
verify(consulClient, atLeastOnce()).agentServiceRegister(serviceCaptor.capture(), tokenCaptor.capture());
assertThat(serviceCaptor.getValue()).isSameAs(service);
}
use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.
the class ConsulHeartbeatTaskTests method notEligibleForReRegistration.
@Test
public void notEligibleForReRegistration() {
TtlScheduler ttlScheduler = new TtlScheduler(heartbeatProperties, discoveryProperties, consulClient, ReregistrationPredicate.DEFAULT);
ConsulHeartbeatTask consulHeartbeatTask = new ConsulHeartbeatTask(serviceId, ttlScheduler);
heartbeatProperties.setReregisterServiceOnFailure(true);
NewService service = new NewService();
service.setId(serviceId);
ttlScheduler.add(service);
OperationException operationException = new OperationException(400, "Internal Server Error", "CheckID \"service:service-A\" does not have associated TTL");
given(consulClient.agentCheckPass("service:" + serviceId)).willThrow(operationException);
assertThatThrownBy(consulHeartbeatTask::run).isSameAs(operationException);
}
use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.
the class ConsulHeartbeatTaskTests method enableReRegistration.
@Test
public void enableReRegistration() {
TtlScheduler ttlScheduler = new TtlScheduler(heartbeatProperties, discoveryProperties, consulClient, ReregistrationPredicate.DEFAULT);
ConsulHeartbeatTask consulHeartbeatTask = new ConsulHeartbeatTask(serviceId, ttlScheduler);
heartbeatProperties.setReregisterServiceOnFailure(true);
NewService service = new NewService();
service.setId(serviceId);
ttlScheduler.add(service);
given(consulClient.agentCheckPass("service:" + serviceId)).willThrow(new OperationException(500, "Internal Server Error", "CheckID \"service:service-A\" does not have associated TTL"));
consulHeartbeatTask.run();
ArgumentCaptor<NewService> serviceCaptor = ArgumentCaptor.forClass(NewService.class);
ArgumentCaptor<String> tokenCaptor = ArgumentCaptor.forClass(String.class);
verify(consulClient, atLeastOnce()).agentServiceRegister(serviceCaptor.capture(), tokenCaptor.capture());
assertThat(serviceCaptor.getValue()).isSameAs(service);
}
use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.
the class ConsulAutoServiceDeRegistrationDisabledTests method checkService.
private void checkService(final boolean expected) {
final Response<Map<String, Service>> response = this.consul.getAgentServices();
final Map<String, Service> services = response.getValue();
final Service service = services.get("myTestNotDeRegisteredService-D");
if (expected) {
assertThat(service).as("service was not registered").isNotNull();
} else {
assertThat(service).as("service was registered").isNull();
}
}
Aggregations