This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lucasaguiar.resilience; | |
import io.github.resilience4j.timelimiter.TimeLimiter; | |
import io.github.resilience4j.timelimiter.TimeLimiterConfig; | |
import io.vavr.control.Try; | |
import org.assertj.core.api.Assertions; | |
import org.junit.jupiter.api.Test; | |
import java.time.Duration; | |
import java.util.concurrent.Callable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void countBased_example() throws Exception { | |
MockResponse mockResponse = new MockResponse() | |
.setResponseCode(500) | |
.addHeader("Content-Type", "application/json;charset=utf-8"); | |
CircuitBreaker circuitBreaker = CircuitBreaker.of("books", CircuitBreakerConfig.custom() | |
.slidingWindowSize(4) | |
.permittedNumberOfCallsInHalfOpenState(2) | |
.waitDurationInOpenState(Duration.ofMillis(100)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void retry(){ | |
MockResponse mockResponse = new MockResponse() | |
.setResponseCode(500) | |
.addHeader("Content-Type", "application/json;charset=utf-8"); | |
MockResponse mockResponseSuccess = new MockResponse() | |
.setResponseCode(200) | |
.addHeader("Content-Type", "application/json;charset=utf-8"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void threadPoolBulkhead() throws InterruptedException { | |
//Only 5 Threads will be the hability to execute a code | |
ThreadPoolBulkhead threadPoolBulkhead = ThreadPoolBulkhead.of("threads", ThreadPoolBulkheadConfig.custom() | |
.coreThreadPoolSize(5) | |
.maxThreadPoolSize(5) | |
.build()); | |
//Decorating the execution of the method and the configuration of the threadPool | |
Supplier<CompletionStage<Void>> withBulkhead = ThreadPoolBulkhead.decorateRunnable(threadPoolBulkhead, this::takeBook); |
OlderNewer