Search in sources :

Example 26 with BooleanSubscription

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

the class ResourceSubscriberTest method dispose.

@Test
public void dispose() {
    TestResourceSubscriber<Integer> tc = new TestResourceSubscriber<>();
    tc.dispose();
    BooleanSubscription bs = new BooleanSubscription();
    tc.onSubscribe(bs);
    assertTrue(bs.isCancelled());
    assertEquals(0, tc.start);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 27 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription 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 28 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription 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 29 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription 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 30 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription 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)

Aggregations

BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)227 Test (org.junit.Test)152 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)81 TestException (io.reactivex.rxjava3.exceptions.TestException)40 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)32 IOException (java.io.IOException)26 InOrder (org.mockito.InOrder)19 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)12 Subscriber (org.reactivestreams.Subscriber)11 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 Assert (org.junit.Assert)10 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)8 Functions (io.reactivex.rxjava3.internal.functions.Functions)8 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)8 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)8 io.reactivex.rxjava3.processors (io.reactivex.rxjava3.processors)8 java.util (java.util)8