Search in sources :

Example 11 with SerializedSubscriber

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

the class SerializedSubscriberTest method dispose.

@Test
public void dispose() {
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
    BooleanSubscription bs = new BooleanSubscription();
    so.onSubscribe(bs);
    ts.cancel();
    assertTrue(bs.isCancelled());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 12 with SerializedSubscriber

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

the class SerializedSubscriberTest method onErrorQueuedUp.

@Test
@SuppressUndeliverable
public void onErrorQueuedUp() {
    AtomicReference<SerializedSubscriber<Integer>> ssRef = new AtomicReference<>();
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<Integer>() {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            ssRef.get().onNext(2);
            ssRef.get().onError(new TestException());
        }
    };
    final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts, true);
    ssRef.set(so);
    BooleanSubscription bs = new BooleanSubscription();
    so.onSubscribe(bs);
    so.onNext(1);
    ts.assertFailure(TestException.class, 1, 2);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 13 with SerializedSubscriber

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

the class SerializedSubscriberTest method onNextOnErrorRaceDelayError.

@Test
public void onNextOnErrorRaceDelayError() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        TestSubscriber<Integer> ts = new TestSubscriber<>();
        final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts, true);
        BooleanSubscription bs = new BooleanSubscription();
        so.onSubscribe(bs);
        final Throwable ex = new TestException();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                so.onError(ex);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                so.onNext(1);
            }
        };
        TestHelper.race(r1, r2);
        ts.awaitDone(5, TimeUnit.SECONDS).assertError(ex).assertNotComplete();
        assertTrue(ts.values().size() <= 1);
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 14 with SerializedSubscriber

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

the class SerializedSubscriberTest method errorReentry.

@Test
public void errorReentry() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final AtomicReference<Subscriber<Integer>> serial = new AtomicReference<>();
        TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {

            @Override
            public void onNext(Integer v) {
                serial.get().onError(new TestException());
                serial.get().onError(new TestException());
                super.onNext(v);
            }
        };
        SerializedSubscriber<Integer> sobs = new SerializedSubscriber<>(ts);
        sobs.onSubscribe(new BooleanSubscription());
        serial.set(sobs);
        sobs.onNext(1);
        ts.assertValue(1);
        ts.assertError(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 15 with SerializedSubscriber

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

the class SerializedSubscriberTest method onNextOnErrorRace.

@Test
public void onNextOnErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        TestSubscriber<Integer> ts = new TestSubscriber<>();
        final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
        BooleanSubscription bs = new BooleanSubscription();
        so.onSubscribe(bs);
        final Throwable ex = new TestException();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                so.onError(ex);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                so.onNext(1);
            }
        };
        TestHelper.race(r1, r2);
        ts.awaitDone(5, TimeUnit.SECONDS).assertError(ex).assertNotComplete();
        assertTrue(ts.values().size() <= 1);
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException)

Aggregations

BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)13 TestException (io.reactivex.rxjava3.exceptions.TestException)5 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)2 SerializedSubscriber (io.reactivex.rxjava3.subscribers.SerializedSubscriber)1