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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1315 - (show annotations) (download)
Tue Apr 19 17:13:40 2011 UTC (13 years, 1 month ago) by torben
File size: 1651 byte(s)
And adapt tests to BreakerConfig
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
12 public class TestAccountingCircuitBreaker {
13 public static final int DELAY = 50;
14 public static final int THRESHOLD = 2;
15
16
17 AccountingCircuitBreaker acb;
18
19 @Before public void setup() {
20 acb = new AccountingCircuitBreaker("test", new StaticConfig(THRESHOLD, DELAY) );
21 }
22
23 @Test public void initialValues() {
24 assertTrue(acb.getBlockCount() == 0);
25 assertTrue(acb.getTotalCallCount() == 0);
26 assertTrue(acb.getTotalFailureCount() == 0);
27 assertTrue(acb.getTripCount() == 0 );
28 }
29
30 @Test public void callCounter() throws Exception{
31 acb.invoke( new SucceedingInvocation() );
32 assertTrue( acb.getTotalCallCount() == 1);
33
34 acb.invoke( new SucceedingInvocation() );
35 assertTrue( acb.getTotalCallCount() == 2);
36 }
37
38 @Test public void testFailing() throws Exception{
39 try{
40 acb.invoke( new FailingInvocation() );
41 } catch (IOException e) {}
42
43 assertTrue( acb.getTotalFailureCount() == 1);
44
45 try{
46 acb.invoke( new FailingInvocation() );
47 } catch (IOException e) {}
48
49 assertTrue( acb.getTripCount() == 1 );
50 assertTrue( acb.getTotalCallCount() == 2 );
51 assertTrue( acb.getTotalFailureCount() == 2);
52 }
53
54 @Test public void testBlockCounter() {
55 assertTrue( acb.getBlockCount() == 0);
56
57 acb.tripBreaker();
58 try {
59 acb.invoke(new SucceedingInvocation() );
60 } catch (Exception e) {}
61
62 assertTrue( acb.getBlockCount() == 1);
63
64
65 }
66 }

  ViewVC Help
Powered by ViewVC 1.1.20