Skip to content

Instantly share code, notes, and snippets.

@xlucasdemelo
Created May 26, 2020 22:52
Show Gist options
  • Save xlucasdemelo/20fac1a4c63062aad4a2d4a0a7be48cc to your computer and use it in GitHub Desktop.
Save xlucasdemelo/20fac1a4c63062aad4a2d4a0a7be48cc to your computer and use it in GitHub Desktop.
@Test
public void circuitBreaker_recover(){
MockResponse mockResponse = new MockResponse()
.setResponseCode(500)
.addHeader("Content-Type", "application/json;charset=utf-8");
CircuitBreaker circuitBreaker = CircuitBreaker.of("books", CircuitBreakerConfig.custom()
.slidingWindowSize(1)
.waitDurationInOpenState(Duration.ofMillis(100))
.build());
this.captureEvents(circuitBreaker.getEventPublisher());
Supplier<String> withCircuitBreaker = CircuitBreaker.decorateSupplier(circuitBreaker, bookClient::findAll);
this.enqueue(1, mockResponse);
String result = Try.ofSupplier(withCircuitBreaker)
.recoverWith(throwable -> Try.of(this::sendToQueue)).get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment