Java Code Examples for io.reactivex.rxjava3.processors.PublishProcessor#onError()

The following examples show how to use io.reactivex.rxjava3.processors.PublishProcessor#onError() . 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: ReplayingShareFlowableTest.java    From RxReplayingShare with Apache License 2.0 6 votes vote down vote up
@Test public void errorClearsCacheAndResubscribes() {
  List<String> start = new ArrayList<>();
  start.add("initA");

  PublishProcessor<String> upstream = PublishProcessor.create();
  Flowable<String> replayed = upstream.startWithIterable(start).compose(ReplayingShare.<String>instance());

  TestSubscriber<String> subscriber1 = new TestSubscriber<>();
  replayed.subscribe(subscriber1);
  subscriber1.assertValues("initA");

  TestSubscriber<String> observer2 = new TestSubscriber<>();
  replayed.subscribe(observer2);
  subscriber1.assertValues("initA");

  RuntimeException r = new RuntimeException();
  upstream.onError(r);
  subscriber1.assertError(r);
  observer2.assertError(r);

  start.set(0, "initB");

  TestSubscriber<String> observer3 = new TestSubscriber<>();
  replayed.subscribe(observer3);
  observer3.assertValues("initB");
}
 
Example 2
Source File: ReplayingShareFlowableTest.java    From RxReplayingShare with Apache License 2.0 5 votes vote down vote up
@Test public void errorClearsCacheAndResubscribesStartingWithDefault() {
  List<String> start = new ArrayList<>();
  start.add("initA");

  PublishProcessor<String> upstream = PublishProcessor.create();
  Flowable<String> replayed =
      upstream.startWithIterable(start).compose(ReplayingShare.createWithDefault("default"));

  TestSubscriber<String> subscriber1 = new TestSubscriber<>();
  replayed.subscribe(subscriber1);
  subscriber1.assertValues("default", "initA");

  TestSubscriber<String> observer2 = new TestSubscriber<>();
  replayed.subscribe(observer2);
  subscriber1.assertValues("default", "initA");

  RuntimeException r = new RuntimeException();
  upstream.onError(r);
  subscriber1.assertError(r);
  observer2.assertError(r);

  start.set(0, "initB");

  TestSubscriber<String> observer3 = new TestSubscriber<>();
  replayed.subscribe(observer3);
  observer3.assertValues("default", "initB");
}
 
Example 3
Source File: UndeliverableTest.java    From akarnokd-misc with Apache License 2.0 4 votes vote down vote up
@Test
public void test() {
    RxJavaPlugins.setErrorHandler(error -> System.out.println(error));

    PublishProcessor<Integer> main = PublishProcessor.create();
    PublishProcessor<Integer> inner = PublishProcessor.create();

    // switchMapDelayError will delay all errors
    TestSubscriber<Integer> ts = main.switchMapDelayError(v -> inner).test();

    main.onNext(1);

    // the inner fails
    inner.onError(new IOException());

    // the consumer is still clueless
    ts.assertEmpty();

    // the consumer cancels
    ts.cancel();

}