Search in sources :

Example 81 with BooleanSubscription

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

the class BoundedSubscriberTest method cancel.

@Test
public void cancel() {
    BoundedSubscriber<Integer> subscriber = new BoundedSubscriber<>(Functions.<Integer>emptyConsumer(), Functions.<Throwable>emptyConsumer(), Functions.EMPTY_ACTION, Functions.<Subscription>boundedConsumer(128), 128);
    BooleanSubscription bs = new BooleanSubscription();
    subscriber.onSubscribe(bs);
    subscriber.cancel();
    assertTrue(bs.isCancelled());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 82 with BooleanSubscription

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

the class BoundedSubscriberTest method dispose.

@Test
public void dispose() {
    BoundedSubscriber<Integer> subscriber = new BoundedSubscriber<>(Functions.<Integer>emptyConsumer(), Functions.<Throwable>emptyConsumer(), Functions.EMPTY_ACTION, Functions.<Subscription>boundedConsumer(128), 128);
    BooleanSubscription bs = new BooleanSubscription();
    subscriber.onSubscribe(bs);
    assertFalse(subscriber.isDisposed());
    subscriber.dispose();
    assertTrue(bs.isCancelled());
    assertTrue(subscriber.isDisposed());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 83 with BooleanSubscription

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

the class FutureSubscriberTest method onSubscribe.

@Test
public void onSubscribe() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        BooleanSubscription s = new BooleanSubscription();
        fs.onSubscribe(s);
        BooleanSubscription s2 = new BooleanSubscription();
        fs.onSubscribe(s2);
        assertFalse(s.isCancelled());
        assertTrue(s2.isCancelled());
        TestHelper.assertError(errors, 0, IllegalStateException.class, "Subscription already set!");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest)

Example 84 with BooleanSubscription

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

the class FutureSubscriberTest method onCompleteCancelRace.

@Test
@SuppressUndeliverable
public void onCompleteCancelRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final FutureSubscriber<Integer> fs = new FutureSubscriber<>();
        if (i % 3 == 0) {
            fs.onSubscribe(new BooleanSubscription());
        }
        if (i % 2 == 0) {
            fs.onNext(1);
        }
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                fs.cancel(false);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                fs.onComplete();
            }
        };
        TestHelper.race(r1, r2);
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest)

Example 85 with BooleanSubscription

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

the class LambdaSubscriberTest 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<>();
    LambdaSubscriber<Object> subscriber = new LambdaSubscriber<>(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(Long.MAX_VALUE);
        }
    });
    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