CircuitBreaker implements MonitoredService, ServiceWrapper { public Status getStatus() { return getServiceStatus().getStatus(); } CircuitBreaker();  CircuitBreaker(String name);  CircuitBreaker(FailureInterpreter fi);  CircuitBreaker(String name, FailureInterpreter fi);  CircuitBreaker(String name, CircuitBreakerExceptionMapper<? extends Exception> mapper);  CircuitBreaker(String name,
                          FailureInterpreter fi,
                          CircuitBreakerExceptionMapper<? extends Exception> mapper); Throwable getTripException(); String getTripExceptionAsString(); void setClock(Clock clock); Clock getClock(); V invoke(Callable<V> c); void invoke(Runnable r); V invoke(Runnable r, V result); void setByPassState(boolean b); boolean getByPassState(); void trip(); void tripHard(); long getLastTripTime(); long getTripCount(); void reset(); Status getStatus(); ServiceStatus getServiceStatus(); long getResetMillis(); void setResetMillis(long l); String getHealthCheck(); void setLimit(int limit); void setIgnore(Collection<Class<? extends Throwable>> ignore); void setWindowMillis(long windowMillis); void setFailureInterpreter(FailureInterpreter failureInterpreter); FailureInterpreter getFailureInterpreter(); void setExceptionMapper(CircuitBreakerExceptionMapper<? extends Exception> mapper); void addListener(CircuitBreakerNotificationCallback listener); void setListeners(ArrayList<CircuitBreakerNotificationCallback> listeners); CircuitBreakerExceptionMapper<? extends Exception> getExceptionMapper();  }
@Test public void testOpenAfterCooldownGoesHalfClosed() throws Exception { impl.state = CircuitBreaker.BreakerState.OPEN; impl.resetMillis.set(1000); impl.lastFailure.set(System.currentTimeMillis() - 2000); assertEquals(Status.DEGRADED, impl.getStatus()); assertEquals(CircuitBreaker.BreakerState.HALF_CLOSED, impl.state); }
@Test public void testGetStatusWhenOpen() { impl.state = CircuitBreaker.BreakerState.OPEN; Assert.assertEquals(Status.DOWN, impl.getStatus()); }
@Test public void testGetStatusWhenHalfClosed() { impl.state = CircuitBreaker.BreakerState.HALF_CLOSED; assertEquals(Status.DEGRADED, impl.getStatus()); }
@Test public void testGetStatusWhenOpenBeforeReset() { impl.state = CircuitBreaker.BreakerState.CLOSED; impl.resetMillis.set(1000); impl.lastFailure.set(System.currentTimeMillis() - 50); assertEquals(Status.UP, impl.getStatus()); }
@Test public void testGetStatusWhenOpenAfterReset() { impl.state = CircuitBreaker.BreakerState.OPEN; impl.resetMillis.set(1000); impl.lastFailure.set(System.currentTimeMillis() - 2000); assertEquals(Status.DEGRADED, impl.getStatus()); }