use of net.jodah.failsafe.CircuitBreaker in project failsafe by jhalterman.
the class HalfOpenStateTest method testFailureWithSuccessThresholdAndFailureRatio.
/**
* Asserts that the circuit is opened after a single failure.
*/
public void testFailureWithSuccessThresholdAndFailureRatio() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withFailureThreshold(3, 5).withSuccessThreshold(3);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
// When
state.recordFailure();
// Then
assertTrue(breaker.isOpen());
}
use of net.jodah.failsafe.CircuitBreaker in project failsafe by jhalterman.
the class HalfOpenStateTest method testSuccessWithSuccessRatioAndFailureThreshold.
/**
* Asserts that the circuit is closed after the success ratio is met. The failure threshold is ignored.
*/
public void testSuccessWithSuccessRatioAndFailureThreshold() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withSuccessThreshold(3, 4).withFailureThreshold(2);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
// When
state.recordSuccess();
state.recordSuccess();
state.recordFailure();
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
state.recordSuccess();
// Then
assertTrue(breaker.isClosed());
}
use of net.jodah.failsafe.CircuitBreaker in project failsafe by jhalterman.
the class HalfOpenStateTest method testSuccessWithSuccessThreshold.
/**
* Asserts that the circuit is closed after the success threshold is met.
*/
public void testSuccessWithSuccessThreshold() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withSuccessThreshold(3);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
// When
for (int i = 0; i < 3; i++) {
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
state.recordSuccess();
}
// Then
assertTrue(breaker.isClosed());
}
use of net.jodah.failsafe.CircuitBreaker in project failsafe by jhalterman.
the class HalfOpenStateTest method testFailureWithFailureRatio.
/**
* Asserts that the the circuit is opened after the failure ratio is met.
*/
public void testFailureWithFailureRatio() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withFailureThreshold(2, 3);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
assertFalse(breaker.isOpen());
// When
state.recordFailure();
state.recordSuccess();
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
state.recordFailure();
// Then
assertTrue(breaker.isOpen());
}
use of net.jodah.failsafe.CircuitBreaker in project failsafe by jhalterman.
the class HalfOpenStateTest method testFailureWithSuccessAndFailureThresholds.
/**
* Asserts that the circuit is opened after a single failure. The failure threshold is ignored.
*/
public void testFailureWithSuccessAndFailureThresholds() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withSuccessThreshold(3).withFailureThreshold(2);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
// When
state.recordSuccess();
state.recordSuccess();
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
state.recordFailure();
// Then
assertTrue(breaker.isOpen());
}
Aggregations