diff --git a/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/EventService.java b/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/EventService.java index 5035f4eb..75e36336 100644 --- a/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/EventService.java +++ b/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/EventService.java @@ -24,6 +24,7 @@ import javax.annotation.PostConstruct; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; +import com.ecwid.consul.v1.event.EventListRequest; import com.ecwid.consul.v1.event.model.Event; import com.ecwid.consul.v1.event.model.EventParams; import com.fasterxml.jackson.databind.ObjectMapper; @@ -77,7 +78,8 @@ public class EventService { } public Response> getEventsResponse() { - return this.consul.eventList(QueryParams.DEFAULT); + return this.consul.eventList(EventListRequest.newBuilder() + .setQueryParams(QueryParams.DEFAULT).build()); } public List getEvents() { @@ -102,8 +104,8 @@ public class EventService { if (this.properties != null) { eventTimeout = this.properties.getEventTimeout(); } - Response> watch = this.consul - .eventList(new QueryParams(eventTimeout, index)); + Response> watch = this.consul.eventList(EventListRequest.newBuilder() + .setQueryParams(new QueryParams(eventTimeout, index)).build()); return filterEvents(readEvents(watch), lastIndex); } diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java index 32262f44..b7a3fb40 100644 --- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java +++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java @@ -32,10 +32,10 @@ import org.springframework.cloud.endpoint.event.RefreshEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.util.StringUtils; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulEndpoint.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulEndpoint.java index d31aba62..67ac0c70 100644 --- a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulEndpoint.java +++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulEndpoint.java @@ -24,6 +24,9 @@ import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; import com.ecwid.consul.v1.agent.model.Service; +import com.ecwid.consul.v1.catalog.CatalogNodesRequest; +import com.ecwid.consul.v1.catalog.CatalogServiceRequest; +import com.ecwid.consul.v1.catalog.CatalogServicesRequest; import com.ecwid.consul.v1.catalog.model.CatalogService; import com.ecwid.consul.v1.catalog.model.Node; @@ -51,16 +54,19 @@ public class ConsulEndpoint { data.setAgentServices(agentServices.getValue()); Response>> catalogServices = this.consul - .getCatalogServices(QueryParams.DEFAULT); + .getCatalogServices(CatalogServicesRequest.newBuilder() + .setQueryParams(QueryParams.DEFAULT).build()); for (String serviceId : catalogServices.getValue().keySet()) { Response> response = this.consul - .getCatalogService(serviceId, QueryParams.DEFAULT); + .getCatalogService(serviceId, CatalogServiceRequest.newBuilder() + .setQueryParams(QueryParams.DEFAULT).build()); data.getCatalogServices().put(serviceId, response.getValue()); } Response> catalogNodes = this.consul - .getCatalogNodes(QueryParams.DEFAULT); + .getCatalogNodes(CatalogNodesRequest.newBuilder() + .setQueryParams(QueryParams.DEFAULT).build()); data.setCatalogNodes(catalogNodes.getValue()); return data; diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulHealthIndicator.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulHealthIndicator.java index 9aab81dd..3f364dd1 100644 --- a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulHealthIndicator.java +++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulHealthIndicator.java @@ -22,6 +22,7 @@ import java.util.Map; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; +import com.ecwid.consul.v1.catalog.CatalogServicesRequest; import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; @@ -41,7 +42,8 @@ public class ConsulHealthIndicator extends AbstractHealthIndicator { protected void doHealthCheck(Health.Builder builder) throws Exception { final Response leaderStatus = this.consul.getStatusLeader(); final Response>> services = this.consul - .getCatalogServices(QueryParams.DEFAULT); + .getCatalogServices(CatalogServicesRequest.newBuilder() + .setQueryParams(QueryParams.DEFAULT).build()); builder.up().withDetail("leader", leaderStatus.getValue()).withDetail("services", services.getValue()); } diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulCatalogWatch.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulCatalogWatch.java index e8979fa4..95c475c9 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulCatalogWatch.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulCatalogWatch.java @@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicReference; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; +import com.ecwid.consul.v1.catalog.CatalogServicesRequest; import io.micrometer.core.annotation.Timed; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -126,10 +127,12 @@ public class ConsulCatalogWatch index = this.catalogServicesIndex.get().longValue(); } - Response>> response = this.consul.getCatalogServices( - new QueryParams(this.properties.getCatalogServicesWatchTimeout(), - index), - this.properties.getAclToken()); + CatalogServicesRequest request = CatalogServicesRequest.newBuilder() + .setQueryParams(new QueryParams( + this.properties.getCatalogServicesWatchTimeout(), index)) + .setToken(this.properties.getAclToken()).build(); + Response>> response = this.consul + .getCatalogServices(request); Long consulIndex = response.getConsulIndex(); if (consulIndex != null) { this.catalogServicesIndex.set(BigInteger.valueOf(consulIndex)); diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClient.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClient.java index d69b2eb4..f64cf6fd 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClient.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClient.java @@ -23,6 +23,8 @@ import java.util.Map; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; +import com.ecwid.consul.v1.catalog.CatalogServicesRequest; +import com.ecwid.consul.v1.health.HealthServicesRequest; import com.ecwid.consul.v1.health.model.HealthService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,7 +32,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.cloud.client.DefaultServiceInstance; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; -import org.springframework.util.StringUtils; import static org.springframework.cloud.consul.discovery.ConsulServerUtils.findHost; import static org.springframework.cloud.consul.discovery.ConsulServerUtils.getMetadata; @@ -77,18 +78,13 @@ public class ConsulDiscoveryClient implements DiscoveryClient { private void addInstancesToList(List instances, String serviceId, QueryParams queryParams) { - String aclToken = this.properties.getAclToken(); - Response> services; - if (StringUtils.hasText(aclToken)) { - services = this.client.getHealthServices(serviceId, - this.properties.getDefaultQueryTag(), - this.properties.isQueryPassing(), queryParams, aclToken); - } - else { - services = this.client.getHealthServices(serviceId, - this.properties.getDefaultQueryTag(), - this.properties.isQueryPassing(), queryParams); - } + HealthServicesRequest request = HealthServicesRequest.newBuilder() + .setTag(this.properties.getDefaultQueryTag()) + .setPassing(this.properties.isQueryPassing()).setQueryParams(queryParams) + .setToken(this.properties.getAclToken()).build(); + Response> services = this.client.getHealthServices(serviceId, + request); + for (HealthService service : services.getValue()) { String host = findHost(service); @@ -106,7 +102,8 @@ public class ConsulDiscoveryClient implements DiscoveryClient { List instances = new ArrayList<>(); Response>> services = this.client - .getCatalogServices(QueryParams.DEFAULT); + .getCatalogServices(CatalogServicesRequest.newBuilder() + .setQueryParams(QueryParams.DEFAULT).build()); for (String serviceId : services.getValue().keySet()) { addInstancesToList(instances, serviceId, QueryParams.DEFAULT); } @@ -117,15 +114,11 @@ public class ConsulDiscoveryClient implements DiscoveryClient { public List getServices() { String aclToken = this.properties.getAclToken(); - if (StringUtils.hasText(aclToken)) { - return new ArrayList<>( - this.client.getCatalogServices(QueryParams.DEFAULT, aclToken) - .getValue().keySet()); - } - else { - return new ArrayList<>(this.client.getCatalogServices(QueryParams.DEFAULT) - .getValue().keySet()); - } + CatalogServicesRequest request = CatalogServicesRequest.newBuilder() + .setQueryParams(QueryParams.DEFAULT) + .setToken(this.properties.getAclToken()).build(); + return new ArrayList<>( + this.client.getCatalogServices(request).getValue().keySet()); } @Override diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java index a34d06fb..60901403 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java @@ -23,6 +23,7 @@ import java.util.List; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; +import com.ecwid.consul.v1.health.HealthServicesRequest; import com.ecwid.consul.v1.health.model.HealthService; import com.netflix.client.config.IClientConfig; import com.netflix.loadbalancer.AbstractServerList; @@ -76,10 +77,12 @@ public class ConsulServerList extends AbstractServerList { if (this.client == null) { return Collections.emptyList(); } - String tag = getTag(); // null is ok - Response> response = this.client.getHealthServices( - this.serviceId, tag, this.properties.isQueryPassing(), - createQueryParamsForClientRequest(), this.properties.getAclToken()); + HealthServicesRequest request = HealthServicesRequest.newBuilder() + .setTag(getTag()).setPassing(this.properties.isQueryPassing()) + .setQueryParams(createQueryParamsForClientRequest()) + .setToken(this.properties.getAclToken()).build(); + Response> response = this.client + .getHealthServices(this.serviceId, request); if (response.getValue() == null || response.getValue().isEmpty()) { return Collections.emptyList(); } diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClient.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClient.java index 122dbc50..db8325c4 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClient.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClient.java @@ -24,6 +24,8 @@ import java.util.Map; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; +import com.ecwid.consul.v1.catalog.CatalogServicesRequest; +import com.ecwid.consul.v1.health.HealthServicesRequest; import com.ecwid.consul.v1.health.model.HealthService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +36,6 @@ import org.springframework.cloud.client.DefaultServiceInstance; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties; -import org.springframework.util.StringUtils; import static org.springframework.cloud.consul.discovery.ConsulServerUtils.findHost; import static org.springframework.cloud.consul.discovery.ConsulServerUtils.getMetadata; @@ -79,15 +80,14 @@ public class ConsulReactiveDiscoveryClient implements ReactiveDiscoveryClient { } private List getHealthServices(String serviceId) { - Response> services = StringUtils - .hasText(properties.getAclToken()) - ? client.getHealthServices(serviceId, - properties.getDefaultQueryTag(), - properties.isQueryPassing(), QueryParams.DEFAULT, - properties.getAclToken()) - : client.getHealthServices(serviceId, - properties.getDefaultQueryTag(), - properties.isQueryPassing(), QueryParams.DEFAULT); + HealthServicesRequest request = HealthServicesRequest.newBuilder() + .setTag(this.properties.getDefaultQueryTag()) + .setPassing(this.properties.isQueryPassing()) + .setQueryParams(QueryParams.DEFAULT) + .setToken(this.properties.getAclToken()).build(); + + Response> services = client.getHealthServices(serviceId, + request); return services == null ? Collections.emptyList() : services.getValue(); } @@ -106,11 +106,11 @@ public class ConsulReactiveDiscoveryClient implements ReactiveDiscoveryClient { @Override public Flux getServices() { return Flux.defer(() -> { - Response>> services = StringUtils - .hasText(properties.getAclToken()) - ? client.getCatalogServices(QueryParams.DEFAULT, - properties.getAclToken()) - : client.getCatalogServices(QueryParams.DEFAULT); + CatalogServicesRequest request = CatalogServicesRequest.newBuilder() + .setToken(properties.getAclToken()) + .setQueryParams(QueryParams.DEFAULT).build(); + Response>> services = client + .getCatalogServices(request); return services == null ? Flux.empty() : Flux.fromIterable(services.getValue().keySet()); }).onErrorResume(exception -> { diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulServiceRegistry.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulServiceRegistry.java index 3d20495a..39f043c8 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulServiceRegistry.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulServiceRegistry.java @@ -23,6 +23,7 @@ import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; import com.ecwid.consul.v1.agent.model.NewService; +import com.ecwid.consul.v1.health.HealthChecksForServiceRequest; import com.ecwid.consul.v1.health.model.Check; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -119,7 +120,8 @@ public class ConsulServiceRegistry implements ServiceRegistry> response = this.client.getHealthChecksForService(serviceId, - QueryParams.DEFAULT); + HealthChecksForServiceRequest.newBuilder() + .setQueryParams(QueryParams.DEFAULT).build()); List checks = response.getValue(); for (Check check : checks) { diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/TtlSchedulerRemoveTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/TtlSchedulerRemoveTests.java index fa8583e4..54e9cd74 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/TtlSchedulerRemoveTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/TtlSchedulerRemoveTests.java @@ -21,6 +21,7 @@ import java.util.List; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; +import com.ecwid.consul.v1.health.HealthChecksForServiceRequest; import com.ecwid.consul.v1.health.model.Check; import org.junit.Test; import org.junit.runner.RunWith; @@ -75,7 +76,8 @@ public class TtlSchedulerRemoveTests { private Check getCheckForService(String serviceId) { Response> checkResponse = this.consul - .getHealthChecksForService(serviceId, QueryParams.DEFAULT); + .getHealthChecksForService(serviceId, HealthChecksForServiceRequest + .newBuilder().setQueryParams(QueryParams.DEFAULT).build()); if (checkResponse.getValue().size() > 0) { return checkResponse.getValue().get(0); } diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/TtlSchedulerTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/TtlSchedulerTests.java index bd96a663..c6191bb8 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/TtlSchedulerTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/TtlSchedulerTests.java @@ -21,6 +21,7 @@ import java.util.List; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; +import com.ecwid.consul.v1.health.HealthChecksForServiceRequest; import com.ecwid.consul.v1.health.model.Check; import org.junit.Test; import org.junit.runner.RunWith; @@ -72,7 +73,8 @@ public class TtlSchedulerTests { private Check getCheckForService(String serviceId) { Response> checkResponse = this.consul - .getHealthChecksForService(serviceId, QueryParams.DEFAULT); + .getHealthChecksForService(serviceId, HealthChecksForServiceRequest + .newBuilder().setQueryParams(QueryParams.DEFAULT).build()); if (checkResponse.getValue().size() > 0) { return checkResponse.getValue().get(0); } diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClientTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClientTests.java index 3f0c376e..c455c7d6 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClientTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/reactive/ConsulReactiveDiscoveryClientTests.java @@ -20,8 +20,9 @@ import java.util.List; import java.util.Map; import com.ecwid.consul.v1.ConsulClient; -import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; +import com.ecwid.consul.v1.catalog.CatalogServicesRequest; +import com.ecwid.consul.v1.health.HealthServicesRequest; import com.ecwid.consul.v1.health.model.HealthService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -38,6 +39,8 @@ import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -69,70 +72,68 @@ class ConsulReactiveDiscoveryClientTests { @Test public void shouldReturnEmptyFluxOfServicesWhenConsulFails() { Flux services = client.getServices(); - when(consulClient.getCatalogServices(QueryParams.DEFAULT)) + when(consulClient.getCatalogServices(any(CatalogServicesRequest.class))) .thenThrow(new RuntimeException("Possible runtime exception")); StepVerifier.create(services).expectNextCount(0).expectComplete().verify(); - verify(consulClient).getCatalogServices(QueryParams.DEFAULT); + verify(consulClient).getCatalogServices(any(CatalogServicesRequest.class)); } @Test public void shouldReturnFluxOfServices() { Flux services = client.getServices(); - when(consulClient.getCatalogServices(QueryParams.DEFAULT)) + when(consulClient.getCatalogServices(any(CatalogServicesRequest.class))) .thenReturn(consulServicesResponse()); StepVerifier.create(services).expectNext("my-service").expectComplete().verify(); verify(properties).getAclToken(); - verify(consulClient).getCatalogServices(QueryParams.DEFAULT); + verify(consulClient).getCatalogServices(any(CatalogServicesRequest.class)); } @Test public void shouldReturnFluxOfServicesWithAclToken() { when(properties.getAclToken()).thenReturn("aclToken"); - when(consulClient.getCatalogServices(QueryParams.DEFAULT, "aclToken")) + when(consulClient.getCatalogServices(any(CatalogServicesRequest.class))) .thenReturn(consulServicesResponse()); Flux services = client.getServices(); StepVerifier.create(services).expectNext("my-service").expectComplete().verify(); - verify(properties, times(2)).getAclToken(); - verify(consulClient).getCatalogServices(QueryParams.DEFAULT, "aclToken"); + verify(properties, times(1)).getAclToken(); + verify(consulClient).getCatalogServices(any(CatalogServicesRequest.class)); } @Test public void shouldReturnEmptyFluxForNonExistingService() { configureCommonProperties(); - when(consulClient.getHealthServices("nonexistent-service", "queryTag", false, - QueryParams.DEFAULT)).thenReturn(emptyConsulInstancesResponse()); + when(consulClient.getHealthServices(eq("nonexistent-service"), + any(HealthServicesRequest.class))) + .thenReturn(emptyConsulInstancesResponse()); Flux instances = client.getInstances("nonexistent-service"); StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); verify(properties).getAclToken(); - verify(consulClient).getHealthServices("nonexistent-service", "queryTag", false, - QueryParams.DEFAULT); + verify(consulClient).getHealthServices(eq("nonexistent-service"), any()); } @Test public void shouldReturnEmptyFluxWhenConsulFails() { configureCommonProperties(); - when(consulClient.getHealthServices("existing-service", "queryTag", false, - QueryParams.DEFAULT)) + when(consulClient.getHealthServices(eq("existing-service"), + any(HealthServicesRequest.class))) .thenThrow(new RuntimeException("Possible runtime exception")); Flux instances = client.getInstances("existing-service"); StepVerifier.create(instances).expectNextCount(0).expectComplete().verify(); - verify(consulClient).getHealthServices("existing-service", "queryTag", false, - QueryParams.DEFAULT); + verify(consulClient).getHealthServices(eq("existing-service"), any()); } @Test public void shouldReturnFluxOfServiceInstances() { configureCommonProperties(); Response> response = consulInstancesResponse(); - when(consulClient.getHealthServices("existing-service", "queryTag", false, - QueryParams.DEFAULT)).thenReturn(response); + when(consulClient.getHealthServices(eq("existing-service"), + any(HealthServicesRequest.class))).thenReturn(response); Flux instances = client.getInstances("existing-service"); StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); verify(properties).getAclToken(); verify(properties).getDefaultQueryTag(); verify(properties).isQueryPassing(); - verify(consulClient).getHealthServices("existing-service", "queryTag", false, - QueryParams.DEFAULT); + verify(consulClient).getHealthServices(eq("existing-service"), any()); } @Test @@ -140,15 +141,14 @@ class ConsulReactiveDiscoveryClientTests { configureCommonProperties(); when(properties.getAclToken()).thenReturn("aclToken"); Response> response = consulInstancesResponse(); - when(consulClient.getHealthServices("existing-service", "queryTag", false, - QueryParams.DEFAULT, "aclToken")).thenReturn(response); + when(consulClient.getHealthServices(eq("existing-service"), + any(HealthServicesRequest.class))).thenReturn(response); Flux instances = client.getInstances("existing-service"); StepVerifier.create(instances).expectNextCount(1).expectComplete().verify(); - verify(properties, times(2)).getAclToken(); + verify(properties, times(1)).getAclToken(); verify(properties).getDefaultQueryTag(); verify(properties).isQueryPassing(); - verify(consulClient).getHealthServices("existing-service", "queryTag", false, - QueryParams.DEFAULT, "aclToken"); + verify(consulClient).getHealthServices(eq("existing-service"), any()); } private Response>> consulServicesResponse() { diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedPropsTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedPropsTests.java index bb3013f4..c6a70d9d 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedPropsTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedPropsTests.java @@ -23,6 +23,7 @@ import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.QueryParams; import com.ecwid.consul.v1.Response; import com.ecwid.consul.v1.agent.model.Service; +import com.ecwid.consul.v1.health.HealthChecksForServiceRequest; import com.ecwid.consul.v1.health.model.Check; import org.junit.Test; import org.junit.runner.RunWith; @@ -82,8 +83,9 @@ public class ConsulAutoServiceRegistrationCustomizedPropsTests { assertThat("myhost").as("service address was wrong") .isEqualTo(service.getAddress()); - Response> checkResponse = this.consul - .getHealthChecksForService("myTestService-B", QueryParams.DEFAULT); + Response> checkResponse = this.consul.getHealthChecksForService( + "myTestService-B", HealthChecksForServiceRequest.newBuilder() + .setQueryParams(QueryParams.DEFAULT).build()); List checks = checkResponse.getValue(); assertThat(checks).as("checks was wrong size").hasSize(0); }