Search in sources :

Example 1 with BooleanSubscription

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

the class FlowableSubscriberTest method onNextCrashes.

@Test
public void onNextCrashes() {
    final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    ts.onSubscribe(new BooleanSubscription());
    ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<Integer>(new Predicate<Integer>() {

        @Override
        public boolean test(Integer v) throws Exception {
            throw new TestException();
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable e) throws Exception {
            ts.onError(e);
        }
    }, new Action() {

        @Override
        public void run() throws Exception {
            ts.onComplete();
        }
    });
    BooleanSubscription b = new BooleanSubscription();
    s.onSubscribe(b);
    s.onNext(1);
    assertTrue(b.isCancelled());
    ts.assertFailure(TestException.class);
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) ForEachWhileSubscriber(io.reactivex.internal.subscribers.ForEachWhileSubscriber)

Example 2 with BooleanSubscription

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

the class FlowableSubscriberTest method onCompleteThrows.

@Test
public void onCompleteThrows() {
    ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<Integer>(new Predicate<Integer>() {

        @Override
        public boolean test(Integer v) throws Exception {
            return true;
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable e) throws Exception {
        }
    }, new Action() {

        @Override
        public void run() throws Exception {
            throw new TestException("Inner");
        }
    });
    List<Throwable> list = TestHelper.trackPluginErrors();
    try {
        s.onSubscribe(new BooleanSubscription());
        s.onComplete();
        TestHelper.assertUndeliverable(list, 0, TestException.class, "Inner");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : ForEachWhileSubscriber(io.reactivex.internal.subscribers.ForEachWhileSubscriber) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription)

Example 3 with BooleanSubscription

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

the class FlowableSubscriberTest method onErrorThrows.

@Test
public void onErrorThrows() {
    ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<Integer>(new Predicate<Integer>() {

        @Override
        public boolean test(Integer v) throws Exception {
            return true;
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable e) throws Exception {
            throw new TestException("Inner");
        }
    }, new Action() {

        @Override
        public void run() throws Exception {
        }
    });
    List<Throwable> list = TestHelper.trackPluginErrors();
    try {
        s.onSubscribe(new BooleanSubscription());
        s.onError(new TestException("Outer"));
        TestHelper.assertError(list, 0, CompositeException.class);
        List<Throwable> cel = TestHelper.compositeList(list.get(0));
        TestHelper.assertError(cel, 0, TestException.class, "Outer");
        TestHelper.assertError(cel, 1, TestException.class, "Inner");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : ForEachWhileSubscriber(io.reactivex.internal.subscribers.ForEachWhileSubscriber) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription)

Example 4 with BooleanSubscription

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

the class FutureObserverTest method onCompleteCancelRace.

@Test
public void onCompleteCancelRace() {
    for (int i = 0; i < 500; i++) {
        final FutureSubscriber<Integer> fo = new FutureSubscriber<Integer>();
        if (i % 3 == 0) {
            fo.onSubscribe(new BooleanSubscription());
        }
        if (i % 2 == 0) {
            fo.onNext(1);
        }
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                fo.cancel(false);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                fo.onComplete();
            }
        };
        TestHelper.race(r1, r2, Schedulers.single());
    }
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) FutureSubscriber(io.reactivex.internal.subscribers.FutureSubscriber)

Example 5 with BooleanSubscription

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

the class FlowableSubscriberTest method suppressAfterCompleteEvents.

@Test
public void suppressAfterCompleteEvents() {
    final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    ts.onSubscribe(new BooleanSubscription());
    ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<Integer>(new Predicate<Integer>() {

        @Override
        public boolean test(Integer v) throws Exception {
            ts.onNext(v);
            return true;
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable e) throws Exception {
            ts.onError(e);
        }
    }, new Action() {

        @Override
        public void run() throws Exception {
            ts.onComplete();
        }
    });
    s.onComplete();
    s.onNext(1);
    s.onError(new TestException());
    s.onComplete();
    ts.assertResult();
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) ForEachWhileSubscriber(io.reactivex.internal.subscribers.ForEachWhileSubscriber)

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