io.github.resilience4j.timelimiter.TimeLimiterConfig Java Examples
The following examples show how to use
io.github.resilience4j.timelimiter.TimeLimiterConfig.
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: TimeLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void shouldRecordSuccesses() { TimeLimiter timeLimiter = TimeLimiter.of(TimeLimiterConfig.ofDefaults()); metricRegistry.registerAll(TimeLimiterMetrics.ofTimeLimiter(timeLimiter)); timeLimiter.onSuccess(); timeLimiter.onSuccess(); assertThat(metricRegistry).hasMetricsSize(3); assertThat(metricRegistry).counter(DEFAULT_PREFIX + SUCCESSFUL) .hasValue(2L); assertThat(metricRegistry).counter(DEFAULT_PREFIX + FAILED) .hasValue(0L); assertThat(metricRegistry).counter(DEFAULT_PREFIX + TIMEOUT) .hasValue(0L); }
Example #2
Source File: DecoratorsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void shouldThrowTimeoutException() { TimeLimiter timeLimiter = TimeLimiter.of("helloBackend", TimeLimiterConfig.custom() .timeoutDuration(Duration.ofMillis(100)).build()); CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("helloBackend"); ThreadPoolBulkhead bulkhead = ThreadPoolBulkhead.ofDefaults("helloBackend"); CompletionStage<String> completionStage = Decorators .ofCallable(() -> { Thread.sleep(1000); return "Bla"; }) .withThreadPoolBulkhead(bulkhead) .withTimeLimiter(timeLimiter, Executors.newSingleThreadScheduledExecutor()) .withCircuitBreaker(circuitBreaker) .get(); assertThatThrownBy(() -> completionStage.toCompletableFuture().get()) .hasCauseInstanceOf(TimeoutException.class); CircuitBreaker.Metrics metrics = circuitBreaker.getMetrics(); assertThat(metrics.getNumberOfBufferedCalls()).isEqualTo(1); assertThat(metrics.getNumberOfFailedCalls()).isEqualTo(1); }
Example #3
Source File: DecoratorsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void testDecorateCompletionStageWithTimeoutExceptionFallback() throws ExecutionException, InterruptedException { TimeLimiter timeLimiter = TimeLimiter.of("helloBackend", TimeLimiterConfig.custom() .timeoutDuration(Duration.ofMillis(100)).build()); CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("helloBackend"); ThreadPoolBulkhead bulkhead = ThreadPoolBulkhead.ofDefaults("helloBackend"); CompletionStage<String> completionStage = Decorators .ofCallable(() -> { Thread.sleep(1000); return "Bla"; }) .withThreadPoolBulkhead(bulkhead) .withTimeLimiter(timeLimiter, Executors.newSingleThreadScheduledExecutor()) .withCircuitBreaker(circuitBreaker) .withFallback(TimeoutException.class, (e) -> "Fallback") .get(); String result = completionStage.toCompletableFuture().get(); assertThat(result).isEqualTo("Fallback"); CircuitBreaker.Metrics metrics = circuitBreaker.getMetrics(); assertThat(metrics.getNumberOfFailedCalls()).isEqualTo(1); }
Example #4
Source File: TaggedTimeLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void customMetricNamesGetApplied() { MeterRegistry meterRegistry = new SimpleMeterRegistry(); TaggedTimeLimiterMetricsPublisher taggedTimeLimiterMetricsPublisher = new TaggedTimeLimiterMetricsPublisher( TimeLimiterMetricNames.custom() .callsMetricName("custom_calls") .build(), meterRegistry); TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry .of(TimeLimiterConfig.ofDefaults(), taggedTimeLimiterMetricsPublisher); timeLimiterRegistry.timeLimiter("backendA"); Set<String> metricNames = meterRegistry.getMeters() .stream() .map(Meter::getId) .map(Meter.Id::getName) .collect(Collectors.toSet()); assertThat(metricNames).hasSameElementsAs(Arrays.asList( "custom_calls" )); }
Example #5
Source File: TimeLimiterConfigCustomizer.java From resilience4j with Apache License 2.0 | 6 votes |
/** * A convenient method to create TimeLimiterConfigCustomizer using {@link Consumer} * * @param instanceName the name of the instance * @param consumer delegate call to Consumer when {@link TimeLimiterConfigCustomizer#customize(TimeLimiterConfig.Builder)} * is called * @return Customizer instance */ static TimeLimiterConfigCustomizer of(@NonNull String instanceName, @NonNull Consumer<TimeLimiterConfig.Builder> consumer) { return new TimeLimiterConfigCustomizer() { @Override public void customize(TimeLimiterConfig.Builder builder) { consumer.accept(builder); } @Override public String name() { return instanceName; } }; }
Example #6
Source File: TimeLimiterConfigurationProperties.java From resilience4j with Apache License 2.0 | 6 votes |
public TimeLimiterConfig createTimeLimiterConfig(String backendName, @Nullable InstanceProperties instanceProperties, CompositeCustomizer<TimeLimiterConfigCustomizer> compositeTimeLimiterCustomizer) { if (instanceProperties == null) { return TimeLimiterConfig.ofDefaults(); } if (StringUtils.isNotEmpty(instanceProperties.getBaseConfig())) { InstanceProperties baseProperties = configs.get(instanceProperties.getBaseConfig()); if (baseProperties == null) { throw new ConfigurationNotFoundException(instanceProperties.getBaseConfig()); } return buildConfigFromBaseConfig(baseProperties, instanceProperties, compositeTimeLimiterCustomizer, backendName); } return buildTimeLimiterConfig(TimeLimiterConfig.custom(), instanceProperties, compositeTimeLimiterCustomizer, backendName); }
Example #7
Source File: TimeLimiterConfigurationProperties.java From resilience4j with Apache License 2.0 | 6 votes |
private static TimeLimiterConfig buildTimeLimiterConfig( TimeLimiterConfig.Builder builder, @Nullable InstanceProperties instanceProperties, CompositeCustomizer<TimeLimiterConfigCustomizer> compositeTimeLimiterCustomizer, String backendName) { if (instanceProperties == null) { return builder.build(); } if (instanceProperties.getTimeoutDuration() != null) { builder.timeoutDuration(instanceProperties.getTimeoutDuration()); } if (instanceProperties.getCancelRunningFuture() != null) { builder.cancelRunningFuture(instanceProperties.getCancelRunningFuture()); } compositeTimeLimiterCustomizer.getCustomizer(backendName).ifPresent( timeLimiterConfigCustomizer -> timeLimiterConfigCustomizer.customize(builder)); return builder.build(); }
Example #8
Source File: InMemoryTimeLimiterRegistryTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void timeLimiterPositiveWithSupplier() { TimeLimiterRegistry registry = new InMemoryTimeLimiterRegistry(config); Supplier<TimeLimiterConfig> timeLimiterConfigSupplier = mock(Supplier.class); given(timeLimiterConfigSupplier.get()).willReturn(config); TimeLimiter firstTimeLimiter = registry.timeLimiter("test", timeLimiterConfigSupplier); verify(timeLimiterConfigSupplier, times(1)).get(); TimeLimiter sameAsFirst = registry.timeLimiter("test", timeLimiterConfigSupplier); verify(timeLimiterConfigSupplier, times(1)).get(); TimeLimiter anotherLimit = registry.timeLimiter("test1", timeLimiterConfigSupplier); verify(timeLimiterConfigSupplier, times(2)).get(); then(firstTimeLimiter).isEqualTo(sameAsFirst); then(firstTimeLimiter).isNotEqualTo(anotherLimit); }
Example #9
Source File: TimeLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void shouldRecordErrors() { TimeLimiter timeLimiter = TimeLimiter.of(TimeLimiterConfig.ofDefaults()); metricRegistry.registerAll(TimeLimiterMetrics.ofTimeLimiter(timeLimiter)); timeLimiter.onError(new RuntimeException()); timeLimiter.onError(new RuntimeException()); assertThat(metricRegistry).hasMetricsSize(3); assertThat(metricRegistry).counter(DEFAULT_PREFIX + SUCCESSFUL) .hasValue(0L); assertThat(metricRegistry).counter(DEFAULT_PREFIX + FAILED) .hasValue(2L); assertThat(metricRegistry).counter(DEFAULT_PREFIX + TIMEOUT) .hasValue(0L); }
Example #10
Source File: Resilience4JCircuitBreakerIntegrationTest.java From spring-cloud-circuitbreaker with Apache License 2.0 | 6 votes |
@Bean public Customizer<Resilience4JCircuitBreakerFactory> slowCustomizer() { return factory -> { factory.configure( builder -> builder .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()) .timeLimiterConfig(TimeLimiterConfig.custom() .timeoutDuration(Duration.ofSeconds(2)).build()), "slow"); factory.configureDefault(id -> new Resilience4JConfigBuilder(id) .timeLimiterConfig(TimeLimiterConfig.custom() .timeoutDuration(Duration.ofSeconds(4)).build()) .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults()).build()); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker .getEventPublisher().onError(slowErrorConsumer) .onSuccess(slowSuccessConsumer), "slow"); factory.addCircuitBreakerCustomizer(circuitBreaker -> circuitBreaker .getEventPublisher().onError(normalErrorConsumer) .onSuccess(normalSuccessConsumer), "normal"); }; }
Example #11
Source File: TimeLimiterMetricsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void shouldRecordTimeouts() { TimeLimiter timeLimiter = TimeLimiter.of(TimeLimiterConfig.custom() .timeoutDuration(Duration.ZERO) .build()); metricRegistry.registerAll(TimeLimiterMetrics.ofTimeLimiter(timeLimiter)); timeLimiter.onError(new TimeoutException()); timeLimiter.onError(new TimeoutException()); assertThat(metricRegistry).hasMetricsSize(3); assertThat(metricRegistry).counter(DEFAULT_PREFIX + SUCCESSFUL) .hasValue(0L); assertThat(metricRegistry).counter(DEFAULT_PREFIX + FAILED) .hasValue(0L); assertThat(metricRegistry).counter(DEFAULT_PREFIX + TIMEOUT) .hasValue(2L); }
Example #12
Source File: SpringApp.java From tutorials with MIT License | 6 votes |
@Bean public Customizer<Resilience4JCircuitBreakerFactory> specificCustomConfiguration2() { TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom() .timeoutDuration(Duration.ofSeconds(4)) .build(); CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom() .failureRateThreshold(50) .waitDurationInOpenState(Duration.ofMillis(1000)) .slidingWindowSize(2) .build(); return factory -> factory.configure(builder -> builder.circuitBreakerConfig(circuitBreakerConfig) .timeLimiterConfig(timeLimiterConfig).build(), "circuitBreaker1", "circuitBreaker2", "circuitBreaker3"); }
Example #13
Source File: TimeLimiterTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void shouldThrowTimeoutExceptionAndInvokeCancel() throws Exception { Duration timeoutDuration = Duration.ofSeconds(1); TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom() .timeoutDuration(timeoutDuration) .build(); TimeLimiter timeLimiter = TimeLimiter.of(TIME_LIMITER_NAME,timeLimiterConfig); @SuppressWarnings("unchecked") Future<Integer> mockFuture = (Future<Integer>) mock(Future.class); Supplier<Future<Integer>> supplier = () -> mockFuture; given(mockFuture.get(timeoutDuration.toMillis(), TimeUnit.MILLISECONDS)) .willThrow(new TimeoutException()); Callable<Integer> decorated = TimeLimiter.decorateFutureSupplier(timeLimiter, supplier); Try<Integer> decoratedResult = Try.ofCallable(decorated); assertThat(decoratedResult.isFailure()).isTrue(); assertThat(decoratedResult.getCause()).isInstanceOf(TimeoutException.class); assertThat(decoratedResult.getCause()).hasMessage(createdTimeoutExceptionWithName(TIME_LIMITER_NAME).getMessage()); then(mockFuture).should().cancel(true); }
Example #14
Source File: Resilience4jTest.java From spring-cloud-formula with Apache License 2.0 | 6 votes |
@Before public void init() { TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom() .timeoutDuration(Duration.ofSeconds(1)) .cancelRunningFuture(true) .build(); timeLimiter = TimeLimiter.of(timeLimiterConfig); CustomizableThreadFactory factory = new CustomizableThreadFactory("timeLimiter-"); factory.setDaemon(true); executorService = Executors.newCachedThreadPool(factory); CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig .custom() .enableAutomaticTransitionFromOpenToHalfOpen() .failureRateThreshold(50) .ringBufferSizeInClosedState(10) .ringBufferSizeInHalfOpenState(2) .build(); circuitBreaker = CircuitBreaker.of("backendName", circuitBreakerConfig); }
Example #15
Source File: CircuitBreakerManager.java From spring-cloud-formula with Apache License 2.0 | 6 votes |
private TimeLimiterCoalition createTimeLimiter(String ruleName, CircuitBreakerRule rule) { if (rule == null) { return null; } Duration timeout = rule.getTimeoutDuration(); if (rule.getEnabled() != null && rule.getEnabled() && timeout != null && !timeout.isNegative() && !timeout.isZero()) { try { TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom() .timeoutDuration(rule.getTimeoutDuration()) .cancelRunningFuture(rule.getCancelRunningFuture()) .build(); TimeLimiter timeLimiter = TimeLimiter.of(timeLimiterConfig); TimeLimiterCoalition timeLimiterCoalition = new TimeLimiterCoalition( timeLimiter, rule); return timeLimiterCoalition; } catch (Exception e) { logger.error("failed to create timeLimiter,name:{},id{}", ruleName, rule.getRuleId(), e); return null; } } return null; }
Example #16
Source File: SpringApp.java From tutorials with MIT License | 6 votes |
@Bean public Customizer<Resilience4JCircuitBreakerFactory> globalCustomConfiguration() { TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom() .timeoutDuration(Duration.ofSeconds(4)) .build(); CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom() .failureRateThreshold(50) .waitDurationInOpenState(Duration.ofMillis(1000)) .slidingWindowSize(2) .build(); return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) .timeLimiterConfig(timeLimiterConfig) .circuitBreakerConfig(circuitBreakerConfig) .build()); }
Example #17
Source File: TimeLimiterTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void shouldThrowTimeoutExceptionAndNotInvokeCancel() throws Exception { Duration timeoutDuration = Duration.ofSeconds(1); TimeLimiter timeLimiter = TimeLimiter .of(TimeLimiterConfig.custom().timeoutDuration(timeoutDuration) .cancelRunningFuture(false).build()); @SuppressWarnings("unchecked") Future<Integer> mockFuture = (Future<Integer>) mock(Future.class); Supplier<Future<Integer>> supplier = () -> mockFuture; given(mockFuture.get(timeoutDuration.toMillis(), TimeUnit.MILLISECONDS)) .willThrow(new TimeoutException()); Callable<Integer> decorated = TimeLimiter.decorateFutureSupplier(timeLimiter, supplier); Try<Integer> decoratedResult = Try.ofCallable(decorated); assertThat(decoratedResult.isFailure()).isTrue(); assertThat(decoratedResult.getCause()).isInstanceOf(TimeoutException.class); then(mockFuture).should(never()).cancel(true); }
Example #18
Source File: Resilience4jUnitTest.java From tutorials with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Test public void whenTimeLimiterIsUsed_thenItWorksAsExpected() throws Exception { long ttl = 1; TimeLimiterConfig config = TimeLimiterConfig.custom().timeoutDuration(Duration.ofMillis(ttl)).build(); TimeLimiter timeLimiter = TimeLimiter.of(config); Future futureMock = mock(Future.class); Callable restrictedCall = TimeLimiter.decorateFutureSupplier(timeLimiter, () -> futureMock); restrictedCall.call(); verify(futureMock).get(ttl, TimeUnit.MILLISECONDS); }
Example #19
Source File: TimeLimiterAspect.java From resilience4j with Apache License 2.0 | 5 votes |
private io.github.resilience4j.timelimiter.TimeLimiter getOrCreateTimeLimiter(String methodName, String name) { io.github.resilience4j.timelimiter.TimeLimiter timeLimiter = timeLimiterRegistry.timeLimiter(name); if (logger.isDebugEnabled()) { TimeLimiterConfig timeLimiterConfig = timeLimiter.getTimeLimiterConfig(); logger.debug( "Created or retrieved time limiter '{}' with timeout duration '{}' and cancelRunningFuture '{}' for method: '{}'", name, timeLimiterConfig.getTimeoutDuration(), timeLimiterConfig.shouldCancelRunningFuture(), methodName ); } return timeLimiter; }
Example #20
Source File: TimeLimiterConfigurationPropertiesTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void testTimeLimiterProperties() { // Given TimeLimiterConfigurationProperties.InstanceProperties instanceProperties1 = new TimeLimiterConfigurationProperties.InstanceProperties(); instanceProperties1.setTimeoutDuration(Duration.ofSeconds(3)); instanceProperties1.setCancelRunningFuture(true); instanceProperties1.setEventConsumerBufferSize(200); TimeLimiterConfigurationProperties.InstanceProperties instanceProperties2 = new TimeLimiterConfigurationProperties.InstanceProperties(); instanceProperties2.setTimeoutDuration(Duration.ofSeconds(5)); instanceProperties2.setCancelRunningFuture(false); instanceProperties2.setEventConsumerBufferSize(500); TimeLimiterConfigurationProperties timeLimiterConfigurationProperties = new TimeLimiterConfigurationProperties(); timeLimiterConfigurationProperties.getInstances().put("backend1", instanceProperties1); timeLimiterConfigurationProperties.getInstances().put("backend2", instanceProperties2); Map<String,String> tags = new HashMap<>(); tags.put("testKey1","testKet2"); timeLimiterConfigurationProperties.setTags(tags); // Then assertThat(timeLimiterConfigurationProperties.getTags()).isNotEmpty(); assertThat(timeLimiterConfigurationProperties.getInstances().size()).isEqualTo(2); final TimeLimiterConfig timeLimiter1 = timeLimiterConfigurationProperties.createTimeLimiterConfig("backend1"); final TimeLimiterConfig timeLimiter2 = timeLimiterConfigurationProperties.createTimeLimiterConfig("backend2"); TimeLimiterConfigurationProperties.InstanceProperties instancePropertiesForTimeLimiter1 = timeLimiterConfigurationProperties.getInstances().get("backend1"); assertThat(instancePropertiesForTimeLimiter1.getTimeoutDuration().toMillis()).isEqualTo(3000); assertThat(timeLimiter1).isNotNull(); assertThat(timeLimiter1.shouldCancelRunningFuture()).isEqualTo(true); assertThat(timeLimiter2).isNotNull(); assertThat(timeLimiter2.getTimeoutDuration().toMillis()).isEqualTo(5000); }
Example #21
Source File: TimeLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected TimeLimiter given(String prefix, MetricRegistry metricRegistry) { TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.of(TimeLimiterConfig.ofDefaults(), new TimeLimiterMetricsPublisher(prefix, metricRegistry)); return timeLimiterRegistry.timeLimiter("testLimit"); }
Example #22
Source File: TimeLimiterConfigurationPropertiesTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void testCustomizeTimeLimiterConfig() { TimeLimiterConfigurationProperties timeLimiterConfigurationProperties = new TimeLimiterConfigurationProperties(); TimeLimiterConfigCustomizer customizer = TimeLimiterConfigCustomizer.of("backend", builder -> builder.timeoutDuration(Duration.ofSeconds(10))); TimeLimiterConfigurationProperties.InstanceProperties instanceProperties = new TimeLimiterConfigurationProperties.InstanceProperties(); instanceProperties.setTimeoutDuration(Duration.ofSeconds(3)); TimeLimiterConfig config = timeLimiterConfigurationProperties.createTimeLimiterConfig("backend", instanceProperties, new CompositeCustomizer<>(Collections.singletonList(customizer))); assertThat(config).isNotNull(); assertThat(config.getTimeoutDuration()).isEqualTo(Duration.ofSeconds(10)); }
Example #23
Source File: TimeLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected TimeLimiter given(MetricRegistry metricRegistry) { TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry.of(TimeLimiterConfig.ofDefaults(), new TimeLimiterMetricsPublisher(metricRegistry)); return timeLimiterRegistry.timeLimiter("testLimit"); }
Example #24
Source File: TaggedTimeLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Before public void setUp() { meterRegistry = new SimpleMeterRegistry(); taggedTimeLimiterMetricsPublisher = new TaggedTimeLimiterMetricsPublisher(meterRegistry); timeLimiterRegistry = TimeLimiterRegistry .of(TimeLimiterConfig.ofDefaults(), taggedTimeLimiterMetricsPublisher); timeLimiter = timeLimiterRegistry.timeLimiter("backendA"); }
Example #25
Source File: TimeLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void customMetricNamesOverrideDefaultOnes() { TimeLimiterMetricsPublisher.MetricNames names = TimeLimiterMetricsPublisher.MetricNames .custom() .callsMetricName("custom_calls") .build(); CollectorRegistry customRegistry = new CollectorRegistry(); TimeLimiterMetricsPublisher timeLimiterMetricsPublisher = new TimeLimiterMetricsPublisher( names); timeLimiterMetricsPublisher.register(customRegistry); TimeLimiterRegistry timeLimiterRegistry = TimeLimiterRegistry .of(TimeLimiterConfig.ofDefaults(), timeLimiterMetricsPublisher); TimeLimiter timeLimiter = timeLimiterRegistry.timeLimiter("backendA"); timeLimiter.onSuccess(); timeLimiter.onError(new RuntimeException()); timeLimiter.onError(new TimeoutException()); Double successfulCalls = getSampleValue(customRegistry, "custom_calls", KIND_SUCCESSFUL); Double failedCalls = getSampleValue(customRegistry, "custom_calls", KIND_FAILED); Double timeoutCalls = getSampleValue(customRegistry, "custom_calls", KIND_TIMEOUT); assertThat(successfulCalls).isNotNull(); assertThat(failedCalls).isNotNull(); assertThat(timeoutCalls).isNotNull(); }
Example #26
Source File: TimeLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Before public void setup() { registry = new CollectorRegistry(); timeLimiterMetricsPublisher = new TimeLimiterMetricsPublisher(); timeLimiterMetricsPublisher.register(registry); timeLimiterRegistry = TimeLimiterRegistry .of(TimeLimiterConfig.ofDefaults(), timeLimiterMetricsPublisher); timeLimiter = timeLimiterRegistry.timeLimiter("backendA"); }
Example #27
Source File: InMemoryTimeLimiterRegistryTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void timeLimiterNewWithNullConfigSupplier() { exception.expect(NullPointerException.class); exception.expectMessage("Supplier must not be null"); TimeLimiterRegistry registry = new InMemoryTimeLimiterRegistry(config); registry.timeLimiter("name", (Supplier<TimeLimiterConfig>) null); }
Example #28
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 #29
Source File: InMemoryTimeLimiterRegistryTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void timeLimiterConfigIsNull() { exception.expect(NullPointerException.class); exception.expectMessage(CONFIG_MUST_NOT_BE_NULL); new InMemoryTimeLimiterRegistry((TimeLimiterConfig) null); }
Example #30
Source File: TimeLimiterImplTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Before public void init() { timeLimiterConfig = TimeLimiterConfig.custom() .timeoutDuration(Duration.ZERO) .build(); TimeLimiterImpl testTimeout = new TimeLimiterImpl("name", timeLimiterConfig); timeLimiter = PowerMockito.spy(testTimeout); }