@Test public void testErrorInParentObservableDelayed() throws Exception { for (int i = 0; i < 50; i++) { final TestASynchronous1sDelayedObservable o1 = new TestASynchronous1sDelayedObservable(); final TestASynchronous1sDelayedObservable o2 = new TestASynchronous1sDelayedObservable(); Observable<Observable<String>> parentObservable = Observable.create( new Publisher<Observable<String>>() { @Override public void subscribe(Subscriber<? super Observable<String>> op) { op.onSubscribe(EmptySubscription.INSTANCE); op.onNext(Observable.create(o1)); op.onNext(Observable.create(o2)); op.onError(new NullPointerException("throwing exception in parent")); } }); Subscriber<String> stringObserver = TestHelper.mockSubscriber(); TestSubscriber<String> ts = new TestSubscriber<>(stringObserver); Observable<String> m = Observable.mergeDelayError(parentObservable); m.subscribe(ts); System.out.println("testErrorInParentObservableDelayed | " + i); ts.awaitTerminalEvent(2000, TimeUnit.MILLISECONDS); ts.assertTerminated(); verify(stringObserver, times(2)).onNext("hello"); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); verify(stringObserver, never()).onComplete(); } }
@Test public void testDelayErrorMaxConcurrent() { final List<Long> requests = new ArrayList<>(); Observable<Integer> source = Observable.mergeDelayError( Observable.just( Observable.just(1).asObservable(), Observable.<Integer>error(new TestException())) .doOnRequest( new LongConsumer() { @Override public void accept(long t1) { requests.add(t1); } }), 1); TestSubscriber<Integer> ts = new TestSubscriber<>(); source.subscribe(ts); ts.assertValue(1); ts.assertTerminated(); ts.assertError(TestException.class); assertEquals(Arrays.asList(1L, 1L, 1L), requests); }
@Test public void testErrorInParentObservable() { TestSubscriber<Integer> ts = new TestSubscriber<>(); Observable.mergeDelayError( Observable.just(Observable.just(1), Observable.just(2)) .startWith(Observable.<Integer>error(new RuntimeException()))) .subscribe(ts); ts.awaitTerminalEvent(); ts.assertTerminated(); ts.assertValues(1, 2); assertEquals(1, ts.errorCount()); }
@Test public void testScanWithRequestOne() { Observable<Integer> o = Observable.just(1, 2) .scan( 0, new BiFunction<Integer, Integer, Integer>() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }) .take(1); TestSubscriber<Integer> subscriber = new TestSubscriber<>(); o.subscribe(subscriber); subscriber.assertValue(0); subscriber.assertTerminated(); subscriber.assertNoErrors(); }