HttpHealthReporter(Vertx vertx) { this.port = Utils.getFreePort(); CountDownLatch latch = new CountDownLatch(1); this.server = vertx.createHttpServer().requestHandler(h -> h.response() .setStatusCode(statusCode(status)) .end(status.name())).listen(port, h -> latch.countDown()); try { latch.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } }
public static void toJson(Check obj, java.util.Map<String, Object> json) { if (obj.getId() != null) { json.put("id", obj.getId()); } if (obj.getName() != null) { json.put("name", obj.getName()); } if (obj.getNodeName() != null) { json.put("nodeName", obj.getNodeName()); } if (obj.getNotes() != null) { json.put("notes", obj.getNotes()); } if (obj.getOutput() != null) { json.put("output", obj.getOutput()); } if (obj.getServiceId() != null) { json.put("serviceId", obj.getServiceId()); } if (obj.getServiceName() != null) { json.put("serviceName", obj.getServiceName()); } if (obj.getStatus() != null) { json.put("status", obj.getStatus().name()); } } }
json.put("status", obj.getStatus().name());
@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)); }