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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2570 - (show 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 package dk.thoerup.circuitbreaker;
2
3 import static org.junit.Assert.assertTrue;
4
5 import java.io.IOException;
6
7 import org.junit.Before;
8 import org.junit.Test;
9
10 import dk.thoerup.circuitbreaker.config.StaticConfig;
11 import dk.thoerup.circuitbreaker.statistics.AccountingStatistics;
12
13 public class TestAccountingCircuitBreaker {
14 public static final int DELAY = 50;
15 public static final int THRESHOLD = 2;
16
17
18 AccountingStatistics stats;
19 CircuitBreaker acb;
20
21 @Before public void setup() {
22 stats = new AccountingStatistics();
23
24 acb = new CircuitBreaker("test", new StaticConfig(THRESHOLD, DELAY) );
25 acb.setStatistics(stats);
26 }
27
28 @Test public void initialValues() {
29 assertTrue(stats.getBlockCount() == 0);
30 assertTrue(stats.getTotalCallCount() == 0);
31 assertTrue(stats.getTotalFailureCount() == 0);
32 assertTrue(stats.getTripCount() == 0 );
33 }
34
35 @Test public void callCounter() throws Exception{
36 acb.invoke( new SucceedingInvocation() );
37 assertTrue( stats.getTotalCallCount() == 1);
38
39 acb.invoke( new SucceedingInvocation() );
40 assertTrue( stats.getTotalCallCount() == 2);
41 }
42
43 @Test public void testFailing() throws Exception{
44 try{
45 acb.invoke( new FailingInvocation() );
46 } catch (IOException e) {}
47
48 assertTrue( stats.getTotalFailureCount() == 1);
49
50 try{
51 acb.invoke( new FailingInvocation() );
52 } catch (IOException e) {}
53
54 assertTrue( stats.getTripCount() == 1 );
55 assertTrue( stats.getTotalCallCount() == 2 );
56 assertTrue( stats.getTotalFailureCount() == 2);
57 }
58
59 @Test public void testBlockCounter() {
60 assertTrue( stats.getBlockCount() == 0);
61
62 acb.tripBreaker();
63 try {
64 acb.invoke(new SucceedingInvocation() );
65 } catch (Exception e) {}
66
67 assertTrue( stats.getBlockCount() == 1);
68
69
70 }
71 }

  ViewVC Help
Powered by ViewVC 1.1.20