private void handleOnError(Throwable ex) { if (!this.content.isTerminated()) { this.content.onError(ex); } }
private <T> Consumer<T> updateConnectMono(MonoProcessor<Void> connectMono) { return o -> { if (!connectMono.isTerminated()) { if (o instanceof Throwable) { connectMono.onError((Throwable) o); } else { connectMono.onComplete(); } } }; }
@Override public void onError(Throwable ex) { if (this.completionMono != null) { this.completionMono.onError(ex); } int code = CloseStatus.SERVER_ERROR.getCode(); close(new CloseStatus(code, ex.getMessage())); }
@Test public void MonoProcessorRejectedSubscribeCallback() { MonoProcessor<String> mp = MonoProcessor.create(); AtomicReference<Throwable> ref = new AtomicReference<>(); mp.subscribe(v -> {}, ref::set); mp.onError(new Exception("test")); assertThat(ref.get()).hasMessage("test"); assertThat(mp.isSuccess()).isFalse(); assertThat(mp.isError()).isTrue(); }
@Test public void MonoProcessorRejectedDoOnError() { MonoProcessor<String> mp = MonoProcessor.create(); AtomicReference<Throwable> ref = new AtomicReference<>(); mp.doOnError(ref::set).subscribe(); mp.onError(new Exception("test")); assertThat(ref.get()).hasMessage("test"); assertThat(mp.isSuccess()).isFalse(); assertThat(mp.isError()).isTrue(); }
@Test public void MonoProcessorRejectedDoOnSuccessOrError() { MonoProcessor<String> mp = MonoProcessor.create(); AtomicReference<Throwable> ref = new AtomicReference<>(); mp.doOnSuccessOrError((s, f) -> ref.set(f)).subscribe(); mp.onError(new Exception("test")); assertThat(ref.get()).hasMessage("test"); assertThat(mp.isSuccess()).isFalse(); assertThat(mp.isError()).isTrue(); }
@Test public void MonoProcessorRejectedDoOnTerminate() { MonoProcessor<String> mp = MonoProcessor.create(); AtomicInteger invoked = new AtomicInteger(); mp.doOnTerminate(invoked::incrementAndGet).subscribe(); mp.onError(new Exception("test")); assertThat(invoked.get()).isEqualTo(1); assertThat(mp.isSuccess()).isFalse(); assertThat(mp.isError()).isTrue(); }
@Test public void MonoProcessorRejectedChainTogether() { MonoProcessor<String> mp = MonoProcessor.create(); MonoProcessor<String> mp2 = MonoProcessor.create(); mp.subscribe(mp2); mp.onError(new Exception("test")); assertThat(mp2.getError()).hasMessage("test"); assertThat(mp.isSuccess()).isFalse(); assertThat(mp.isError()).isTrue(); }
@Test(expected = Exception.class) public void MonoProcessorDoubleSignal() { MonoProcessor<String> mp = MonoProcessor.create(); mp.onNext("test"); mp.onError(new Exception("test")); }
@Test public void deferredResultSubscriberWithError() throws Exception { IllegalStateException ex = new IllegalStateException(); // Mono MonoProcessor<String> mono = MonoProcessor.create(); testDeferredResultSubscriber(mono, Mono.class, forClass(String.class), () -> mono.onError(ex), ex); // RxJava 1 Single AtomicReference<SingleEmitter<String>> ref = new AtomicReference<>(); Single<String> single = Single.fromEmitter(ref::set); testDeferredResultSubscriber(single, Single.class, forClass(String.class), () -> ref.get().onError(ex), ex); // RxJava 2 Single AtomicReference<io.reactivex.SingleEmitter<String>> ref2 = new AtomicReference<>(); io.reactivex.Single<String> single2 = io.reactivex.Single.create(ref2::set); testDeferredResultSubscriber(single2, io.reactivex.Single.class, forClass(String.class), () -> ref2.get().onError(ex), ex); }
@Test public void scanProcessorError() { MonoProcessor<String> test = MonoProcessor.create(); Subscription subscription = Operators.emptySubscription(); test.onSubscribe(subscription); test.onError(new IllegalStateException("boom")); assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom"); assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue(); }
@Test public void zipMonoProcessorRejected() { MonoProcessor<Integer> mp = MonoProcessor.create(); MonoProcessor<Integer> mp2 = MonoProcessor.create(); MonoProcessor<Tuple2<Integer, Integer>> mp3 = MonoProcessor.create(); StepVerifier.create(Mono.zip(mp, mp2) .subscribeWith(mp3)) .then(() -> assertThat(mp3.isPending()).isTrue()) .then(() -> mp.onError(new Exception("test"))) .then(() -> { assertThat(mp3.isTerminated()).isTrue(); assertThat(mp3.isSuccess()).isFalse(); assertThat(mp3.isPending()).isFalse(); assertThat(mp3.getError()).hasMessage("test"); }) .verifyErrorMessage("test"); }
@Override public void onError(Throwable t) { processor.onError(t); }
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void monoFailure() { Message emptyMessage = MessageBuilder.withPayload(new byte[0]).build(); given(this.channel.send(any(Message.class))).willReturn(true); given(this.converter.toMessage(any(), any(MessageHeaders.class))).willReturn(emptyMessage); ReactiveController controller = new ReactiveController(); this.messageHandler.registerHandler(controller); this.messageHandler.setDestinationPrefixes(Arrays.asList("/app1", "/app2/")); Message<?> message = createMessage("/app1/mono"); this.messageHandler.handleMessage(message); controller.mono.onError(new IllegalStateException()); assertTrue(controller.exceptionCaught); }
@Test public void promiseErrorCountCannotExceedOne() { MonoProcessor<Object> deferred = MonoProcessor.create(); Throwable error = new IOException("foo"); StepVerifier.create(deferred) .then(() -> { deferred.onError(error); deferred.onNext(error); }) .expectErrorMessage("foo") .verifyThenAssertThat() .hasDroppedExactly(error); Assertions.assertThat(deferred.getError()).isSameAs(error); }
@Test public void promiseAcceptCountAndErrorCountCannotExceedOneInTotal() { MonoProcessor<Object> deferred = MonoProcessor.create(); Throwable error = new IOException("foo"); StepVerifier.create(deferred) .then(() -> { deferred.onError(error); deferred.onNext("alpha"); }) .expectErrorMessage("foo") .verifyThenAssertThat() .hasDroppedExactly("alpha"); Assertions.assertThat(deferred.getError()).isSameAs(error); }
private <T> Consumer<T> updateConnectMono(MonoProcessor<Void> connectMono) { return o -> { if (!connectMono.isTerminated()) { if (o instanceof Throwable) { connectMono.onError((Throwable) o); } else { connectMono.onComplete(); } } }; }
private <T> Consumer<T> updateConnectMono(MonoProcessor<Void> connectMono) { return o -> { if (!connectMono.isTerminated()) { if (o instanceof Throwable) { connectMono.onError((Throwable) o); } else { connectMono.onComplete(); } } }; }
@Override public void onError(Throwable ex) { if (this.completionMono != null) { this.completionMono.onError(ex); } int code = CloseStatus.SERVER_ERROR.getCode(); close(new CloseStatus(code, ex.getMessage())); }