use of net.jodah.failsafe.internal.HalfOpenState in project failsafe by jhalterman.
the class HalfOpenStateTest method testSuccessWithFailureRatio.
/**
* Asserts that the the circuit is closed after the failure ratio fails to be met.
*/
public void testSuccessWithFailureRatio() {
// Given
CircuitBreaker breaker = new CircuitBreaker().withFailureThreshold(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.internal.HalfOpenState 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.internal.HalfOpenState 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.internal.HalfOpenState 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.internal.HalfOpenState 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());
}
Aggregations