Search in sources :

Example 1 with SerializedSubscriber

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

the class SerializedSubscriberTest method startOnce.

@Test
public void startOnce() {
    List<Throwable> error = TestHelper.trackPluginErrors();
    try {
        TestSubscriber<Integer> ts = new TestSubscriber<>();
        final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
        so.onSubscribe(new BooleanSubscription());
        BooleanSubscription bs = new BooleanSubscription();
        so.onSubscribe(bs);
        assertTrue(bs.isCancelled());
        TestHelper.assertError(error, 0, IllegalStateException.class, "Subscription already set!");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 2 with SerializedSubscriber

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

the class SerializedSubscriberTest method onCompleteRace.

@Test
public void onCompleteRace() {
    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);
        Runnable r = new Runnable() {

            @Override
            public void run() {
                so.onComplete();
            }
        };
        TestHelper.race(r, r);
        ts.awaitDone(5, TimeUnit.SECONDS).assertResult();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 3 with SerializedSubscriber

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

the class SerializedSubscriberTest method onNextOnCompleteRace.

@Test
public void onNextOnCompleteRace() {
    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);
        Runnable r1 = new Runnable() {

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

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

Example 4 with SerializedSubscriber

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

the class SerializedSubscriberTest method onCompleteOnErrorRace.

@Test
public void onCompleteOnErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
            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.onComplete();
                }
            };
            TestHelper.race(r1, r2);
            ts.awaitDone(5, TimeUnit.SECONDS);
            if (ts.completions() != 0) {
                ts.assertResult();
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            } else {
                ts.assertFailure(TestException.class).assertError(ex);
                assertTrue("" + errors, errors.isEmpty());
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 5 with SerializedSubscriber

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

the class SerializedSubscriberTest method nullOnNext.

@Test
public void nullOnNext() {
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
    final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts);
    so.onSubscribe(new BooleanSubscription());
    so.onNext(null);
    ts.assertFailureAndMessage(NullPointerException.class, ExceptionHelper.nullWarning("onNext called with a null value."));
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

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