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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2570 - (hide annotations) (download)
Tue Jun 9 09:05:26 2015 UTC (8 years, 11 months ago) by torben
File size: 1824 byte(s)
Remove old/deprecated inherited circuitbreakers
1 torben 463 package dk.thoerup.circuitbreaker;
2    
3 torben 1315 import static org.junit.Assert.assertTrue;
4    
5 torben 463 import java.io.IOException;
6    
7 torben 1315 import org.junit.Before;
8     import org.junit.Test;
9 torben 463
10 torben 1315 import dk.thoerup.circuitbreaker.config.StaticConfig;
11 torben 2570 import dk.thoerup.circuitbreaker.statistics.AccountingStatistics;
12 torben 463
13     public class TestAccountingCircuitBreaker {
14     public static final int DELAY = 50;
15     public static final int THRESHOLD = 2;
16    
17    
18 torben 2570 AccountingStatistics stats;
19     CircuitBreaker acb;
20 torben 463
21     @Before public void setup() {
22 torben 2570 stats = new AccountingStatistics();
23    
24     acb = new CircuitBreaker("test", new StaticConfig(THRESHOLD, DELAY) );
25     acb.setStatistics(stats);
26 torben 463 }
27    
28     @Test public void initialValues() {
29 torben 2570 assertTrue(stats.getBlockCount() == 0);
30     assertTrue(stats.getTotalCallCount() == 0);
31     assertTrue(stats.getTotalFailureCount() == 0);
32     assertTrue(stats.getTripCount() == 0 );
33 torben 463 }
34    
35     @Test public void callCounter() throws Exception{
36     acb.invoke( new SucceedingInvocation() );
37 torben 2570 assertTrue( stats.getTotalCallCount() == 1);
38 torben 463
39     acb.invoke( new SucceedingInvocation() );
40 torben 2570 assertTrue( stats.getTotalCallCount() == 2);
41 torben 463 }
42    
43     @Test public void testFailing() throws Exception{
44     try{
45     acb.invoke( new FailingInvocation() );
46     } catch (IOException e) {}
47    
48 torben 2570 assertTrue( stats.getTotalFailureCount() == 1);
49 torben 463
50     try{
51     acb.invoke( new FailingInvocation() );
52     } catch (IOException e) {}
53    
54 torben 2570 assertTrue( stats.getTripCount() == 1 );
55     assertTrue( stats.getTotalCallCount() == 2 );
56     assertTrue( stats.getTotalFailureCount() == 2);
57 torben 463 }
58    
59     @Test public void testBlockCounter() {
60 torben 2570 assertTrue( stats.getBlockCount() == 0);
61 torben 463
62     acb.tripBreaker();
63     try {
64     acb.invoke(new SucceedingInvocation() );
65     } catch (Exception e) {}
66    
67 torben 2570 assertTrue( stats.getBlockCount() == 1);
68 torben 463
69    
70     }
71     }

  ViewVC Help
Powered by ViewVC 1.1.20