Java Code Examples for io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry#ofDefaults()
The following examples show how to use
io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry#ofDefaults() .
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: CircuitBreakerMetricsCollectorTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Before public void setup() { registry = new CollectorRegistry(); circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); CircuitBreakerConfig configWithSlowCallThreshold = CircuitBreakerConfig.custom() .slowCallDurationThreshold(Duration.ofSeconds(1)).build(); circuitBreaker = circuitBreakerRegistry .circuitBreaker("backendA", configWithSlowCallThreshold); CircuitBreakerMetricsCollector.ofCircuitBreakerRegistry(circuitBreakerRegistry) .register(registry); // record some basic stats // SLOW_SUCCESS circuitBreaker.onSuccess(2000, TimeUnit.NANOSECONDS); circuitBreaker.onError(100, TimeUnit.NANOSECONDS, new RuntimeException("oops")); circuitBreaker.transitionToOpenState(); }
Example 2
Source File: TaggedCircuitBreakerMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Before public void setUp() { meterRegistry = new SimpleMeterRegistry(); circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); CircuitBreakerConfig configWithSlowCallThreshold = CircuitBreakerConfig.custom() .slowCallDurationThreshold(Duration.ofSeconds(1)).build(); circuitBreaker = circuitBreakerRegistry .circuitBreaker("backendA", configWithSlowCallThreshold); // record some basic stats circuitBreaker.onSuccess(0, TimeUnit.NANOSECONDS); circuitBreaker.onError(0, TimeUnit.NANOSECONDS, new RuntimeException("oops")); // record slow calls circuitBreaker.onSuccess(2000, TimeUnit.NANOSECONDS); circuitBreaker.onError(2000, TimeUnit.NANOSECONDS, new RuntimeException("oops")); taggedCircuitBreakerMetrics = TaggedCircuitBreakerMetrics .ofCircuitBreakerRegistry(circuitBreakerRegistry); taggedCircuitBreakerMetrics.bindTo(meterRegistry); }
Example 3
Source File: ReactiveResilience4JCircuitbreakerDemoApplication.java From spring-cloud-circuitbreaker-demo with Apache License 2.0 | 5 votes |
@Bean public Customizer<ReactiveResilience4JCircuitBreakerFactory> defaultCustomizer() { CircuitBreakerRegistry cbr = CircuitBreakerRegistry.ofDefaults(); return factory -> { factory.configureDefault(id -> new Resilience4JConfigBuilder(id) .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(3)).build()) .circuitBreakerConfig(CircuitBreakerConfig.custom().failureRateThreshold(10) .slowCallRateThreshold(5).slowCallRateThreshold(2).build()).build()); }; }
Example 4
Source File: InMemoryCircuitBreakerRegistryTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void testAddCircuitBreakerRegistry() { CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); circuitBreakerRegistry.addConfiguration("testConfig", CircuitBreakerConfig.ofDefaults()); assertThat(circuitBreakerRegistry.getConfiguration("testConfig")).isNotNull(); }
Example 5
Source File: InMemoryCircuitBreakerRegistryTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void testGetNotFoundCircuitBreakerRegistry() { InMemoryCircuitBreakerRegistry circuitBreakerRegistry = (InMemoryCircuitBreakerRegistry) CircuitBreakerRegistry .ofDefaults(); assertThat(circuitBreakerRegistry.getConfiguration("testNotFound")).isEmpty(); }
Example 6
Source File: InMemoryCircuitBreakerRegistryTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void testUpdateDefaultCircuitBreakerRegistry() { CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); assertThatThrownBy(() -> circuitBreakerRegistry .addConfiguration("default", CircuitBreakerConfig.custom().build())) .isExactlyInstanceOf(IllegalArgumentException.class); }
Example 7
Source File: InMemoryCircuitBreakerRegistryTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void testCreateCircuitBreakerWithSharedConfiguration() { CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); circuitBreakerRegistry.addConfiguration("testConfig", CircuitBreakerConfig.ofDefaults()); final CircuitBreaker circuitBreaker = circuitBreakerRegistry .circuitBreaker("circuitBreaker", circuitBreakerRegistry.getConfiguration("testConfig").get()); assertThat(circuitBreaker).isNotNull(); }
Example 8
Source File: InMemoryCircuitBreakerRegistryTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void testCreateCircuitBreakerWithConfigName() { CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); circuitBreakerRegistry.addConfiguration("testConfig", CircuitBreakerConfig.custom().slidingWindowSize(5).build()); final CircuitBreaker circuitBreaker = circuitBreakerRegistry .circuitBreaker("circuitBreaker", "testConfig"); assertThat(circuitBreaker).isNotNull(); assertThat(circuitBreaker.getCircuitBreakerConfig().getSlidingWindowSize()).isEqualTo(5); }
Example 9
Source File: TaggedCircuitBreakerMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void metricsAreRegisteredWithCustomName() { MeterRegistry meterRegistry = new SimpleMeterRegistry(); CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); circuitBreakerRegistry.circuitBreaker("backendA"); TaggedCircuitBreakerMetrics.ofCircuitBreakerRegistry( CircuitBreakerMetricNames.custom() .callsMetricName("custom_calls") .notPermittedCallsMetricName("custom_not_permitted_calls") .stateMetricName("custom_state") .bufferedCallsMetricName("custom_buffered_calls") .slowCallsMetricName("custom_slow_calls") .failureRateMetricName("custom_failure_rate") .slowCallRateMetricName("custom_slow_call_rate") .build(), circuitBreakerRegistry ).bindTo(meterRegistry); Set<String> metricNames = meterRegistry.getMeters() .stream() .map(Meter::getId) .map(Meter.Id::getName) .collect(Collectors.toSet()); assertThat(metricNames).hasSameElementsAs(Arrays.asList( "custom_calls", "custom_not_permitted_calls", "custom_state", "custom_buffered_calls", "custom_slow_calls", "custom_failure_rate", "custom_slow_call_rate" )); }
Example 10
Source File: CircuitBreakerMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected CircuitBreaker givenMetricRegistry(String prefix, MetricRegistry metricRegistry) { CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker("testName"); metricRegistry.registerAll( CircuitBreakerMetrics.ofCircuitBreakerRegistry(prefix, circuitBreakerRegistry)); return circuitBreaker; }
Example 11
Source File: CircuitBreakerMetricsTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected CircuitBreaker givenMetricRegistry(MetricRegistry metricRegistry) { CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker("testName"); metricRegistry .registerAll(CircuitBreakerMetrics.ofCircuitBreakerRegistry(circuitBreakerRegistry)); return circuitBreaker; }
Example 12
Source File: InMemoryCircuitBreakerRegistryTest.java From resilience4j with Apache License 2.0 | 4 votes |
@Test public void testCreateCircuitBreakerWithConfigNameNotFound() { CircuitBreakerRegistry circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); assertThatThrownBy(() -> circuitBreakerRegistry.circuitBreaker("circuitBreaker", "testConfig")).isInstanceOf(ConfigurationNotFoundException.class); }
Example 13
Source File: CircuitBreakerConfigurationOnMissingBeanTest.java From resilience4j with Apache License 2.0 | 4 votes |
@Bean public CircuitBreakerRegistry circuitBreakerRegistry() { circuitBreakerRegistry = CircuitBreakerRegistry.ofDefaults(); return circuitBreakerRegistry; }