GaugeHealthCheck extends HealthCheck { @Override protected Result check() throws Exception { final T value = gauge.getValue(); if (alwaysHealthy.contains(value)) { return Result.healthy(); } return ceiling.map(value::compareTo).orElse(-1) < 0 ? Result.healthy() : Result.unhealthy(getUnhealthyMessage(value)); } GaugeHealthCheck(Gauge<T> gauge, Optional<T> ceiling, Set<T> alwaysHealthy);  GaugeHealthCheck(Gauge<T> gauge, Optional<T> ceiling);   }
@Test public void testNaN() throws Exception { when(doubleGauge.getValue()).thenReturn(Double.NaN); healthCheck = HealthChecks.forDoubleGauge(doubleGauge, Optional.of(5d)); assertTrue(healthCheck.check().isHealthy()); }
@Test public void testRegularGauge() throws Exception { when(stringGauge.getValue()).thenReturn("foobarbaz"); stringHealthCheck = HealthChecks.forGauge(stringGauge, Optional.of("foobarbazzz")); assertTrue(stringHealthCheck.check().isHealthy()); }
@Test public void testRegularGaugeUnhealthy() throws Exception { when(stringGauge.getValue()).thenReturn("foobarbaz"); stringHealthCheck = HealthChecks.forGauge(stringGauge, Optional.of("abc")); assertFalse(stringHealthCheck.check().isHealthy()); }
@Test public void testHealthy() throws Exception { when(doubleGauge.getValue()).thenReturn(3d); healthCheck = HealthChecks.forDoubleGauge(doubleGauge, Optional.of(5d)); assertTrue(healthCheck.check().isHealthy()); }
@Test public void testHealthyWithoutCeiling() throws Exception { when(doubleGauge.getValue()).thenReturn(3d); healthCheck = HealthChecks.forDoubleGauge(doubleGauge, Optional.empty()); assertTrue(healthCheck.check().isHealthy()); }
@Test public void testUnhealthyAtCeiling() throws Exception { when(doubleGauge.getValue()).thenReturn(5d); healthCheck = HealthChecks.forDoubleGauge(doubleGauge, Optional.of(5d)); assertFalse(healthCheck.check().isHealthy()); }
@Test public void testUnhealthy() throws Exception { when(doubleGauge.getValue()).thenReturn(10d); healthCheck = HealthChecks.forDoubleGauge(doubleGauge, Optional.of(5d)); assertFalse(healthCheck.check().isHealthy()); }