case "checkOptions": if (member.getValue() instanceof JsonObject) { obj.setCheckOptions(new io.vertx.ext.consul.CheckOptions((JsonObject)member.getValue()));
@Override void createCheck(TestContext tc, CheckOptions opts, Handler<String> idHandler) { ServiceOptions options = randomServiceOptions().setCheckOptions(opts); ctx.writeClient().registerService(options, tc.asyncAssertSuccess(v -> idHandler.handle("service:" + options.getId()))); } }
@Override String createCheck(CheckOptions opts) { String serviceId = "serviceId"; ServiceOptions service = new ServiceOptions() .setName("serviceName") .setId(serviceId) .setTags(Arrays.asList("tag1", "tag2")) .setCheckOptions(opts) .setAddress("10.0.0.1") .setPort(8080); runAsync(h -> ctx.writeClient().registerService(service, h)); return "service:" + serviceId; }
serviceOptions.setCheckOptions(new CheckOptions(record.getMetadata().getJsonObject("checkoptions", new JsonObject()))); record.getMetadata().remove("checkoptions");
@Test public void healthState() throws InterruptedException { String serviceName = randomAlphaString(10); ServiceOptions opts = new ServiceOptions() .setName(serviceName) .setId(serviceName) .setCheckOptions(new CheckOptions().setTtl("1m")); runAsync(h -> ctx.writeClient().registerService(opts, h)); CheckList list1 = getAsync(h -> ctx.readClient().healthState(HealthState.CRITICAL, h)); CountDownLatch latch = new CountDownLatch(1); waitBlockingQuery(latch, 10, list1.getIndex(), (idx, fut) -> { CheckQueryOptions options = new CheckQueryOptions() .setBlockingOptions(new BlockingQueryOptions().setIndex(idx)); ctx.readClient().healthStateWithOptions(HealthState.PASSING, options, h -> { List<String> names = h.result().getList().stream().map(Check::getServiceName).collect(Collectors.toList()); waitComplete(vertx, fut, h.result().getIndex(), names.contains(serviceName)); }); }); runAsync(h -> ctx.writeClient().passCheck("service:" + serviceName, h)); awaitLatch(latch); runAsync(h -> ctx.writeClient().deregisterService(serviceName, h)); }
runAsync(h -> ctx.writeClient().registerService(new ServiceOptions() .setName("service").setId("id1").setTags(Collections.singletonList("tag1")) .setCheckOptions(new CheckOptions().setTtl("5s").setStatus(CheckStatus.PASSING)), h)); runAsync(h -> ctx.writeClient().registerService(new ServiceOptions() .setName("service").setId("id2").setTags(Collections.singletonList("tag2")) .setCheckOptions(new CheckOptions().setTtl("5s").setStatus(CheckStatus.PASSING)), h));
@Test public void watchService() throws InterruptedException { StateConsumer<String> consumer = new StateConsumer<>(); ServiceOptions service = new ServiceOptions() .setCheckOptions(new CheckOptions() .setStatus(CheckStatus.PASSING) .setTtl("4s") .setName(randomAlphaString(10))) .setId(randomAlphaString(10)) .setName(randomAlphaString(10)); Watch<ServiceEntryList> watch = Watch.service(service.getName(), vertx, ctx.readClientOptions()) .setHandler(list -> { if (list.succeeded()) { consumer.consume(list.nextResult().getList() .stream().filter(s -> s.getService().getName().equals(service.getName())) .map(e -> e.getService().getName() + "/" + e.getChecks().stream() .filter(c -> c.getId().equals("service:" + service.getId())) .map(c -> c.getStatus().name()).findFirst().orElse("")) .findFirst().orElse("")); } }) .start(); consumer.await(""); runAsync(h -> ctx.writeClient().registerService(service, h)); consumer.await(service.getName() + "/" + CheckStatus.PASSING.name()); consumer.await(service.getName() + "/" + CheckStatus.CRITICAL.name()); consumer.check(); watch.stop(); runAsync(h -> ctx.writeClient().deregisterService(service.getId(), h)); }
public static ServiceOptions randomServiceOptions() { return new ServiceOptions() .setId(randomAlphaString(10)) .setName(randomAlphaString(10)) .setTags(randomStringList(2)) .setCheckOptions(randomCheckOptions()) .setAddress(randomAlphaString(10)) .setMeta(randomMeta()) .setPort(randomPortInt()); }
.setId(serviceId) .setAddress("10.0.0.1") .setCheckOptions(new CheckOptions().setTtl("1h")) .setPort(8080); runAsync(h -> ctx.writeClient().registerService(service, h));