Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Collections;

import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
Expand Down Expand Up @@ -241,9 +240,8 @@ public boolean resolve(Object argument, MethodParameter parameter, HttpRequestVa
builder.addRequestParameter("dc", params.getDatacenter());
}

if (params.getConsistencyMode() != ConsulClient.ConsistencyMode.DEFAULT) {
builder.configureRequestParams(
map -> map.put(params.getConsistencyMode().getParamName(), Collections.emptyList()));
if (params.getConsistencyMode() != null && params.getConsistencyMode() != ConsulClient.ConsistencyMode.DEFAULT) {
builder.addRequestParameter(params.getConsistencyMode().getParamName(), "true");
}

if (params.getWaitTime() != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ ResponseEntity<List<HealthService>> getHealthServices(@PathVariable String servi
@RequestParam boolean passing, @RequestHeader(name = ACL_TOKEN_HEADER, required = false) String aclToken,
@RequestParam(required = false) List<String> tag, QueryParams queryParams);

@GetExchange("/v1/health/service/{serviceName}")
ResponseEntity<List<HealthService>> getHealthServices(@PathVariable String serviceName,
@RequestParam boolean passing, @RequestHeader(name = ACL_TOKEN_HEADER, required = false) String aclToken,
@RequestParam(required = false) List<String> tag, QueryParams queryParams,
@RequestParam(required = false) Boolean cached);

@DeleteExchange("/v1/kv/{context}")
ResponseEntity<Void> deleteKVValues(@PathVariable String context);

Expand Down Expand Up @@ -182,12 +188,11 @@ public QueryParams(String datacenter, long waitTime, long index) {
this(datacenter, ConsistencyMode.DEFAULT, waitTime, index, null);
}

private QueryParams(String datacenter, ConsistencyMode consistencyMode, long waitTime, long index) {
public QueryParams(String datacenter, ConsistencyMode consistencyMode, long waitTime, long index) {
this(datacenter, consistencyMode, waitTime, index, null);
}

private QueryParams(String datacenter, ConsistencyMode consistencyMode, long waitTime, long index,
String near) {
public QueryParams(String datacenter, ConsistencyMode consistencyMode, long waitTime, long index, String near) {
this.datacenter = datacenter;
this.consistencyMode = consistencyMode;
this.waitTime = waitTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.testcontainers.utility.DockerImageName;

import org.springframework.cloud.consul.model.http.event.Event;
import org.springframework.cloud.consul.model.http.health.HealthService;
import org.springframework.cloud.consul.model.http.kv.GetValue;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -151,6 +152,46 @@ void getKVValues_WithWaitTimeAndIndexAndAclToken() {
assertThat(value.getDecodedValue()).isEqualTo("test");
}

@Test
void getHealthServiceWithCached() {

mockServerClient.when(request().withMethod("GET").withPath("/v1/health/service/testservice"))
.respond(response().withStatusCode(200));
ResponseEntity<List<HealthService>> response = client.getHealthServices("testservice", true, "token12345",
List.of("tag1", "tag2"),
new ConsulClient.QueryParams(null, ConsulClient.ConsistencyMode.STALE, 3, 12345), true);

mockServerClient.verify(request().withMethod("GET")
.withPath("/v1/health/service/testservice")
.withHeader(Header.header("X-Consul-Token", "token12345"))
.withQueryStringParameter("tag", "tag1", "tag2")
.withQueryStringParameter("passing", "true")
.withQueryStringParameter("stale", "true")
.withQueryStringParameter("wait", "3s")
.withQueryStringParameter("index", "12345")
.withQueryStringParameter("cached", "true"), VerificationTimes.exactly(1));
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}

@Test
void getHealthServiceWithoutCached() {

mockServerClient.when(request().withMethod("GET").withPath("/v1/health/service/testservice"))
.respond(response().withStatusCode(200));
ResponseEntity<List<HealthService>> response = client.getHealthServices("testservice", true, "token12345",
List.of("tag1", "tag2"),
new ConsulClient.QueryParams(null, null, 3, 12345), null);

mockServerClient.verify(request().withMethod("GET")
.withPath("/v1/health/service/testservice")
.withHeader(Header.header("X-Consul-Token", "token12345"))
.withQueryStringParameter("tag", "tag1", "tag2")
.withQueryStringParameter("passing", "true")
.withQueryStringParameter("wait", "3s")
.withQueryStringParameter("index", "12345"), VerificationTimes.exactly(1));
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
}

@Test
void eventListWithWaitTimeAndIndex() {

Expand Down
Loading