Java Code Examples for net.jodah.failsafe.CircuitBreaker#getDelay()
The following examples show how to use
net.jodah.failsafe.CircuitBreaker#getDelay() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenStateTest.java From failsafe with Apache License 2.0 | 5 votes |
public void testAllowsExecution() throws Throwable { // Given CircuitBreaker breaker = new CircuitBreaker().withDelay(Duration.ofMillis(100)); breaker.open(); OpenState state = new OpenState(breaker, new ClosedState(breaker, Testing.getInternals(breaker)), breaker.getDelay()); assertTrue(breaker.isOpen()); assertFalse(state.allowsExecution()); // When Thread.sleep(110); // Then assertTrue(state.allowsExecution()); assertEquals(breaker.getState(), State.HALF_OPEN); }
Example 2
Source File: OpenStateTest.java From failsafe with Apache License 2.0 | 5 votes |
public void testRemainingDelay() throws Throwable { // Given CircuitBreaker breaker = new CircuitBreaker().withDelay(Duration.ofSeconds(1)); OpenState state = new OpenState(breaker, new ClosedState(breaker, Testing.getInternals(breaker)), breaker.getDelay()); // When / Then long remainingDelayMillis = state.getRemainingDelay().toMillis(); assertTrue(remainingDelayMillis < 1000); assertTrue(remainingDelayMillis > 0); Thread.sleep(110); remainingDelayMillis = state.getRemainingDelay().toMillis(); assertTrue(remainingDelayMillis < 900); assertTrue(remainingDelayMillis > 0); }
Example 3
Source File: OpenStateTest.java From failsafe with Apache License 2.0 | 5 votes |
public void testNoRemainingDelay() throws Throwable { // Given CircuitBreaker breaker = new CircuitBreaker().withDelay(Duration.ofMillis(10)); assertEquals(breaker.getRemainingDelay(), Duration.ZERO); // When OpenState state = new OpenState(breaker, new ClosedState(breaker, Testing.getInternals(breaker)), breaker.getDelay()); Thread.sleep(50); // Then assertEquals(state.getRemainingDelay().toMillis(), 0); }