use of net.jodah.failsafe.internal.HalfOpenState in project failsafe by jhalterman.
the class HalfOpenStateTest method testSuccessWithDefaultConfig.
/**
* Asserts that the the circuit is closed after a single success.
*/
public void testSuccessWithDefaultConfig() {
// Given
CircuitBreaker breaker = new CircuitBreaker();
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
// When
state.recordSuccess();
// Then
assertTrue(breaker.isClosed());
}
use of net.jodah.failsafe.internal.HalfOpenState in project failsafe by jhalterman.
the class HalfOpenStateTest method testSuccessWithSuccessAndFailureRatios.
/**
* Asserts that the circuit is closed after the success ratio is met. The failure ratio is ignored.
*/
public void testSuccessWithSuccessAndFailureRatios() {
// 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.recordSuccess();
// Then
assertTrue(breaker.isClosed());
}
use of net.jodah.failsafe.internal.HalfOpenState in project failsafe by jhalterman.
the class HalfOpenStateTest method testSuccessWithFailureThreshold.
/**
* Asserts that the the circuit is closed after a single success.
*/
public void testSuccessWithFailureThreshold() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withFailureThreshold(3);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
// When
state.recordFailure();
state.recordSuccess();
// Then
assertTrue(breaker.isClosed());
}
use of net.jodah.failsafe.internal.HalfOpenState in project failsafe by jhalterman.
the class HalfOpenStateTest method shouldHandleLateSetSucessRatio.
/**
* Asserts that the late configuration of a success 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 shouldHandleLateSetSucessRatio() {
// Given
CircuitBreaker breaker = new CircuitBreaker();
breaker.halfOpen();
HalfOpenState state = Testing.stateFor(breaker);
// When
breaker.withSuccessThreshold(2);
state.recordSuccess();
assertTrue(breaker.isHalfOpen());
state.recordSuccess();
// Then
assertTrue(breaker.isClosed());
// Given
breaker = new CircuitBreaker().withFailureThreshold(3);
breaker.halfOpen();
state = Testing.stateFor(breaker);
// When
state.recordFailure();
state.recordFailure();
breaker.withSuccessThreshold(2, 4);
state.recordSuccess();
assertTrue(breaker.isHalfOpen());
state.recordSuccess();
// Then
assertTrue(breaker.isClosed());
}
use of net.jodah.failsafe.internal.HalfOpenState in project failsafe by jhalterman.
the class HalfOpenStateTest method testSuccessWithSuccessThresholdAndFailureRatio.
/**
* Asserts that the circuit is closed after the success threshold is met. The failure ratio is ignored.
*/
public void testSuccessWithSuccessThresholdAndFailureRatio() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withFailureThreshold(3, 5).withSuccessThreshold(2);
breaker.halfOpen();
HalfOpenState state = new HalfOpenState(breaker);
// When success threshold exceeded
state.recordSuccess();
assertFalse(breaker.isOpen());
assertFalse(breaker.isClosed());
state.recordSuccess();
// Then
assertTrue(breaker.isClosed());
}
Aggregations