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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 445 - (hide annotations) (download)
Mon Oct 19 13:01:46 2009 UTC (14 years, 7 months ago) by torben
Original Path: CircuitBreaker/test/dk/thoerup/circuitbreaker/TestCircuitBreaker.java
File size: 1402 byte(s)
Code sync ... started test code
1 torben 445 package dk.thoerup.circuitbreaker;
2    
3    
4     import org.junit.*;
5     import static org.junit.Assert.*;
6     import dk.thoerup.curcuitbreaker.*;
7     import java.io.IOException;
8    
9    
10     public class TestCircuitBreaker {
11     class SucceedingInvocation implements CircuitInvocation {
12     public Object proceed() throws Exception {
13     return "OK";
14     }
15     }
16    
17     class FailingInvocation implements CircuitInvocation {
18     public Object proceed() throws Exception {
19     throw new IOException("Error");
20     }
21     }
22    
23     CircuitBreaker cb;
24    
25     @Before public void setup() {
26     cb = new CircuitBreaker("test",2,500);
27     }
28    
29     @Test public void simpleTest() throws Throwable {
30     String retval = (String) cb.invoke( new SucceedingInvocation() );
31     assertEquals(retval, "OK");
32     assertTrue(cb.getFailureCount() == 0);
33     }
34    
35     @Test(expected=IOException.class) public void simpleFailingTest() throws Throwable {
36     cb.invoke( new FailingInvocation() );
37     }
38    
39     @Test public void failingTest() throws Throwable {
40     try {
41     cb.invoke( new FailingInvocation() );
42     }catch (Throwable t) {}
43     assertTrue(cb.getFailureCount() == 1);
44     }
45    
46     @Test public void normalOpenTest() throws Throwable {
47     try{
48     cb.invoke( new FailingInvocation() );
49     } catch (IOException e) {}
50    
51     try{
52     cb.invoke( new FailingInvocation() );
53     } catch (IOException e) {}
54    
55     assertTrue( cb.getStateName().equalsIgnoreCase("open") );
56     }
57    
58     }

  ViewVC Help
Powered by ViewVC 1.1.20