Search in sources :

Example 76 with BooleanSubscription

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

the class HalfSerializerSubscriberTest method onErrorOnCompleteRace.

@Test
@SuppressUndeliverable
public void onErrorOnCompleteRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final AtomicInteger wip = new AtomicInteger();
        final AtomicThrowable error = new AtomicThrowable();
        final TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
        ts.onSubscribe(new BooleanSubscription());
        final TestException ex = new TestException();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                HalfSerializer.onError(ts, ex, wip, error);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                HalfSerializer.onComplete(ts, wip, error);
            }
        };
        TestHelper.race(r1, r2);
        if (ts.completions() != 0) {
            ts.assertResult();
        } else {
            ts.assertFailure(TestException.class);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 77 with BooleanSubscription

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

the class QueueDrainSubscriberTest method acceptBadRequest.

@Test
public void acceptBadRequest() {
    TestSubscriber<Integer> ts = new TestSubscriber<>(0);
    Disposable d = Disposable.empty();
    QueueDrainSubscriber<Integer, Integer, Integer> qd = createUnordered(ts, d);
    ts.onSubscribe(new BooleanSubscription());
    assertTrue(qd.accept(ts, 0));
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        qd.requested(-1);
        TestHelper.assertError(errors, 0, IllegalArgumentException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 78 with BooleanSubscription

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

the class QueueDrainSubscriberTest method orderedFastPathRequest1.

@Test
public void orderedFastPathRequest1() {
    TestSubscriber<Integer> ts = new TestSubscriber<>(1);
    Disposable d = Disposable.empty();
    QueueDrainSubscriber<Integer, Integer, Integer> qd = createOrdered(ts, d);
    ts.onSubscribe(new BooleanSubscription());
    qd.requested(1);
    qd.onNext(1);
    ts.assertValuesOnly(1);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 79 with BooleanSubscription

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

the class QueueDrainSubscriberTest method unorderedSlowPath.

@Test
public void unorderedSlowPath() {
    TestSubscriber<Integer> ts = new TestSubscriber<>(1);
    Disposable d = Disposable.empty();
    QueueDrainSubscriber<Integer, Integer, Integer> qd = createUnordered(ts, d);
    ts.onSubscribe(new BooleanSubscription());
    qd.enter();
    qd.onNext(1);
    ts.assertEmpty();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 80 with BooleanSubscription

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

the class BoundedSubscriberTest method badSourceEmitAfterDone.

@Test
@SuppressUndeliverable
public void badSourceEmitAfterDone() {
    Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer> s) {
            BooleanSubscription s1 = new BooleanSubscription();
            s.onSubscribe(s1);
            s.onNext(1);
            s.onComplete();
            s.onNext(2);
            s.onError(new TestException());
            s.onComplete();
        }
    });
    final List<Object> received = new ArrayList<>();
    BoundedSubscriber<Object> subscriber = new BoundedSubscriber<>(new Consumer<Object>() {

        @Override
        public void accept(Object v) throws Exception {
            received.add(v);
        }
    }, new Consumer<Throwable>() {

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

        @Override
        public void run() throws Exception {
            received.add(100);
        }
    }, new Consumer<Subscription>() {

        @Override
        public void accept(Subscription s) throws Exception {
            s.request(128);
        }
    }, 128);
    source.subscribe(subscriber);
    assertEquals(Arrays.asList(1, 100), received);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

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