--- CircuitBreaker/test/dk/thoerup/circuitbreaker/TestCircuitBreaker.java 2009/10/19 14:04:40 448 +++ CircuitBreaker/test/dk/thoerup/circuitbreaker/TestCircuitBreaker.java 2009/10/19 20:10:09 449 @@ -36,13 +36,24 @@ cb.invoke( new FailingInvocation() ); } - @Test public void failingTest() throws Throwable { + @Test public void failingTest() { try { cb.invoke( new FailingInvocation() ); }catch (Throwable t) {} assertTrue(cb.getFailureCount() == 1); } + @Test public void failAndResetTest() throws Throwable { + try { + cb.invoke( new FailingInvocation() ); + }catch (Throwable t) {} + + cb.invoke(new SucceedingInvocation() ); //after one good it should reset back to closed + + assertTrue(cb.isClosed()); + assertTrue(cb.getFailureCount() == 0); + } + @Test public void normalOpenTest() throws Throwable { try{ cb.invoke( new FailingInvocation() ); @@ -52,7 +63,21 @@ cb.invoke( new FailingInvocation() ); } catch (IOException e) {} - assertTrue( cb.getStateName().equalsIgnoreCase("open") ); + assertTrue( cb.isOpen() ); + } + + @Test public void forcedResetTest() throws Throwable { + try{ + cb.invoke( new FailingInvocation() ); + } catch (IOException e) {} + + try{ + cb.invoke( new FailingInvocation() ); + } catch (IOException e) {} + + cb.reset(); + + assertTrue( cb.isClosed() ); } }