Search in sources :

Example 86 with BooleanSubscription

use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableReplayTest method badSource.

@Test
public void badSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> observer) {
                observer.onSubscribe(new BooleanSubscription());
                observer.onError(new TestException("First"));
                observer.onNext(1);
                observer.onError(new TestException("Second"));
                observer.onComplete();
            }
        }.replay().autoConnect().test().assertFailureAndMessage(TestException.class, "First");
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) TestSubscriber(io.reactivex.subscribers.TestSubscriber) ConnectableFlowable(io.reactivex.flowables.ConnectableFlowable)

Example 87 with BooleanSubscription

use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableReplayTest method delayedUpstreamOnSubscribe.

@Test
public void delayedUpstreamOnSubscribe() {
    final Subscriber<?>[] sub = { null };
    new Flowable<Integer>() {

        @Override
        protected void subscribeActual(Subscriber<? super Integer> s) {
            sub[0] = s;
        }
    }.replay().connect().dispose();
    BooleanSubscription bs = new BooleanSubscription();
    sub[0].onSubscribe(bs);
    assertTrue(bs.isCancelled());
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber)

Example 88 with BooleanSubscription

use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableRetryTest method testSourceObservableCallsUnsubscribe.

@Test
public void testSourceObservableCallsUnsubscribe() throws InterruptedException {
    final AtomicInteger subsCount = new AtomicInteger(0);
    final TestSubscriber<String> ts = new TestSubscriber<String>();
    Publisher<String> onSubscribe = new Publisher<String>() {

        @Override
        public void subscribe(Subscriber<? super String> s) {
            BooleanSubscription bs = new BooleanSubscription();
            // https://github.com/ReactiveX/RxJava/issues/1024
            if (!bs.isCancelled()) {
                subsCount.incrementAndGet();
                s.onError(new RuntimeException("failed"));
                // it unsubscribes the child directly
                // this simulates various error/completion scenarios that could occur
                // or just a source that proactively triggers cleanup
                // FIXME can't unsubscribe child
                //                    s.unsubscribe();
                bs.cancel();
            } else {
                s.onError(new RuntimeException());
            }
        }
    };
    Flowable.unsafeCreate(onSubscribe).retry(3).subscribe(ts);
    // 1 + 3 retries
    assertEquals(4, subsCount.get());
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 89 with BooleanSubscription

use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableMergeDelayErrorTest method testMergeSourceWhichDoesntPropagateExceptionBack.

@Test
@Ignore("Subscribers should not throw")
public void testMergeSourceWhichDoesntPropagateExceptionBack() {
    Flowable<Integer> source = Flowable.unsafeCreate(new Publisher<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer> t1) {
            t1.onSubscribe(new BooleanSubscription());
            try {
                t1.onNext(0);
            } catch (Throwable swallow) {
            }
            t1.onNext(1);
            t1.onComplete();
        }
    });
    Flowable<Integer> result = Flowable.mergeDelayError(source, Flowable.just(2));
    final Subscriber<Integer> o = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(o);
    result.subscribe(new DefaultSubscriber<Integer>() {

        int calls;

        @Override
        public void onNext(Integer t) {
            if (calls++ == 0) {
                throw new TestException();
            }
            o.onNext(t);
        }

        @Override
        public void onError(Throwable e) {
            o.onError(e);
        }

        @Override
        public void onComplete() {
            o.onComplete();
        }
    });
    /*
         * If the child onNext throws, why would we keep accepting values from
         * other sources?
         */
    inOrder.verify(o).onNext(2);
    inOrder.verify(o, never()).onNext(0);
    inOrder.verify(o, never()).onNext(1);
    inOrder.verify(o, never()).onNext(anyInt());
    inOrder.verify(o).onError(any(TestException.class));
    verify(o, never()).onComplete();
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 90 with BooleanSubscription

use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableElementAtTest method badSource.

@Test
public void badSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> subscriber) {
                subscriber.onSubscribe(new BooleanSubscription());
                subscriber.onNext(1);
                subscriber.onNext(2);
                subscriber.onError(new TestException());
                subscriber.onComplete();
            }
        }.elementAt(0).toFlowable().test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
    TestHelper.checkBadSourceFlowable(new Function<Flowable<Integer>, Object>() {

        @Override
        public Object apply(Flowable<Integer> f) throws Exception {
            return f.elementAt(0);
        }
    }, false, null, 1);
    TestHelper.checkBadSourceFlowable(new Function<Flowable<Integer>, Object>() {

        @Override
        public Object apply(Flowable<Integer> f) throws Exception {
            return f.elementAt(0, 1);
        }
    }, false, null, 1, 1);
    TestHelper.checkBadSourceFlowable(new Function<Flowable<Integer>, Object>() {

        @Override
        public Object apply(Flowable<Integer> f) throws Exception {
            return f.elementAt(0).toFlowable();
        }
    }, false, null, 1);
    TestHelper.checkBadSourceFlowable(new Function<Flowable<Integer>, Object>() {

        @Override
        public Object apply(Flowable<Integer> f) throws Exception {
            return f.elementAt(0, 1).toFlowable();
        }
    }, false, null, 1, 1);
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.exceptions.TestException) TestException(io.reactivex.exceptions.TestException)

Aggregations

BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)131 Test (org.junit.Test)70 TestSubscriber (io.reactivex.subscribers.TestSubscriber)31 TestException (io.reactivex.exceptions.TestException)24 InOrder (org.mockito.InOrder)21 IOException (java.io.IOException)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 BooleanSupplier (io.reactivex.functions.BooleanSupplier)5 ForEachWhileSubscriber (io.reactivex.internal.subscribers.ForEachWhileSubscriber)5 ArrayDeque (java.util.ArrayDeque)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 Disposable (io.reactivex.disposables.Disposable)4 GroupedFlowable (io.reactivex.flowables.GroupedFlowable)4 Subscriber (org.reactivestreams.Subscriber)4 BaseObserveOnSubscriber (io.reactivex.internal.operators.flowable.FlowableObserveOn.BaseObserveOnSubscriber)3 Worker (io.reactivex.Scheduler.Worker)2 Nullable (io.reactivex.annotations.Nullable)2 ConnectableFlowable (io.reactivex.flowables.ConnectableFlowable)2 SubscribeOnSubscriber (io.reactivex.internal.operators.flowable.FlowableSubscribeOn.SubscribeOnSubscriber)2 FutureSubscriber (io.reactivex.internal.subscribers.FutureSubscriber)2