Search in sources :

Example 86 with BooleanSubscription

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

the class QueueDrainSubscriberTest method unorderedFastPathReject.

@Test
public void unorderedFastPathReject() {
    TestSubscriber<Integer> ts = new TestSubscriber<>(1);
    Disposable d = Disposable.empty();
    QueueDrainSubscriber<Integer, Integer, Integer> qd = createUnorderedReject(ts, d);
    ts.onSubscribe(new BooleanSubscription());
    qd.requested(1);
    qd.onNext(1);
    ts.assertValuesOnly(1);
    assertEquals(1, qd.requested());
}
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 87 with BooleanSubscription

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

the class QueueDrainSubscriberTest method orderedOnNextRace.

@Test
public void orderedOnNextRace() {
    for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
        TestSubscriber<Integer> ts = new TestSubscriber<>(1);
        Disposable d = Disposable.empty();
        final QueueDrainSubscriber<Integer, Integer, Integer> qd = createOrdered(ts, d);
        ts.onSubscribe(new BooleanSubscription());
        qd.requested(Long.MAX_VALUE);
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                qd.onNext(1);
            }
        };
        TestHelper.race(r1, r1);
        ts.assertValuesOnly(1, 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 88 with BooleanSubscription

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

the class StrictSubscriberTest method cancelAfterOnComplete.

@Test
public void cancelAfterOnComplete() {
    final List<Object> list = new ArrayList<>();
    Subscriber<Object> sub = new Subscriber<Object>() {

        Subscription upstream;

        @Override
        public void onSubscribe(Subscription s) {
            this.upstream = s;
        }

        @Override
        public void onNext(Object t) {
            list.add(t);
        }

        @Override
        public void onError(Throwable t) {
            upstream.cancel();
            list.add(t);
        }

        @Override
        public void onComplete() {
            upstream.cancel();
            list.add("Done");
        }
    };
    new Flowable<Object>() {

        @Override
        protected void subscribeActual(Subscriber<? super Object> s) {
            BooleanSubscription b = new BooleanSubscription();
            s.onSubscribe(b);
            s.onComplete();
            list.add(b.isCancelled());
        }
    }.subscribe(sub);
    assertEquals(Arrays.<Object>asList("Done", false), list);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 89 with BooleanSubscription

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

the class StrictSubscriberTest method cancelAfterOnError.

@Test
public void cancelAfterOnError() {
    final List<Object> list = new ArrayList<>();
    Subscriber<Object> sub = new Subscriber<Object>() {

        Subscription upstream;

        @Override
        public void onSubscribe(Subscription s) {
            this.upstream = s;
        }

        @Override
        public void onNext(Object t) {
            list.add(t);
        }

        @Override
        public void onError(Throwable t) {
            upstream.cancel();
            list.add(t.getMessage());
        }

        @Override
        public void onComplete() {
            upstream.cancel();
            list.add("Done");
        }
    };
    new Flowable<Object>() {

        @Override
        protected void subscribeActual(Subscriber<? super Object> s) {
            BooleanSubscription b = new BooleanSubscription();
            s.onSubscribe(b);
            s.onError(new TestException("Forced failure"));
            list.add(b.isCancelled());
        }
    }.subscribe(sub);
    assertEquals(Arrays.<Object>asList("Forced failure", false), list);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 90 with BooleanSubscription

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

the class SubscriberResourceWrapperTest method cancel.

@Test
public void cancel() {
    BooleanSubscription bs = new BooleanSubscription();
    Disposable d = Disposable.empty();
    s.setResource(d);
    s.onSubscribe(bs);
    assertFalse(d.isDisposed());
    assertFalse(s.isDisposed());
    ts.cancel();
    assertTrue(bs.isCancelled());
    assertTrue(d.isDisposed());
    assertTrue(s.isDisposed());
}
Also used : 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