Search in sources :

Example 51 with Service

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

the class ConsulServiceRegistryDisabledTests method testAutoRegistrationDisabled.

private void testAutoRegistrationDisabled(String testName, String disableProperty) {
    new WebApplicationContextRunner().withUserConfiguration(TestConfig.class).withPropertyValues("spring.application.name=" + testName, disableProperty + "=false", "server.port=0").withInitializer(new ConsulTestcontainers()).run(context -> {
        assertThat(context).doesNotHaveBean(ConsulServiceRegistry.class);
        assertThat(context).doesNotHaveBean(HeartbeatProperties.class);
        ConsulClient consul = context.getBean(ConsulClient.class);
        Response<Map<String, Service>> response = consul.getAgentServices();
        Map<String, Service> services = response.getValue();
        Service service = services.get(testName);
        assertThat(service).as("service was registered").isNull();
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) ConsulClient(com.ecwid.consul.v1.ConsulClient) Service(com.ecwid.consul.v1.agent.model.Service) Map(java.util.Map) ConsulTestcontainers(org.springframework.cloud.consul.test.ConsulTestcontainers)

Example 52 with Service

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

the class ConsulServiceRegistry method getStatus.

@Override
public Object getStatus(ConsulRegistration registration) {
    String serviceId = registration.getServiceId();
    Response<List<Check>> response = this.client.getHealthChecksForService(serviceId, HealthChecksForServiceRequest.newBuilder().setQueryParams(QueryParams.DEFAULT).build());
    List<Check> checks = response.getValue();
    for (Check check : checks) {
        if (check.getServiceId().equals(registration.getInstanceId())) {
            if (check.getName().equalsIgnoreCase("Service Maintenance Mode")) {
                return OUT_OF_SERVICE.getCode();
            }
        }
    }
    return UP.getCode();
}
Also used : Check(com.ecwid.consul.v1.health.model.Check) List(java.util.List)

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