diff --git a/src/itest/java/com/orbitz/consul/AgentITest.java b/src/itest/java/com/orbitz/consul/AgentITest.java index e54cdee7..8a88cd8b 100644 --- a/src/itest/java/com/orbitz/consul/AgentITest.java +++ b/src/itest/java/com/orbitz/consul/AgentITest.java @@ -125,6 +125,72 @@ public void shouldRegisterGrpcCheck() throws UnknownHostException, InterruptedEx assertTrue(found); } + @Test + @Ignore + public void shouldRegisterCheckWithId() throws UnknownHostException, InterruptedException { + String serviceName = UUID.randomUUID().toString(); + String serviceId = UUID.randomUUID().toString(); + String checkId = UUID.randomUUID().toString(); + + Registration registration = ImmutableRegistration.builder() + .name(serviceName) + .id(serviceId) + .addChecks(ImmutableRegCheck.builder() + .id(checkId) + .ttl("10s") + .build()) + .build(); + + client.agentClient().register(registration); + + Synchroniser.pause(Duration.ofMillis(100)); + + boolean found = false; + + for (ServiceHealth health : client.healthClient().getAllServiceInstances(serviceName).getResponse()) { + if (health.getService().getId().equals(serviceId)) { + found = true; + assertThat(health.getChecks().size(), is(2)); + assertTrue(health.getChecks().stream().anyMatch(check -> check.getCheckId().equals(checkId))); + } + } + + assertTrue(found); + } + + @Test + @Ignore + public void shouldRegisterCheckWithName() throws UnknownHostException, InterruptedException { + String serviceName = UUID.randomUUID().toString(); + String serviceId = UUID.randomUUID().toString(); + String checkName = UUID.randomUUID().toString(); + + Registration registration = ImmutableRegistration.builder() + .name(serviceName) + .id(serviceId) + .addChecks(ImmutableRegCheck.builder() + .name(checkName) + .ttl("10s") + .build()) + .build(); + + client.agentClient().register(registration); + + Synchroniser.pause(Duration.ofMillis(100)); + + boolean found = false; + + for (ServiceHealth health : client.healthClient().getAllServiceInstances(serviceName).getResponse()) { + if (health.getService().getId().equals(serviceId)) { + found = true; + assertThat(health.getChecks().size(), is(2)); + assertTrue(health.getChecks().stream().anyMatch(check -> check.getName().equals(checkName))); + } + } + + assertTrue(found); + } + @Test @Ignore public void shouldRegisterMultipleChecks() throws UnknownHostException, InterruptedException, MalformedURLException { diff --git a/src/main/java/com/orbitz/consul/model/agent/Registration.java b/src/main/java/com/orbitz/consul/model/agent/Registration.java index 4b549113..e30a4a96 100644 --- a/src/main/java/com/orbitz/consul/model/agent/Registration.java +++ b/src/main/java/com/orbitz/consul/model/agent/Registration.java @@ -60,6 +60,12 @@ public abstract class Registration { @JsonInclude(JsonInclude.Include.NON_NULL) public abstract static class RegCheck { + @JsonProperty("CheckID") + public abstract Optional getId(); + + @JsonProperty("Name") + public abstract Optional getName(); + @JsonProperty("Args") public abstract Optional> getArgs();