@Test(timeout = 20000) public void connectOk() throws Exception { CompletableFuture<SocketChannel> accepted = new CompletableFuture<>(); acceptor.submit(() -> { try { accepted.complete(dstSocket.accept()); } catch (Exception ex) { accepted.completeExceptionally(ex); } }); final Collection<MetricGroup> collected; try (TcpCollector tcpCollector = new TcpCollector(dstAddress, GROUP)) { collected = tcpCollector.getGroups(new CompletableFuture<>()); } assertThat(collected, contains( allOf( hasProperty("name", equalTo(GROUP)), hasProperty("metrics", arrayContainingInAnyOrder( allOf(hasProperty("name", equalTo(MetricName.valueOf("up"))), hasProperty("value", equalTo(MetricValue.TRUE))), allOf(hasProperty("name", equalTo(MetricName.valueOf("latency")))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "msg"))), hasProperty("value", equalTo(MetricValue.EMPTY))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "type"))), hasProperty("value", equalTo(MetricValue.fromStrValue(TcpCollector.ConnectResult.OK.toString())))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "timed_out"))), hasProperty("value", equalTo(MetricValue.FALSE))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "no_route_to_host"))), hasProperty("value", equalTo(MetricValue.FALSE))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "port_unreachable"))), hasProperty("value", equalTo(MetricValue.FALSE))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "unknown_host"))), hasProperty("value", equalTo(MetricValue.FALSE))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "unknown_service"))), hasProperty("value", equalTo(MetricValue.FALSE))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "connect_failed"))), hasProperty("value", equalTo(MetricValue.FALSE))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "protocol_error"))), hasProperty("value", equalTo(MetricValue.FALSE))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "bind_failed"))), hasProperty("value", equalTo(MetricValue.FALSE))), allOf(hasProperty("name", equalTo(MetricName.valueOf("error", "io_error"))), hasProperty("value", equalTo(MetricValue.FALSE))) )) ))); assertTrue(accepted.get().isOpen()); accepted.get().close(); }
@Override public Collection<MetricGroup> getGroups(CompletableFuture<TimeoutObject> timeout) { final Thread currentThread = Thread.currentThread(); timeout.thenAccept((timeoutObject) -> currentThread.interrupt()); final ConnectDatum connect = tryConnect(); return singleton(mainGroup(connect)); }
TcpCollector extends SynchronousGroupGenerator { @Override public Collection<MetricGroup> getGroups(CompletableFuture<TimeoutObject> timeout) { final Thread currentThread = Thread.currentThread(); timeout.thenAccept((timeoutObject) -> currentThread.interrupt()); final ConnectDatum connect = tryConnect(); return singleton(mainGroup(connect)); } }
TcpCollector extends SynchronousGroupGenerator { @Override public Collection<MetricGroup> getGroups(CompletableFuture<TimeoutObject> timeout) { final Thread currentThread = Thread.currentThread(); timeout.thenAccept((timeoutObject) -> currentThread.interrupt()); final ConnectDatum connect = tryConnect(); return singleton(mainGroup(connect)); }  }
TcpCollector extends SynchronousGroupGenerator { @Override public Collection<MetricGroup> getGroups(CompletableFuture<TimeoutObject> timeout) { final Thread currentThread = Thread.currentThread(); timeout.thenAccept((timeoutObject) -> currentThread.interrupt()); final ConnectDatum connect = tryConnect(); return singleton(mainGroup(connect)); }  @Override Collection<MetricGroup> getGroups(CompletableFuture<TimeoutObject> timeout); }
TcpCollector extends SynchronousGroupGenerator { @Override public Collection<MetricGroup> getGroups(CompletableFuture<TimeoutObject> timeout) { final Thread currentThread = Thread.currentThread(); timeout.thenAccept((timeoutObject) -> currentThread.interrupt()); final ConnectDatum connect = tryConnect(); return singleton(mainGroup(connect)); }  @Override Collection<MetricGroup> getGroups(CompletableFuture<TimeoutObject> timeout);  }