--- miscJava/CircuitBreaker/src/test/java/dk/thoerup/circuitbreaker/TestAccountingCircuitBreaker.java 2015/06/09 08:55:10 2569 +++ miscJava/CircuitBreaker/src/test/java/dk/thoerup/circuitbreaker/TestAccountingCircuitBreaker.java 2015/06/09 09:05:26 2570 @@ -8,31 +8,36 @@ import org.junit.Test; import dk.thoerup.circuitbreaker.config.StaticConfig; +import dk.thoerup.circuitbreaker.statistics.AccountingStatistics; public class TestAccountingCircuitBreaker { public static final int DELAY = 50; public static final int THRESHOLD = 2; - AccountingCircuitBreaker acb; + AccountingStatistics stats; + CircuitBreaker acb; @Before public void setup() { - acb = new AccountingCircuitBreaker("test", new StaticConfig(THRESHOLD, DELAY) ); + stats = new AccountingStatistics(); + + acb = new CircuitBreaker("test", new StaticConfig(THRESHOLD, DELAY) ); + acb.setStatistics(stats); } @Test public void initialValues() { - assertTrue(acb.getBlockCount() == 0); - assertTrue(acb.getTotalCallCount() == 0); - assertTrue(acb.getTotalFailureCount() == 0); - assertTrue(acb.getTripCount() == 0 ); + assertTrue(stats.getBlockCount() == 0); + assertTrue(stats.getTotalCallCount() == 0); + assertTrue(stats.getTotalFailureCount() == 0); + assertTrue(stats.getTripCount() == 0 ); } @Test public void callCounter() throws Exception{ acb.invoke( new SucceedingInvocation() ); - assertTrue( acb.getTotalCallCount() == 1); + assertTrue( stats.getTotalCallCount() == 1); acb.invoke( new SucceedingInvocation() ); - assertTrue( acb.getTotalCallCount() == 2); + assertTrue( stats.getTotalCallCount() == 2); } @Test public void testFailing() throws Exception{ @@ -40,26 +45,26 @@ acb.invoke( new FailingInvocation() ); } catch (IOException e) {} - assertTrue( acb.getTotalFailureCount() == 1); + assertTrue( stats.getTotalFailureCount() == 1); try{ acb.invoke( new FailingInvocation() ); } catch (IOException e) {} - assertTrue( acb.getTripCount() == 1 ); - assertTrue( acb.getTotalCallCount() == 2 ); - assertTrue( acb.getTotalFailureCount() == 2); + assertTrue( stats.getTripCount() == 1 ); + assertTrue( stats.getTotalCallCount() == 2 ); + assertTrue( stats.getTotalFailureCount() == 2); } @Test public void testBlockCounter() { - assertTrue( acb.getBlockCount() == 0); + assertTrue( stats.getBlockCount() == 0); acb.tripBreaker(); try { acb.invoke(new SucceedingInvocation() ); } catch (Exception e) {} - assertTrue( acb.getBlockCount() == 1); + assertTrue( stats.getBlockCount() == 1); }