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

Add optional fields to checks during registration #444

Merged
merged 1 commit into from
Jun 6, 2021
Merged
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
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