Source:
public void before() throws Throwable { super.before(); Polling.awaitUnchecked(30, TimeUnit.SECONDS, new Callable<Boolean>() { @Override public Boolean call() throws Exception { final URI uri = Iterables.getOnlyElement(deployment.uris()); final SocketAddress address = new InetSocketAddress(uri.getHost(), uri.getPort()); log.debug("attempting to connect to {}", address); try { final Socket s = new Socket(); s.connect(address, 100); log.info("successfully connected to address for {}", address, deployment); return true; } catch (SocketTimeoutException | ConnectException e) { log.debug("could not yet connect to HeliosDeployment: {}", e.toString()); return null; } } }); final HeliosClient client = client(); Polling.awaitUnchecked(30, TimeUnit.SECONDS, new Callable<Boolean>() { @Override public Boolean call() throws Exception { final ListenableFuture<List<String>> future = client.listHosts(); final List<String> hosts; try { hosts = future.get(1, TimeUnit.SECONDS); } catch (TimeoutException | InterruptedException e) { log.debug("timed out waiting for listHosts request to finish, will retry"); return null; } if (hosts.isEmpty()) { log.debug("0 agents in {}, will retry", deployment); return null; } final ListenableFuture<Map<String, HostStatus>> statusFuture = client.hostStatuses(hosts); final Map<String, HostStatus> hostStatuses; try { hostStatuses = statusFuture.get(1, TimeUnit.SECONDS); } catch (TimeoutException | InterruptedException e) { log.debug("timed out waiting for hostStatuses to finish, will retry"); return null; } for (final HostStatus hostStatus : hostStatuses.values()) { if (hostStatus != null && hostStatus.getStatus() == HostStatus.Status.UP) { log.info("Ensured that at least one agent is UP in this HeliosDeployment, " + "continuing with test!"); return true; } } return null; } }); }

Target:
public void before() throws Throwable { super.before(); final HeliosClient client = client(); Polling.awaitUnchecked(30, TimeUnit.SECONDS, new Callable<Boolean>() { @Override public Boolean call() throws Exception { try { client.listMasters().get(); log.info("successfully connected to helios master"); return true; } catch (final Exception e) { log.debug("could not yet connect to HeliosDeployment: {}", e.toString()); return null; } } }); Polling.awaitUnchecked(30, TimeUnit.SECONDS, new Callable<Boolean>() { @Override public Boolean call() throws Exception { final ListenableFuture<List<String>> future = client.listHosts(); final List<String> hosts; try { hosts = future.get(1, TimeUnit.SECONDS); } catch (TimeoutException | InterruptedException e) { log.debug("timed out waiting for listHosts request to finish, will retry"); return null; } if (hosts.isEmpty()) { log.debug("0 agents in {}, will retry", deployment); return null; } final ListenableFuture<Map<String, HostStatus>> statusFuture = client.hostStatuses(hosts); final Map<String, HostStatus> hostStatuses; try { hostStatuses = statusFuture.get(1, TimeUnit.SECONDS); } catch (TimeoutException | InterruptedException e) { log.debug("timed out waiting for hostStatuses to finish, will retry"); return null; } for (final HostStatus hostStatus : hostStatuses.values()) { if (hostStatus != null && hostStatus.getStatus() == HostStatus.Status.UP) { log.info("Ensured that at least one agent is UP in this HeliosDeployment, " + "continuing with test!"); return true; } } return null; } }); }