Search in sources :

Example 1 with CircuitBreaker

use of org.springframework.cloud.client.circuitbreaker.CircuitBreaker in project spring-cloud-alibaba by alibaba.

the class SentinelCircuitBreakerTest method testRunWithFallback.

@Test
public void testRunWithFallback() {
    CircuitBreaker cb = new SentinelCircuitBreakerFactory().create("testSentinelRunWithFallback");
    assertThat(cb.<String>run(() -> {
        throw new RuntimeException("boom");
    }, t -> "fallback")).isEqualTo("fallback");
}
Also used : CircuitBreaker(org.springframework.cloud.client.circuitbreaker.CircuitBreaker) Test(org.junit.Test)

Example 2 with CircuitBreaker

use of org.springframework.cloud.client.circuitbreaker.CircuitBreaker in project spring-cloud-circuitbreaker by spring-cloud.

the class Resilience4JCircuitBreakerTest method run.

@Test
public void run() {
    CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), TimeLimiterRegistry.ofDefaults(), null).create("foo");
    assertThat(cb.run(() -> "foobar")).isEqualTo("foobar");
}
Also used : CircuitBreaker(org.springframework.cloud.client.circuitbreaker.CircuitBreaker) Test(org.junit.Test)

Example 3 with CircuitBreaker

use of org.springframework.cloud.client.circuitbreaker.CircuitBreaker in project spring-cloud-circuitbreaker by spring-cloud.

the class Resilience4JCircuitBreakerTest method runWithGroupName.

@Test
public void runWithGroupName() {
    CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), TimeLimiterRegistry.ofDefaults(), null).create("foo", "groupFoo");
    assertThat(cb.run(() -> "foobar")).isEqualTo("foobar");
}
Also used : CircuitBreaker(org.springframework.cloud.client.circuitbreaker.CircuitBreaker) Test(org.junit.Test)

Example 4 with CircuitBreaker

use of org.springframework.cloud.client.circuitbreaker.CircuitBreaker in project spring-cloud-circuitbreaker by spring-cloud.

the class Resilience4JCircuitBreakerTest method runWithFallbackBulkheadProviderAndGroupName.

@Test
public void runWithFallbackBulkheadProviderAndGroupName() {
    CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), TimeLimiterRegistry.ofDefaults(), new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults())).create("foo", "groupFoo");
    assertThat((String) cb.run(() -> {
        throw new RuntimeException("boom");
    }, t -> "fallback")).isEqualTo("fallback");
}
Also used : BulkheadRegistry(io.github.resilience4j.bulkhead.BulkheadRegistry) CircuitBreaker(org.springframework.cloud.client.circuitbreaker.CircuitBreaker) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeLimiterRegistry(io.github.resilience4j.timelimiter.TimeLimiterRegistry) Test(org.junit.Test) CircuitBreakerRegistry(io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry) ThreadPoolBulkheadRegistry(io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry) CircuitBreaker(org.springframework.cloud.client.circuitbreaker.CircuitBreaker) Test(org.junit.Test)

Example 5 with CircuitBreaker

use of org.springframework.cloud.client.circuitbreaker.CircuitBreaker in project spring-cloud-circuitbreaker by spring-cloud.

the class Resilience4JCircuitBreakerTest method runWithBulkheadProvider.

@Test
public void runWithBulkheadProvider() {
    CircuitBreaker cb = new Resilience4JCircuitBreakerFactory(CircuitBreakerRegistry.ofDefaults(), TimeLimiterRegistry.ofDefaults(), new Resilience4jBulkheadProvider(ThreadPoolBulkheadRegistry.ofDefaults(), BulkheadRegistry.ofDefaults())).create("foo");
    assertThat(cb.run(() -> "foobar")).isEqualTo("foobar");
}
Also used : CircuitBreaker(org.springframework.cloud.client.circuitbreaker.CircuitBreaker) Test(org.junit.Test)

Aggregations

CircuitBreaker (org.springframework.cloud.client.circuitbreaker.CircuitBreaker)18 Test (org.junit.Test)12 BulkheadRegistry (io.github.resilience4j.bulkhead.BulkheadRegistry)4 ThreadPoolBulkheadRegistry (io.github.resilience4j.bulkhead.ThreadPoolBulkheadRegistry)4 CircuitBreakerRegistry (io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry)4 TimeLimiterRegistry (io.github.resilience4j.timelimiter.TimeLimiterRegistry)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 InvocationHandlerFactory (feign.InvocationHandlerFactory)2 Target (feign.Target)2 Util.checkNotNull (feign.Util.checkNotNull)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 Method (java.lang.reflect.Method)2 Proxy (java.lang.reflect.Proxy)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Function (java.util.function.Function)2 Supplier (java.util.function.Supplier)2 Test (org.junit.jupiter.api.Test)2 CircuitBreakerFactory (org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory)2 RequestAttributes (org.springframework.web.context.request.RequestAttributes)2