/[projects]/miscJava/CircuitBreaker/src/test/java/dk/thoerup/circuitbreaker/TestAccountingCircuitBreaker.java
ViewVC logotype

Diff of /miscJava/CircuitBreaker/src/test/java/dk/thoerup/circuitbreaker/TestAccountingCircuitBreaker.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2569 by torben, Fri Mar 20 08:58:46 2015 UTC revision 2570 by torben, Tue Jun 9 09:05:26 2015 UTC
# Line 8  import org.junit.Before; Line 8  import org.junit.Before;
8  import org.junit.Test;  import org.junit.Test;
9    
10  import dk.thoerup.circuitbreaker.config.StaticConfig;  import dk.thoerup.circuitbreaker.config.StaticConfig;
11    import dk.thoerup.circuitbreaker.statistics.AccountingStatistics;
12    
13  public class TestAccountingCircuitBreaker {  public class TestAccountingCircuitBreaker {
14          public static final int DELAY = 50;          public static final int DELAY = 50;
15          public static final int THRESHOLD = 2;          public static final int THRESHOLD = 2;
16                    
17                    
18          AccountingCircuitBreaker acb;          AccountingStatistics stats;
19            CircuitBreaker acb;
20                    
21          @Before public void setup() {          @Before public void setup() {
22                  acb = new AccountingCircuitBreaker("test", new StaticConfig(THRESHOLD, DELAY) );                  stats = new AccountingStatistics();
23                    
24                    acb = new CircuitBreaker("test", new StaticConfig(THRESHOLD, DELAY) );
25                    acb.setStatistics(stats);
26          }          }
27                    
28          @Test public void initialValues() {          @Test public void initialValues() {
29                  assertTrue(acb.getBlockCount() == 0);                  assertTrue(stats.getBlockCount() == 0);
30                  assertTrue(acb.getTotalCallCount() == 0);                  assertTrue(stats.getTotalCallCount() == 0);
31                  assertTrue(acb.getTotalFailureCount() == 0);                  assertTrue(stats.getTotalFailureCount() == 0);
32                  assertTrue(acb.getTripCount() == 0 );                  assertTrue(stats.getTripCount() == 0 );
33          }          }
34                    
35          @Test public void callCounter() throws Exception{          @Test public void callCounter() throws Exception{
36                  acb.invoke( new SucceedingInvocation() );                  acb.invoke( new SucceedingInvocation() );
37                  assertTrue( acb.getTotalCallCount() == 1);                  assertTrue( stats.getTotalCallCount() == 1);
38                                    
39                  acb.invoke( new SucceedingInvocation() );                  acb.invoke( new SucceedingInvocation() );
40                  assertTrue( acb.getTotalCallCount() == 2);                                assertTrue( stats.getTotalCallCount() == 2);            
41          }          }
42                    
43          @Test public void testFailing() throws Exception{          @Test public void testFailing() throws Exception{
# Line 40  public class TestAccountingCircuitBreake Line 45  public class TestAccountingCircuitBreake
45                          acb.invoke( new FailingInvocation() );                          acb.invoke( new FailingInvocation() );
46                  } catch (IOException e) {}                  } catch (IOException e) {}
47                                    
48                  assertTrue( acb.getTotalFailureCount() == 1);                  assertTrue( stats.getTotalFailureCount() == 1);
49                                    
50                  try{                  try{
51                          acb.invoke( new FailingInvocation() );                          acb.invoke( new FailingInvocation() );
52                  } catch (IOException e) {}                  } catch (IOException e) {}
53                                    
54                  assertTrue( acb.getTripCount() == 1 );                  assertTrue( stats.getTripCount() == 1 );
55                  assertTrue( acb.getTotalCallCount() == 2 );                  assertTrue( stats.getTotalCallCount() == 2 );
56                  assertTrue( acb.getTotalFailureCount() == 2);                  assertTrue( stats.getTotalFailureCount() == 2);
57          }          }
58                    
59          @Test public void testBlockCounter() {          @Test public void testBlockCounter() {
60                  assertTrue( acb.getBlockCount() == 0);                  assertTrue( stats.getBlockCount() == 0);
61                                    
62                  acb.tripBreaker();                  acb.tripBreaker();
63                  try {                  try {
64                          acb.invoke(new SucceedingInvocation() );                          acb.invoke(new SucceedingInvocation() );
65                  } catch (Exception e) {}                  } catch (Exception e) {}
66                                    
67                  assertTrue( acb.getBlockCount() == 1);                  assertTrue( stats.getBlockCount() == 1);
68                                    
69                                    
70          }          }

Legend:
Removed from v.2569  
changed lines
  Added in v.2570

  ViewVC Help
Powered by ViewVC 1.1.20