Search in sources :

Example 46 with Service

use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.

the class ConsulAutoServiceRegistrationCustomizedInstanceGroupTests method contextLoads.

@Test
public void contextLoads() {
    Response<Map<String, Service>> response = this.consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestService1-WithGroup");
    assertThat(service).as("service was null").isNotNull();
    assertThat(service.getPort().intValue()).as("service port is 0").isNotEqualTo(0);
    assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService1-WithGroup");
    assertThat(service.getMeta()).as("service group was wrong").containsEntry("group", "test");
    ServiceInstance instance = client.choose("myTestService-WithGroup");
    assertThat(instance).isNotNull();
    assertThat(instance.getMetadata()).containsEntry("group", "test");
}
Also used : Service(com.ecwid.consul.v1.agent.model.Service) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 47 with Service

use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.

the class ConsulAutoServiceRegistrationCustomizedServiceNameTests method contextLoads.

@Test
public void contextLoads() {
    Response<Map<String, Service>> response = this.consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestService1-CC");
    assertThat(service).as("service was null").isNotNull();
    assertThat(service.getPort().intValue()).as("service port is 0").isNotEqualTo(0);
    assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService1-CC");
    assertThat(service.getService()).as("service name was wrong").isEqualTo("myprefix-myTestService-CC");
}
Also used : Service(com.ecwid.consul.v1.agent.model.Service) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 48 with Service

use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.

the class ConsulAutoServiceRegistrationDefaultPortTests method contextLoads.

@Test
public void contextLoads() {
    Response<Map<String, Service>> response = this.consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestService2-DD");
    assertThat(service).as("service was null").isNotNull();
    assertThat(service.getPort().intValue()).as("service port is 0").isNotEqualTo(0);
}
Also used : Service(com.ecwid.consul.v1.agent.model.Service) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 49 with Service

use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.

the class TtlSchedulerTests method should_send_a_check_before_ttl_for_all_services.

@Test
public void should_send_a_check_before_ttl_for_all_services() throws InterruptedException {
    // Wait for TTL to expired (TTL is set to 2 seconds)
    Thread.sleep(2100);
    Check serviceCheck = getCheckForService("ttlScheduler");
    assertThat(serviceCheck).isNotNull();
    assertThat(serviceCheck.getStatus()).isEqualTo(PASSING).as("Service check is in wrong state");
    Check serviceManagementCheck = getCheckForService("ttlScheduler-management");
    assertThat(serviceManagementCheck).isNotNull();
    assertThat(serviceManagementCheck.getStatus()).isEqualTo(PASSING).as("Service management check is in wrong state");
}
Also used : Check(com.ecwid.consul.v1.health.model.Check) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 50 with Service

use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.

the class ConsulAutoServiceRegistrationManagementServiceTests method contextLoads.

@Test
public void contextLoads() {
    final Response<Map<String, Service>> response = this.consul.getAgentServices();
    final Map<String, Service> services = response.getValue();
    final Service service = services.get("myTestService-EE-0");
    assertThat(service).as("service was null").isNotNull();
    assertThat(service.getPort().intValue()).as("service port was 0").isNotEqualTo(0);
    assertThat(service.getId()).as("service id was wrong").isEqualTo("myTestService-EE-0");
    assertThat(service.getService()).as("service name was wrong").isEqualTo("myTestService-EE");
    assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must not be empty").isFalse();
    assertThat(service.getAddress()).as("service address must equals hostname from discovery properties").isEqualTo(this.discoveryProperties.getHostname());
    final Service managementService = services.get("myTestService-EE-0-management");
    assertThat(managementService).as("management service was null").isNotNull();
    assertThat(managementService.getPort().intValue()).as("management service port was wrong").isEqualTo(4452);
    assertThat(managementService.getId()).as("management service id was wrong").isEqualTo("myTestService-EE-0-management");
    assertThat(managementService.getService()).as("management service name was wrong").isEqualTo("myTestService-EE-management");
    assertThat(StringUtils.isEmpty(managementService.getAddress())).as("management service address must not be empty").isFalse();
    assertThat(managementService.getAddress()).as("management service address must equals hostname from discovery properties").isEqualTo(this.discoveryProperties.getHostname());
}
Also used : Service(com.ecwid.consul.v1.agent.model.Service) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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