use of net.jodah.failsafe.CircuitBreaker in project failsafe by jhalterman.
the class HalfOpenStateTest method testSuccessWithSuccessAndFailureThresholds.
/**
* Asserts that the circuit is closed after the success threshold is met. The failure threshold is ignored.
*/
public void testSuccessWithSuccessAndFailureThresholds() {
// 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.recordSuccess();
// Then
assertTrue(breaker.isClosed());
}
use of net.jodah.failsafe.CircuitBreaker in project failsafe by jhalterman.
the class HalfOpenStateTest method testFailureWithSuccessRatioAndFailureThreshold.
/**
* Asserts that the circuit is opened after the success ratio fails to be met. The failure threshold is ignored.
*/
public void testFailureWithSuccessRatioAndFailureThreshold() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withSuccessThreshold(2, 4).withFailureThreshold(1);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
// When
state.recordSuccess();
state.recordFailure();
state.recordFailure();
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 testSuccessWithSuccessRatio.
/**
* Asserts that the circuit is closed after the success ratio is met.
*/
public void testSuccessWithSuccessRatio() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withSuccessThreshold(2, 3);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
// When
state.recordFailure();
state.recordSuccess();
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 testFailureWithDefaultConfig.
/**
* Asserts that the the circuit is opened after a single failure.
*/
public void testFailureWithDefaultConfig() {
// Given
CircuitBreaker breaker = new CircuitBreaker();
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 testFailureWithFailureThreshold.
/**
* Asserts that the the circuit is opened after the failure threshold is met.
*/
public void testFailureWithFailureThreshold() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withFailureThreshold(3);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
// When
for (int i = 0; i < 3; i++) {
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
state.recordFailure();
}
// Then
assertTrue(breaker.isOpen());
}
Aggregations