io.github.resilience4j.bulkhead.BulkheadFullException Java Examples
The following examples show how to use
io.github.resilience4j.bulkhead.BulkheadFullException.
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: DecoratorsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void testDecorateRunnableWithBulkheadFullExceptionFallback() throws ExecutionException, InterruptedException { ThreadPoolBulkhead bulkhead = ThreadPoolBulkhead.ofDefaults("helloBackend"); ThreadPoolBulkhead bulkheadMock = spy(bulkhead); given(bulkheadMock.submit(any(Callable.class))).willThrow(BulkheadFullException.createBulkheadFullException(bulkhead)); CompletionStage<Void> completionStage = Decorators .ofRunnable(() -> helloWorldService.sayHelloWorld()) .withThreadPoolBulkhead(bulkheadMock) .withFallback(BulkheadFullException.class, (e) -> { helloWorldService.sayHelloWorld(); return null; }) .get(); completionStage.toCompletableFuture().get(); then(helloWorldService).should(times(1)).sayHelloWorld(); }
Example #2
Source File: DecoratorsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void testDecorateCallableWithBulkheadFullExceptionFallback() throws ExecutionException, InterruptedException { ThreadPoolBulkhead bulkhead = ThreadPoolBulkhead.ofDefaults("helloBackend"); ThreadPoolBulkhead bulkheadMock = spy(bulkhead); given(bulkheadMock.submit(any(Callable.class))).willThrow(BulkheadFullException.createBulkheadFullException(bulkhead)); CompletionStage<String> completionStage = Decorators .ofCallable(() -> helloWorldService.returnHelloWorldWithException()) .withThreadPoolBulkhead(bulkheadMock) .withFallback(BulkheadFullException.class, (e) -> "Fallback") .get(); String result = completionStage.toCompletableFuture().get(); assertThat(result).isEqualTo("Fallback"); }
Example #3
Source File: DecoratorsTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void testDecorateSupplierWithBulkheadFullExceptionFallback() throws ExecutionException, InterruptedException { ThreadPoolBulkhead bulkhead = ThreadPoolBulkhead.ofDefaults("helloBackend"); ThreadPoolBulkhead bulkheadMock = spy(bulkhead); given(bulkheadMock.submit(any(Callable.class))).willThrow(BulkheadFullException.createBulkheadFullException(bulkhead)); CompletionStage<String> completionStage = Decorators .ofSupplier(() -> helloWorldService.returnHelloWorld()) .withThreadPoolBulkhead(bulkheadMock) .withFallback(BulkheadFullException.class, (e) -> "Fallback") .get(); String result = completionStage.toCompletableFuture().get(); assertThat(result).isEqualTo("Fallback"); }
Example #4
Source File: FixedThreadPoolBulkhead.java From resilience4j with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public CompletableFuture<Void> submit(Runnable runnable) { final CompletableFuture<Void> promise = new CompletableFuture<>(); try { CompletableFuture.runAsync(ContextPropagator.decorateRunnable(config.getContextPropagator(),() -> { try { publishBulkheadEvent(() -> new BulkheadOnCallPermittedEvent(name)); runnable.run(); } catch (Exception e) { throw new CompletionException(e); } }), executorService).whenComplete((result, throwable) -> { publishBulkheadEvent(() -> new BulkheadOnCallFinishedEvent(name)); if (throwable != null) { promise.completeExceptionally(throwable); } else { promise.complete(result); } }); } catch (RejectedExecutionException rejected) { publishBulkheadEvent(() -> new BulkheadOnCallRejectedEvent(name)); throw BulkheadFullException.createBulkheadFullException(this); } return promise; }
Example #5
Source File: FlowableBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitErrorWithBulkheadFullException() { given(bulkhead.tryAcquirePermission()).willReturn(false); Flowable.fromArray("Event 1", "Event 2") .compose(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(BulkheadFullException.class) .assertNotComplete(); then(bulkhead).should(never()).onComplete(); }
Example #6
Source File: BulkheadTransformer.java From resilience4j with Apache License 2.0 | 5 votes |
@Override public Upstream<T> apply(Upstream<? extends T> upstream) throws Exception { return down -> { if (bulkhead.tryAcquirePermission()) { // do not allow permits to leak upstream.connect(new Downstream<T>() { @Override public void success(T value) { bulkhead.onComplete(); down.success(value); } @Override public void error(Throwable throwable) { bulkhead.onComplete(); handleRecovery(down, throwable); } @Override public void complete() { bulkhead.releasePermission(); down.complete(); } }); } else { Throwable t = BulkheadFullException.createBulkheadFullException(bulkhead); handleRecovery(down, t); } }; }
Example #7
Source File: FlowableBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(Subscriber<? super T> downstream) { if (bulkhead.tryAcquirePermission()) { upstream.subscribe(new BulkheadSubscriber(downstream)); } else { downstream.onSubscribe(EmptySubscription.INSTANCE); downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #8
Source File: SingleBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(SingleObserver<? super T> downstream) { if (bulkhead.tryAcquirePermission()) { upstream.subscribe(new BulkheadSingleObserver(downstream)); } else { downstream.onSubscribe(EmptyDisposable.INSTANCE); downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #9
Source File: CompletableBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(CompletableObserver downstream) { if (bulkhead.tryAcquirePermission()) { upstream.subscribe(new BulkheadCompletableObserver(downstream)); } else { downstream.onSubscribe(EmptyDisposable.INSTANCE); downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #10
Source File: MaybeBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(MaybeObserver<? super T> downstream) { if (bulkhead.tryAcquirePermission()) { upstream.subscribe(new BulkheadMaybeObserver(downstream)); } else { downstream.onSubscribe(EmptyDisposable.INSTANCE); downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #11
Source File: ObserverBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(Observer<? super T> downstream) { if (bulkhead.tryAcquirePermission()) { upstream.subscribe(new BulkheadObserver(downstream)); } else { downstream.onSubscribe(EmptyDisposable.INSTANCE); downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #12
Source File: CompletableBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitErrorWithBulkheadFullException() { given(bulkhead.tryAcquirePermission()).willReturn(false); Completable.complete() .compose(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(BulkheadFullException.class) .assertNotComplete(); then(bulkhead).should(never()).onComplete(); }
Example #13
Source File: FluxBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitBulkheadFullExceptionEvenWhenErrorNotOnSubscribe() { given(bulkhead.tryAcquirePermission()).willReturn(false); StepVerifier.create( Flux.error(new IOException("BAM!"), true) .transformDeferred(BulkheadOperator.of(bulkhead))) .expectSubscription() .expectError(BulkheadFullException.class) .verify(Duration.ofSeconds(1)); verify(bulkhead, never()).onComplete(); }
Example #14
Source File: SingleBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitErrorWithBulkheadFullException() { given(bulkhead.tryAcquirePermission()).willReturn(false); Single.just(1) .compose(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(BulkheadFullException.class) .assertNotComplete(); then(bulkhead).should(never()).onComplete(); }
Example #15
Source File: MaybeBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitErrorWithBulkheadFullException() { given(bulkhead.tryAcquirePermission()).willReturn(false); Maybe.just(1) .compose(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(BulkheadFullException.class) .assertNotComplete(); verify(bulkhead, never()).onComplete(); }
Example #16
Source File: ObserverBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitErrorWithBulkheadFullException() { given(bulkhead.tryAcquirePermission()).willReturn(false); Observable.fromArray("Event 1", "Event 2") .compose(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(BulkheadFullException.class) .assertNotComplete(); then(bulkhead).should(never()).onComplete(); }
Example #17
Source File: FluxBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override public void subscribe(CoreSubscriber<? super T> actual) { if (bulkhead.tryAcquirePermission()) { source.subscribe(new BulkheadSubscriber<>(bulkhead, actual, false)); } else { Operators.error(actual, BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #18
Source File: MonoBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override public void subscribe(CoreSubscriber<? super T> actual) { if (bulkhead.tryAcquirePermission()) { source.subscribe(new BulkheadSubscriber<>(bulkhead, actual, true)); } else { Operators.error(actual, BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #19
Source File: MonoBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitErrorWithBulkheadFullException() { given(bulkhead.tryAcquirePermission()).willReturn(false); StepVerifier.create( Mono.just("Event") .transformDeferred(BulkheadOperator.of(bulkhead))) .expectSubscription() .expectError(BulkheadFullException.class) .verify(Duration.ofSeconds(1)); verify(bulkhead, never()).onComplete(); }
Example #20
Source File: MonoBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitBulkheadFullExceptionEvenWhenErrorDuringSubscribe() { given(bulkhead.tryAcquirePermission()).willReturn(false); StepVerifier.create( Mono.error(new IOException("BAM!")) .transformDeferred(BulkheadOperator.of(bulkhead))) .expectSubscription() .expectError(BulkheadFullException.class) .verify(Duration.ofSeconds(1)); }
Example #21
Source File: FluxBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitErrorWithBulkheadFullException() { given(bulkhead.tryAcquirePermission()).willReturn(false); bulkhead.tryAcquirePermission(); StepVerifier.create( Flux.just("Event") .transformDeferred(BulkheadOperator.of(bulkhead))) .expectSubscription() .expectError(BulkheadFullException.class) .verify(Duration.ofSeconds(1)); verify(bulkhead, never()).onComplete(); }
Example #22
Source File: FluxBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitBulkheadFullExceptionEvenWhenErrorDuringSubscribe() { given(bulkhead.tryAcquirePermission()).willReturn(false); StepVerifier.create( Flux.error(new IOException("BAM!")) .transformDeferred(BulkheadOperator.of(bulkhead))) .expectSubscription() .expectError(BulkheadFullException.class) .verify(Duration.ofSeconds(1)); verify(bulkhead, never()).onComplete(); }
Example #23
Source File: Decorators.java From resilience4j with Apache License 2.0 | 5 votes |
private Supplier<CompletionStage<Void>> getCompletionStageSupplier( ThreadPoolBulkhead threadPoolBulkhead) { return () -> { try { return threadPoolBulkhead.executeRunnable(runnable); } catch (BulkheadFullException ex) { CompletableFuture<Void> future = new CompletableFuture<>(); future.completeExceptionally(ex); return future; } }; }
Example #24
Source File: SemaphoreBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void acquirePermission() { boolean permitted = tryAcquirePermission(); if (permitted) { return; } if (Thread.currentThread().isInterrupted()) { throw new AcquirePermissionCancelledException(); } throw BulkheadFullException.createBulkheadFullException(this); }
Example #25
Source File: FlowableBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(Subscriber<? super T> downstream) { if (bulkhead.tryAcquirePermission()) { upstream.subscribe(new BulkheadSubscriber(downstream)); } else { downstream.onSubscribe(EmptySubscription.INSTANCE); downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #26
Source File: SingleBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(SingleObserver<? super T> downstream) { if (bulkhead.tryAcquirePermission()) { upstream.subscribe(new BulkheadSingleObserver(downstream)); } else { downstream.onSubscribe(EmptyDisposable.INSTANCE); downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #27
Source File: CompletableBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(CompletableObserver downstream) { if (bulkhead.tryAcquirePermission()) { upstream.subscribe(new BulkheadCompletableObserver(downstream)); } else { downstream.onSubscribe(EmptyDisposable.INSTANCE); downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #28
Source File: MaybeBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(MaybeObserver<? super T> downstream) { if (bulkhead.tryAcquirePermission()) { upstream.subscribe(new BulkheadMaybeObserver(downstream)); } else { downstream.onSubscribe(EmptyDisposable.INSTANCE); downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #29
Source File: ObserverBulkhead.java From resilience4j with Apache License 2.0 | 5 votes |
@Override protected void subscribeActual(Observer<? super T> downstream) { if (bulkhead.tryAcquirePermission()) { upstream.subscribe(new BulkheadObserver(downstream)); } else { downstream.onSubscribe(EmptyDisposable.INSTANCE); downstream.onError(BulkheadFullException.createBulkheadFullException(bulkhead)); } }
Example #30
Source File: CompletableBulkheadTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldEmitErrorWithBulkheadFullException() { given(bulkhead.tryAcquirePermission()).willReturn(false); Completable.complete() .compose(BulkheadOperator.of(bulkhead)) .test() .assertError(BulkheadFullException.class) .assertNotComplete(); then(bulkhead).should(never()).onComplete(); }