/[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 467 - (show annotations) (download)
Thu Oct 22 06:01:35 2009 UTC (14 years, 7 months ago) by torben
File size: 1597 byte(s)
Rename package
1 package dk.thoerup.circuitbreaker;
2
3 import java.io.IOException;
4
5 import org.junit.*;
6 import static org.junit.Assert.*;
7
8 import dk.thoerup.circuitbreaker.AccountingCircuitBreaker;
9
10 public class TestAccountingCircuitBreaker {
11 public static final int DELAY = 50;
12 public static final int THRESHOLD = 2;
13
14
15 AccountingCircuitBreaker acb;
16
17 @Before public void setup() {
18 acb = new AccountingCircuitBreaker("test", THRESHOLD, DELAY);
19 }
20
21 @Test public void initialValues() {
22 assertTrue(acb.getBlockCount() == 0);
23 assertTrue(acb.getTotalCallCount() == 0);
24 assertTrue(acb.getTotalFailureCount() == 0);
25 assertTrue(acb.getTripCount() == 0 );
26 }
27
28 @Test public void callCounter() throws Exception{
29 acb.invoke( new SucceedingInvocation() );
30 assertTrue( acb.getTotalCallCount() == 1);
31
32 acb.invoke( new SucceedingInvocation() );
33 assertTrue( acb.getTotalCallCount() == 2);
34 }
35
36 @Test public void testFailing() throws Exception{
37 try{
38 acb.invoke( new FailingInvocation() );
39 } catch (IOException e) {}
40
41 assertTrue( acb.getTotalFailureCount() == 1);
42
43 try{
44 acb.invoke( new FailingInvocation() );
45 } catch (IOException e) {}
46
47 assertTrue( acb.getTripCount() == 1 );
48 assertTrue( acb.getTotalCallCount() == 2 );
49 assertTrue( acb.getTotalFailureCount() == 2);
50 }
51
52 @Test public void testBlockCounter() {
53 assertTrue( acb.getBlockCount() == 0);
54
55 acb.tripBreaker();
56 try {
57 acb.invoke(new SucceedingInvocation() );
58 } catch (Exception e) {}
59
60 assertTrue( acb.getBlockCount() == 1);
61
62
63 }
64 }

  ViewVC Help
Powered by ViewVC 1.1.20