@Override public void run() { p.onNext(1); } };
@Override public void onNext(Integer value) { if (++count == 1) { us.onNext(2); upstream.dispose(); cdl.countDown(); } }
@Override public void onNext(T t) { if (fastEnter()) { for (UnicastSubject<T> w : windows) { w.onNext(t); } if (leave(-1) == 0) { return; } } else { queue.offer(t); if (!enter()) { return; } } drainLoop(); }
@Test public void fusionOfflineFailFastMultipleEvents() { UnicastSubject<Integer> ap = UnicastSubject.create(false); ap.onNext(1); ap.onNext(2); ap.onNext(3); ap.onComplete(); TestObserver<Integer> to = ObserverFusion.newTest(QueueFuseable.ANY); ap.subscribe(to); to .assertValueCount(3) .assertComplete(); }
@Override public void onNext(T t) { if (terminated) { return; } if (fastEnter()) { window.onNext(t); if (leave(-1) == 0) { return; } } else { queue.offer(NotificationLite.next(t)); if (!enter()) { return; } } drainLoop(); }
@Override public void onNext(T t) { if (fastEnter()) { for (UnicastSubject<T> w : ws) { w.onNext(t); } if (leave(-1) == 0) { return; } } else { queue.offer(NotificationLite.next(t)); if (!enter()) { return; } } drainLoop(); }
@Test public void threeArgsFactoryFailFast() { Runnable noop = mock(Runnable.class); UnicastSubject<Integer> ap = UnicastSubject.create(16, noop, false); ap.onNext(1); ap.onError(new RuntimeException()); TestObserver<Integer> to = TestObserver.create(); ap.subscribe(to); to .assertValueCount(0) .assertError(RuntimeException.class); }
@Test public void threeArgsFactoryDelayError() { Runnable noop = mock(Runnable.class); UnicastSubject<Integer> ap = UnicastSubject.create(16, noop, true); ap.onNext(1); ap.onError(new RuntimeException()); TestObserver<Integer> to = TestObserver.create(); ap.subscribe(to); to .assertValueCount(1) .assertError(RuntimeException.class); }
@Test public void notFused() throws Exception { UnicastSubject<Integer> us = UnicastSubject.create(); TestObserver<Void> to = us.hide().concatMapCompletable(completableComplete(), 2).test(); us.onNext(1); us.onNext(2); us.onComplete(); to.assertComplete(); to.assertValueCount(0); to.assertNoErrors(); }
@Test public void failFast() { UnicastSubject<Integer> ap = UnicastSubject.create(false); ap.onNext(1); ap.onError(new RuntimeException()); TestObserver<Integer> to = TestObserver.create(); ap.subscribe(to); to .assertValueCount(0) .assertError(RuntimeException.class); }
@Test public void fusionOfflineFailFast() { UnicastSubject<Integer> ap = UnicastSubject.create(false); ap.onNext(1); ap.onError(new RuntimeException()); TestObserver<Integer> to = ObserverFusion.newTest(QueueFuseable.ANY); ap.subscribe(to); to .assertValueCount(0) .assertError(RuntimeException.class); }
@Test public void workerNotDisposedPrematurelyAsyncInNormalOut() { DisposeTrackingScheduler s = new DisposeTrackingScheduler(); UnicastSubject<Integer> up = UnicastSubject.create(); up.onNext(1); up.onComplete(); Observable.concat( up.observeOn(s), Observable.just(2) ) .test() .assertResult(1, 2); assertEquals(1, s.disposedCount.get()); }
@Test public void multiSubscriber() { UnicastSubject<Object> p = UnicastSubject.create(); TestObserver<Object> to = p.test(); p.test() .assertFailure(IllegalStateException.class); p.onNext(1); p.onComplete(); to.assertResult(1); }
@Test public void asyncFused() { UnicastSubject<Integer> us = UnicastSubject.create(); TestObserver<Integer> to = us.concatMap(new Function<Integer, ObservableSource<Integer>>() { @Override public ObservableSource<Integer> apply(Integer v) throws Exception { return Observable.range(v, 2); } }) .test(); us.onNext(1); us.onComplete(); to.assertResult(1, 2); }
@Test public void fuseAndTake() { UnicastSubject<Integer> us = UnicastSubject.create(); us.onNext(1); us.onComplete(); us.concatMapEager(new Function<Integer, ObservableSource<Integer>>() { @Override public ObservableSource<Integer> apply(Integer v) throws Exception { return Observable.just(1); } }) .take(1) .test() .assertResult(1); }
@Test public void asyncFused() throws Exception { UnicastSubject<Integer> us = UnicastSubject.create(); TestObserver<Void> to = us.concatMapCompletable(completableComplete(), 2).test(); us.onNext(1); us.onComplete(); to.assertComplete(); to.assertValueCount(0); }
@Test public void asyncFusion() { TestObserver<Object> to = new TestObserver<Object>(); to.setInitialFusionMode(QueueFuseable.ANY); UnicastSubject<Integer> up = UnicastSubject.create(); up .subscribe(to); up.onNext(1); up.onComplete(); to.assertSubscribed() .assertFuseable() .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1); }
@Test public void fusionOfflie() { UnicastSubject<Integer> ap = UnicastSubject.create(); ap.onNext(1); ap.onComplete(); TestObserver<Integer> to = ObserverFusion.newTest(QueueFuseable.ANY); ap.subscribe(to); to .assertOf(ObserverFusion.<Integer>assertFuseable()) .assertOf(ObserverFusion.<Integer>assertFusionMode(QueueFuseable.ASYNC)) .assertResult(1); }
@Test public void fusionLive() { UnicastSubject<Integer> ap = UnicastSubject.create(); TestObserver<Integer> to = ObserverFusion.newTest(QueueFuseable.ANY); ap.subscribe(to); to .assertOf(ObserverFusion.<Integer>assertFuseable()) .assertOf(ObserverFusion.<Integer>assertFusionMode(QueueFuseable.ASYNC)); to.assertNoValues().assertNoErrors().assertNotComplete(); ap.onNext(1); to.assertValue(1).assertNoErrors().assertNotComplete(); ap.onComplete(); to.assertResult(1); }