Search in sources :

Example 41 with Service

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

the class ConsulAutoServiceRegistrationCustomizedDiscoveryPortTests method contextLoads.

@Test
public void contextLoads() {
    NewService service = this.registration.getService();
    assertThat(service).as("service was null").isNotNull();
    assertThat(service.getPort()).as("service port is 0").isGreaterThan(0);
    NewService.Check check = service.getCheck();
    assertThat(check).as("check was null").isNotNull();
    String httpCheck = String.format("%s://%s:%s%s", this.properties.getScheme(), this.properties.getHostname(), this.properties.getPort(), this.properties.getHealthCheckPath());
    assertThat(check.getHttp()).as("http check was wrong").isEqualTo(httpCheck);
// unable to call consul api to get health check details
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 42 with Service

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

the class ConsulAutoServiceRegistrationCustomizedInstanceZoneTests 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-WithZone");
    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-WithZone");
    assertThat(service.getMeta()).as("service zone was wrong").containsEntry("myZone", "zone1");
}
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 43 with Service

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

the class ConsulAutoServiceRegistrationCustomizedPropsTests method propertiesAreCorrect.

@Test
public void propertiesAreCorrect() {
    Response<Map<String, Service>> response = this.consul.getAgentServices();
    Map<String, Service> services = response.getValue();
    Service service = services.get("myTestService1-B");
    assertThat(service).as("service was null").isNotNull();
    assertThat(service.getPort()).as("service port is discovery port").isEqualTo(4452);
    assertThat("myTestService1-B").as("service id was wrong").isEqualTo(service.getId());
    assertThat("myTestService-B").as("service name was wrong").isEqualTo(service.getService());
    assertThat("myhost").as("property hostname was wrong").isEqualTo(this.properties.getHostname());
    assertThat("10.0.0.1").as("property ipAddress was wrong").isEqualTo(this.properties.getIpAddress());
    assertThat("myhost").as("service address was wrong").isEqualTo(service.getAddress());
    assertThat(service.getEnableTagOverride()).as("property enableTagOverride was wrong").isTrue();
    assertThat(service.getTags()).as("property tags contains the wrong values").containsExactly("mytag");
    HashMap<String, String> entries = new HashMap<>();
    entries.put("key1", "value1");
    entries.put("key2", "value2");
    entries.put("mydefaultzonemetadataname", "myzone");
    entries.put("group", "mygroup");
    entries.put("secure", "false");
    assertThat(service.getMeta()).as("property metadata contains the wrong entries").containsExactlyInAnyOrderEntriesOf(entries);
    Response<List<Check>> checkResponse = this.consul.getHealthChecksForService("myTestService-B", HealthChecksForServiceRequest.newBuilder().setQueryParams(QueryParams.DEFAULT).build());
    List<Check> checks = checkResponse.getValue();
    assertThat(checks).as("checks was wrong size").hasSize(0);
}
Also used : HashMap(java.util.HashMap) Check(com.ecwid.consul.v1.health.model.Check) Service(com.ecwid.consul.v1.agent.model.Service) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 44 with Service

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

the class ConsulAutoRegistrationHealthCheckHeadersTests method contextLoads.

@Test
public void contextLoads() {
    NewService service = this.registration.getService();
    assertThat(service).as("service was null").isNotNull();
    NewService.Check check = service.getCheck();
    assertThat(check).as("check was null").isNotNull();
    assertThat(check.getHeader()).as("header is null").isNotNull();
    assertThat(check.getHeader()).as("header is empty").isNotEmpty();
    assertThat(check.getHeader().get("X-Config-Token").get(0)).as("expected header value not found").isEqualTo("ACCESSTOKEN");
// unable to call consul api to get health check details
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 45 with Service

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

the class ConsulAutoServiceRegistrationCustomizedAgentAddressTests 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-AA");
    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-AA");
    assertThat(service.getService()).as("service name was wrong").isEqualTo("myprefix-myTestService-AA");
    assertThat(StringUtils.isEmpty(service.getAddress())).as("service address must be empty").isTrue();
}
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