@Test public void shouldReturnOKResultIfServerIsLeader() { when(distributedStore.nop()).thenReturn(Futures.<Void>immediateFuture(null)); assertThat(check.check().isHealthy(), equalTo(true)); }
@Override protected Result check() { try { ListenableFuture<Void> nopFuture = distributedStore.nop(); nopFuture.get(TIMEOUT, TIMEOUT_TIME_UNIT); return Result.healthy("server is leader"); } catch (TimeoutException e) { return Result.unhealthy(String.format("timed out after attempting to reach cluster for %d %s", TIMEOUT, TIMEOUT_TIME_UNIT)); } catch (ExecutionException e) { if (e.getCause() instanceof NotLeaderException) { NotLeaderException leaderException = (NotLeaderException) e.getCause(); String leader = leaderException.getLeader(); if (leader != null) { return Result.healthy(String.format("server not leader, but cluster has leader: %s", leader)); } else { return Result.unhealthy("cluster does not have a leader"); } } else { return getDefaultUnhealthyResult(e.getCause()); } } catch (Exception e) { return getDefaultUnhealthyResult(e); } }
DistributedStoreCheck extends HealthCheck { @Override protected Result check() { try { ListenableFuture<Void> nopFuture = distributedStore.nop(); nopFuture.get(TIMEOUT, TIMEOUT_TIME_UNIT); return Result.healthy("server is leader"); } catch (TimeoutException e) { return Result.unhealthy(String.format("timed out after attempting to reach cluster for %d %s", TIMEOUT, TIMEOUT_TIME_UNIT)); } catch (ExecutionException e) { if (e.getCause() instanceof NotLeaderException) { NotLeaderException leaderException = (NotLeaderException) e.getCause(); String leader = leaderException.getLeader(); if (leader != null) { return Result.healthy(String.format("server not leader, but cluster has leader: %s", leader)); } else { return Result.unhealthy("cluster does not have a leader"); } } else { return getDefaultUnhealthyResult(e.getCause()); } } catch (Exception e) { return getDefaultUnhealthyResult(e); } } }
DistributedStoreCheck extends HealthCheck { @Override protected Result check() { try { ListenableFuture<Void> nopFuture = distributedStore.nop(); nopFuture.get(TIMEOUT, TIMEOUT_TIME_UNIT); return Result.healthy("server is leader"); } catch (TimeoutException e) { return Result.unhealthy(String.format("timed out after attempting to reach cluster for %d %s", TIMEOUT, TIMEOUT_TIME_UNIT)); } catch (ExecutionException e) { if (e.getCause() instanceof NotLeaderException) { NotLeaderException leaderException = (NotLeaderException) e.getCause(); String leader = leaderException.getLeader(); if (leader != null) { return Result.healthy(String.format("server not leader, but cluster has leader: %s", leader)); } else { return Result.unhealthy("cluster does not have a leader"); } } else { return getDefaultUnhealthyResult(e.getCause()); } } catch (Exception e) { return getDefaultUnhealthyResult(e); } } DistributedStoreCheck(DistributedStore distributedStore); }
DistributedStoreCheck extends HealthCheck { @Override protected Result check() { try { ListenableFuture<Void> nopFuture = distributedStore.nop(); nopFuture.get(TIMEOUT, TIMEOUT_TIME_UNIT); return Result.healthy("server is leader"); } catch (TimeoutException e) { return Result.unhealthy(String.format("timed out after attempting to reach cluster for %d %s", TIMEOUT, TIMEOUT_TIME_UNIT)); } catch (ExecutionException e) { if (e.getCause() instanceof NotLeaderException) { NotLeaderException leaderException = (NotLeaderException) e.getCause(); String leader = leaderException.getLeader(); if (leader != null) { return Result.healthy(String.format("server not leader, but cluster has leader: %s", leader)); } else { return Result.unhealthy("cluster does not have a leader"); } } else { return getDefaultUnhealthyResult(e.getCause()); } } catch (Exception e) { return getDefaultUnhealthyResult(e); } } DistributedStoreCheck(DistributedStore distributedStore);  }
DistributedStoreCheck extends HealthCheck { @Override protected Result check() { try { ListenableFuture<Void> nopFuture = distributedStore.nop(); nopFuture.get(TIMEOUT, TIMEOUT_TIME_UNIT); return Result.healthy("server is leader"); } catch (TimeoutException e) { return Result.unhealthy(String.format("timed out after attempting to reach cluster for %d %s", TIMEOUT, TIMEOUT_TIME_UNIT)); } catch (ExecutionException e) { if (e.getCause() instanceof NotLeaderException) { NotLeaderException leaderException = (NotLeaderException) e.getCause(); String leader = leaderException.getLeader(); if (leader != null) { return Result.healthy(String.format("server not leader, but cluster has leader: %s", leader)); } else { return Result.unhealthy("cluster does not have a leader"); } } else { return getDefaultUnhealthyResult(e.getCause()); } } catch (Exception e) { return getDefaultUnhealthyResult(e); } } DistributedStoreCheck(DistributedStore distributedStore);   }