Search in sources :

Example 1 with Service

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

the class ConsulAutoServiceRegistrationNonWebTests method contextLoads.

@Test
public void contextLoads() {
    assertNotNull("ConsulAutoServiceRegistration was created", autoServiceRegistration);
    Response<Map<String, Service>> response = consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("consulNonWebTest");
    // no port to listen, hence no registration
    assertNull("service was registered", service);
}
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 2 with Service

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

the class ConsulAutoServiceRegistrationTests method contextLoads.

@Test
public void contextLoads() {
    Response<Map<String, Service>> response = consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get(registration.getInstanceId());
    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.getInstanceId(), 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());
}
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 3 with Service

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

the class ConsulServiceRegistryTests method contextLoads.

@Test
public void contextLoads() {
    assertThat(autoRegistration).as("autoRegistration created erroneously").isNull();
    String serviceId = "myNonAutoRegisteredService";
    NewService service = new NewService();
    service.setAddress("localhost");
    service.setId("myNonAutoRegisteredService-A1");
    service.setName(serviceId);
    service.setPort(port);
    service.setTags(Collections.singletonList("mytag"));
    ConsulRegistration registration = new ConsulRegistration(service, this.properties);
    Throwable t = null;
    try {
        serviceRegistry.register(registration);
        assertHasInstance(serviceId);
        assertStatus(registration, "UP");
        // only works if query-passing = true
        serviceRegistry.setStatus(registration, "OUT_OF_SERVICE");
        assertEmptyInstances(serviceId);
        assertStatus(registration, "OUT_OF_SERVICE");
        serviceRegistry.setStatus(registration, "UP");
        assertHasInstance(serviceId);
    } catch (RuntimeException e) {
        throw e;
    } finally {
        serviceRegistry.deregister(registration);
        if (t == null) {
            // just deregister, test already failed
            assertEmptyInstances(serviceId);
        }
    }
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Service

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

the class ConsulAutoServiceRegistrationCustomizedPropsTests method contextLoads.

@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));
}
Also used : Check(com.ecwid.consul.v1.health.model.Check) Service(com.ecwid.consul.v1.agent.model.Service) List(java.util.List) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Service

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

the class ConsulAutoServiceRegistrationCustomizedServletContextTests method contextLoads.

@Test
public void contextLoads() {
    Response<Map<String, Service>> response = consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestService1-WithServletContext");
    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-WithServletContext");
    assertThat(service.getTags()).as("contextPath tag missing").contains("contextPath=/customContext");
}
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)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 Service (com.ecwid.consul.v1.agent.model.Service)14 Map (java.util.Map)14 NewService (com.ecwid.consul.v1.agent.model.NewService)12 Check (com.ecwid.consul.v1.health.model.Check)6 HealthService (com.ecwid.consul.v1.health.model.HealthService)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 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 JSONObject (com.alibaba.fastjson.JSONObject)1 ConsulClient (com.ecwid.consul.v1.ConsulClient)1 Service (com.ecwid.consul.v1.health.model.HealthService.Service)1 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)1 ConsulServer (org.springframework.cloud.consul.discovery.ConsulServer)1 ConsulServerList (org.springframework.cloud.consul.discovery.ConsulServerList)1