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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 452 by torben, Tue Oct 20 10:47:36 2009 UTC revision 459 by torben, Wed Oct 21 07:52:08 2009 UTC
# Line 12  import org.junit.Test; Line 12  import org.junit.Test;
12  import dk.thoerup.curcuitbreaker.CircuitBreaker;  import dk.thoerup.curcuitbreaker.CircuitBreaker;
13  import dk.thoerup.curcuitbreaker.CircuitBreakerException;  import dk.thoerup.curcuitbreaker.CircuitBreakerException;
14  import dk.thoerup.curcuitbreaker.CircuitInvocation;  import dk.thoerup.curcuitbreaker.CircuitInvocation;
15  import dk.thoerup.curcuitbreaker.notification.SystemOutNotifier;  
16    
17    
18  public class TestCircuitBreaker {  public class TestCircuitBreaker {
# Line 36  public class TestCircuitBreaker { Line 36  public class TestCircuitBreaker {
36                    
37          @Before public void setup() {          @Before public void setup() {
38                  cb = new CircuitBreaker("test", THRESHOLD, DELAY);                  cb = new CircuitBreaker("test", THRESHOLD, DELAY);
                 cb.setNotifier( new SystemOutNotifier() );  
39          }          }
40                    
41          @Test public void defaultState() {          @Test public void defaultState() {
# Line 86  public class TestCircuitBreaker { Line 85  public class TestCircuitBreaker {
85                  assertTrue( cb.isOpen() );                                assertTrue( cb.isOpen() );              
86          }          }
87                    
88            @Test public void forcedTrip() {
89                    assertTrue( cb.isClosed() );
90                    cb.tripBreaker();
91                    assertTrue( cb.isOpen() );
92            }
93            
94          @Test public void forcedResetTest() throws Exception {          @Test public void forcedResetTest() throws Exception {
95                  try{                  try{
96                          cb.invoke( new FailingInvocation() );                          cb.invoke( new FailingInvocation() );
# Line 95  public class TestCircuitBreaker { Line 100  public class TestCircuitBreaker {
100                          cb.invoke( new FailingInvocation() );                          cb.invoke( new FailingInvocation() );
101                  } catch (IOException e) {}                  } catch (IOException e) {}
102                                    
103                  cb.reset();                  cb.reset();
104                    
105                  assertTrue( cb.isClosed() );                  assertTrue( cb.isClosed() );
106                  assertTrue( cb.getFailureCount() == 0 ); //currently an externally triggered reset doesn't reset failure count - should a forced reset be possible at all ?                  assertTrue( cb.getFailureCount() == 0 );
107          }          }
108    
109    
# Line 130  public class TestCircuitBreaker { Line 135  public class TestCircuitBreaker {
135                  assertTrue( cb.isOpen() );                  assertTrue( cb.isOpen() );
136                  Thread.sleep(DELAY*2);                  Thread.sleep(DELAY*2);
137                                    
138                  cb.invoke( new FailingInvocation() ); //in half open this will cause a CircuitBreakerException                            cb.invoke( new FailingInvocation() ); //in half-open this will cause a CircuitBreakerException, as if it was in open mode              
139          }          }
140                    
141          @Test public void halfOpen3() throws Exception {          @Test public void halfOpen3() throws Exception {
# Line 140  public class TestCircuitBreaker { Line 145  public class TestCircuitBreaker {
145                  Thread.sleep(DELAY*2);                  Thread.sleep(DELAY*2);
146                                    
147                  try{                  try{
148                          cb.invoke( new FailingInvocation() );                          cb.invoke( new FailingInvocation() );
149                  } catch (CircuitBreakerException e) {}                  } catch (CircuitBreakerException e) {}
150    
151                  assertTrue( cb.isOpen() );                  assertTrue( cb.isOpen() ); //after failing in half-open go back to open
152          }          }
153    
154                    

Legend:
Removed from v.452  
changed lines
  Added in v.459

  ViewVC Help
Powered by ViewVC 1.1.20