@Test(expected = NullPointerException.class) public void onErrorNull() { EmitterProcessor.create().onError(null); }
@Test public void someFirst() { EmitterProcessor<Integer> tp = EmitterProcessor.create(); AssertSubscriber<Integer> ts = AssertSubscriber.create(); tp.onErrorResume(v -> Flux.range(11, 10)) .subscribe(ts); tp.onNext(1); tp.onNext(2); tp.onNext(3); tp.onNext(4); tp.onNext(5); tp.onError(new RuntimeException("forced failure")); ts.assertValues(1, 2, 3, 4, 5, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) .assertNoError() .assertComplete(); }
@Test public void someFirstBackpressured() { EmitterProcessor<Integer> tp = EmitterProcessor.create(); AssertSubscriber<Integer> ts = AssertSubscriber.create(10); tp.onErrorResume(v -> Flux.range(11, 10)) .subscribe(ts); tp.onNext(1); tp.onNext(2); tp.onNext(3); tp.onNext(4); tp.onNext(5); tp.onError(new RuntimeException("forced failure")); ts.assertValues(1, 2, 3, 4, 5, 11, 12, 13, 14, 15) .assertNotComplete() .assertNoError(); ts.request(10); ts.assertValues(1, 2, 3, 4, 5, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) .assertNoError() .assertComplete(); }
@Test(expected = NullPointerException.class) public void failNullError() { EmitterProcessor.create().onError(null); }
@Test public void failDoubleError() { EmitterProcessor<Integer> ep = EmitterProcessor.create(); StepVerifier.create(ep) .then(() -> { assertThat(ep.getError()).isNull(); ep.onError(new Exception("test")); assertThat(ep.getError()).hasMessage("test"); ep.onError(new Exception("test2")); }) .expectErrorMessage("test") .verifyThenAssertThat() .hasDroppedErrorWithMessage("test2"); }
@Test public void acceptedErrorsArePassedToRegisteredConsumer() { // "Accepted errors are passed to a registered Consumer" // given: "a composable with a registered consumer of RuntimeExceptions" EmitterProcessor<Integer> composable = EmitterProcessor.create(); LongAdder errors = new LongAdder(); composable.doOnError(e -> errors.increment()).subscribe(); // when: "A RuntimeException is accepted" composable.onError(new RuntimeException()); // then: "it is passed to the consumer" assertThat(errors.intValue()).isEqualTo(1); // when: "A new error consumer is subscribed" Flux.error(new RuntimeException()).doOnError(e -> errors.increment()).subscribe(); // then: "it is called since publisher is in error state" assertThat(errors.intValue()).isEqualTo(2); }
@Test public void failCompleteThenError() { EmitterProcessor<Integer> ep = EmitterProcessor.create(); StepVerifier.create(ep) .then(() -> { ep.onComplete(); ep.onComplete();//noop ep.onError(new Exception("test")); }) .expectComplete() .verifyThenAssertThat() .hasDroppedErrorWithMessage("test"); }
@Test public void error() { AssertSubscriber<Integer> ts = AssertSubscriber.create(); EmitterProcessor<Integer> e = EmitterProcessor.create(); ConnectableFlux<Integer> p = e.publish(); p.subscribe(ts); p.connect(); e.onNext(1); e.onNext(2); e.onError(new RuntimeException("forced failure")); ts.assertValues(1, 2) .assertError(RuntimeException.class) .assertErrorWith( x -> Assert.assertTrue(x.getMessage().contains("forced failure"))) .assertNotComplete(); }