Skip to content

Commit

Permalink
Fixes issue ReactiveX#6: The CB changes to OPEN state when the failur…
Browse files Browse the repository at this point in the history
…e rate is above (>) the threshold, but it should be above or equal (>=).
  • Loading branch information
Robert Winkler committed Apr 7, 2016
1 parent 31f313a commit 37ed77c
Showing 1 changed file with 0 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@

import javaslang.circuitbreaker.CircuitBreaker;
import javaslang.circuitbreaker.CircuitBreakerConfig;
import javaslang.circuitbreaker.CircuitBreakerRegistry;
import org.junit.Before;
import org.junit.Test;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;
import static org.assertj.core.api.BDDAssertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class CircuitBreakerStateMachineTest {

Expand Down Expand Up @@ -163,22 +159,4 @@ public void testCircuitBreakerStateMachine() throws InterruptedException {
assertThat(circuitBreaker.getMetrics().getNumberOfFailedCalls()).isEqualTo(0);
assertThat(circuitBreaker.getMetrics().getFailureRate()).isEqualTo(-1f);
}

@Test
public void testCircuitBreakerBehaviour() throws InterruptedException {
CircuitBreakerRegistry registry = CircuitBreakerRegistry.ofDefaults();
int times = 3;
int waitSeconds = 2;
CircuitBreakerConfig config = CircuitBreakerConfig.custom().ringBufferSizeInHalfOpenState(times)
.failureRateThreshold(100).ringBufferSizeInClosedState(times)
.waitDurationInOpenState(Duration.ofSeconds(waitSeconds)).build();
CircuitBreaker circuitBreaker = registry.circuitBreaker("something", config);
for (int i = 0; i < times; i++) {
assertTrue("Circuit-breaker call should be permitted", circuitBreaker.isCallPermitted());
circuitBreaker.recordFailure(new RuntimeException("Fail! " + i));
}
assertFalse("Circuit-breaker call should not be permitted", circuitBreaker.isCallPermitted());
Thread.sleep(TimeUnit.SECONDS.toMillis(waitSeconds));
assertTrue("Circuit-breaker call should be permitted", circuitBreaker.isCallPermitted());
}
}

0 comments on commit 37ed77c

Please sign in to comment.