--- CircuitBreaker/test/dk/thoerup/circuitbreaker/TestCircuitBreaker.java 2009/10/20 10:47:36 452 +++ CircuitBreaker/test/dk/thoerup/circuitbreaker/TestCircuitBreaker.java 2009/10/21 07:52:08 459 @@ -12,7 +12,7 @@ import dk.thoerup.curcuitbreaker.CircuitBreaker; import dk.thoerup.curcuitbreaker.CircuitBreakerException; import dk.thoerup.curcuitbreaker.CircuitInvocation; -import dk.thoerup.curcuitbreaker.notification.SystemOutNotifier; + public class TestCircuitBreaker { @@ -36,7 +36,6 @@ @Before public void setup() { cb = new CircuitBreaker("test", THRESHOLD, DELAY); - cb.setNotifier( new SystemOutNotifier() ); } @Test public void defaultState() { @@ -86,6 +85,12 @@ assertTrue( cb.isOpen() ); } + @Test public void forcedTrip() { + assertTrue( cb.isClosed() ); + cb.tripBreaker(); + assertTrue( cb.isOpen() ); + } + @Test public void forcedResetTest() throws Exception { try{ cb.invoke( new FailingInvocation() ); @@ -95,10 +100,10 @@ cb.invoke( new FailingInvocation() ); } catch (IOException e) {} - cb.reset(); - + cb.reset(); + assertTrue( cb.isClosed() ); - assertTrue( cb.getFailureCount() == 0 ); //currently an externally triggered reset doesn't reset failure count - should a forced reset be possible at all ? + assertTrue( cb.getFailureCount() == 0 ); } @@ -130,7 +135,7 @@ assertTrue( cb.isOpen() ); Thread.sleep(DELAY*2); - cb.invoke( new FailingInvocation() ); //in half open this will cause a CircuitBreakerException + cb.invoke( new FailingInvocation() ); //in half-open this will cause a CircuitBreakerException, as if it was in open mode } @Test public void halfOpen3() throws Exception { @@ -140,10 +145,10 @@ Thread.sleep(DELAY*2); try{ - cb.invoke( new FailingInvocation() ); + cb.invoke( new FailingInvocation() ); } catch (CircuitBreakerException e) {} - assertTrue( cb.isOpen() ); + assertTrue( cb.isOpen() ); //after failing in half-open go back to open }