Search in sources :

Example 36 with Service

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);
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService)

Example 37 with Service

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);
}
Also used : ConsulHeartbeatTask(org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask) NewService(com.ecwid.consul.v1.agent.model.NewService) OperationException(com.ecwid.consul.v1.OperationException) Test(org.junit.Test)

Example 38 with 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);
}
Also used : ConsulHeartbeatTask(org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask) NewService(com.ecwid.consul.v1.agent.model.NewService) OperationException(com.ecwid.consul.v1.OperationException) Test(org.junit.Test)

Example 39 with Service

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);
}
Also used : ConsulHeartbeatTask(org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask) NewService(com.ecwid.consul.v1.agent.model.NewService) OperationException(com.ecwid.consul.v1.OperationException) Test(org.junit.Test)

Example 40 with 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();
    }
}
Also used : Service(com.ecwid.consul.v1.agent.model.Service) Map(java.util.Map)

Aggregations

Test (org.junit.Test)26 NewService (com.ecwid.consul.v1.agent.model.NewService)23 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 Service (com.ecwid.consul.v1.agent.model.Service)17 Map (java.util.Map)17 Check (com.ecwid.consul.v1.health.model.Check)7 HealthService (com.ecwid.consul.v1.health.model.HealthService)6 List (java.util.List)5 OperationException (com.ecwid.consul.v1.OperationException)4 ArrayList (java.util.ArrayList)4 ConsulHeartbeatTask (org.springframework.cloud.consul.discovery.TtlScheduler.ConsulHeartbeatTask)4 ConsulClient (com.ecwid.consul.v1.ConsulClient)3 QueryParams (com.ecwid.consul.v1.QueryParams)3 CatalogService (com.ecwid.consul.v1.catalog.model.CatalogService)2 ConsulService (com.weibo.api.motan.registry.consul.ConsulService)2 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)2 ConsulTestcontainers (org.springframework.cloud.consul.test.ConsulTestcontainers)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ConsulException (com.ecwid.consul.ConsulException)1 Response (com.ecwid.consul.v1.Response)1