use of net.jodah.failsafe.internal.HalfOpenState 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());
}
use of net.jodah.failsafe.internal.HalfOpenState in project failsafe by jhalterman.
the class HalfOpenStateTest method testFailureWithSuccessAndFailureRatios.
/**
* Asserts that the circuit is opened after the success ratio fails to be met. The failure ratio is ignored.
*/
public void testFailureWithSuccessAndFailureRatios() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withFailureThreshold(3, 5).withSuccessThreshold(3, 4);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
// When
state.recordSuccess();
state.recordFailure();
state.recordSuccess();
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
state.recordFailure();
// Then
assertTrue(breaker.isOpen());
}
use of net.jodah.failsafe.internal.HalfOpenState in project failsafe by jhalterman.
the class HalfOpenStateTest method shouldHandleLateSetFailureRatio.
/**
* Asserts that the late configuration of a failure ratio is handled by resetting the state's internal tracking. Also
* asserts that executions from prior configurations are carried over to a new configuration.
*/
public void shouldHandleLateSetFailureRatio() {
// Given
CircuitBreaker breaker = new CircuitBreaker();
breaker.halfOpen();
HalfOpenState state = Testing.stateFor(breaker);
// When
breaker.withFailureThreshold(2);
state.recordFailure();
assertTrue(breaker.isHalfOpen());
state.recordFailure();
// Then
assertTrue(breaker.isOpen());
// Given
breaker = new CircuitBreaker().withFailureThreshold(3);
breaker.halfOpen();
state = Testing.stateFor(breaker);
// When
state.recordFailure();
state.recordFailure();
breaker.withFailureThreshold(3, 5);
state.recordSuccess();
state.recordSuccess();
assertTrue(breaker.isHalfOpen());
state.recordFailure();
// Then
assertTrue(breaker.isOpen());
}
use of net.jodah.failsafe.internal.HalfOpenState in project failsafe by jhalterman.
the class HalfOpenStateTest method testFailureWithSuccessThreshold.
/**
* Asserts that the circuit is opened after a single failure.
*/
public void testFailureWithSuccessThreshold() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withSuccessThreshold(3);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
// When
state.recordSuccess();
state.recordFailure();
// Then
assertTrue(breaker.isOpen());
}
use of net.jodah.failsafe.internal.HalfOpenState in project failsafe by jhalterman.
the class HalfOpenStateTest method testFailureWithSuccessRatio.
/**
* Asserts that the circuit is opened after the success ratio fails to be met.
*/
public void testFailureWithSuccessRatio() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withSuccessThreshold(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());
}
Aggregations