Search in sources :

Example 1 with ForEachWhileSubscriber

use of io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber in project RxJava by ReactiveX.

the class FlowableSubscriberTest method doubleSubscribe.

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

        @Override
        public boolean test(Integer v) throws Exception {
            return true;
        }
    }, Functions.<Throwable>emptyConsumer(), Functions.EMPTY_ACTION);
    List<Throwable> list = TestHelper.trackPluginErrors();
    try {
        s.onSubscribe(new BooleanSubscription());
        BooleanSubscription bs = new BooleanSubscription();
        s.onSubscribe(bs);
        assertTrue(bs.isCancelled());
        TestHelper.assertError(list, 0, IllegalStateException.class, "Subscription already set!");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : ForEachWhileSubscriber(io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 2 with ForEachWhileSubscriber

use of io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber in project RxJava by ReactiveX.

the class FlowableSubscriberTest method onNextCrashes.

@Test
public void onNextCrashes() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    ts.onSubscribe(new BooleanSubscription());
    ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(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.rxjava3.internal.subscriptions.BooleanSubscription) ForEachWhileSubscriber(io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber) Test(org.junit.Test)

Example 3 with ForEachWhileSubscriber

use of io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber in project RxJava by ReactiveX.

the class FlowableSubscriberTest method suppressAfterCompleteEvents.

@Test
public void suppressAfterCompleteEvents() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final TestSubscriber<Integer> ts = new TestSubscriber<>();
        ts.onSubscribe(new BooleanSubscription());
        ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(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();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) ForEachWhileSubscriber(io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber) Test(org.junit.Test)

Example 4 with ForEachWhileSubscriber

use of io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber in project RxJava by ReactiveX.

the class FlowableSubscriberTest method onErrorThrows.

@Test
public void onErrorThrows() {
    ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(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.rxjava3.internal.subscribers.ForEachWhileSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 5 with ForEachWhileSubscriber

use of io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber in project RxJava by ReactiveX.

the class FlowableSubscriberTest method onCompleteThrows.

@Test
public void onCompleteThrows() {
    ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(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.rxjava3.internal.subscribers.ForEachWhileSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Aggregations

ForEachWhileSubscriber (io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber)5 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)5 Test (org.junit.Test)5