@Test
public void testHalfClosedFailureOpensAgain()
        throws Exception {

    impl.state = CircuitBreaker.BreakerState.HALF_CLOSED;
    impl.resetMillis.set(1000);
    impl.lastFailure.set(System.currentTimeMillis() - 2000);
    long start = System.currentTimeMillis();
    expect(mockCallable.call()).andThrow(new RuntimeException());
    replay(mockCallable);
    try {
        impl.invoke(mockCallable);
        fail("should have thrown exception");
    } catch (RuntimeException expected) {
    }
    long end = System.currentTimeMillis();
    verify(mockCallable);
    assertEquals(CircuitBreaker.BreakerState.OPEN, impl.state);
    assertTrue(impl.lastFailure.get() >= start);
    assertTrue(impl.lastFailure.get() <= end);
}