Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Add optional fields CheckId and Name to check during registration (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tipnik authored Jun 6, 2021
1 parent 67f8449 commit 52c40a8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/itest/java/com/orbitz/consul/AgentITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/orbitz/consul/model/agent/Registration.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public abstract class Registration {
@JsonInclude(JsonInclude.Include.NON_NULL)
public abstract static class RegCheck {

@JsonProperty("CheckID")
public abstract Optional<String> getId();

@JsonProperty("Name")
public abstract Optional<String> getName();

@JsonProperty("Args")
public abstract Optional<List<String>> getArgs();

Expand Down

0 comments on commit 52c40a8

Please sign in to comment.