Search in sources :

Example 51 with BooleanSubscription

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

the class FlowableTakeTest2 method cancelIgnored.

@Test
public void cancelIgnored() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> s) {
                BooleanSubscription bs = new BooleanSubscription();
                s.onSubscribe(bs);
                assertTrue(bs.isCancelled());
                s.onNext(1);
                s.onComplete();
                s.onError(new TestException());
                s.onSubscribe(null);
            }
        }.take(0).test().assertResult();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        TestHelper.assertError(errors, 1, NullPointerException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 52 with BooleanSubscription

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

the class FlowableTakeTest method multiTake.

@Test
public void multiTake() {
    final AtomicInteger count = new AtomicInteger();
    Flowable.unsafeCreate(new Publisher<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer> s) {
            BooleanSubscription bs = new BooleanSubscription();
            s.onSubscribe(bs);
            for (int i = 0; !bs.isCancelled(); i++) {
                System.out.println("Emit: " + i);
                count.incrementAndGet();
                s.onNext(i);
            }
        }
    }).take(100).take(1).blockingForEach(new Consumer<Integer>() {

        @Override
        public void accept(Integer t1) {
            System.out.println("Receive: " + t1);
        }
    });
    assertEquals(1, count.get());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 53 with BooleanSubscription

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

the class FlowableThrottleFirstTest method throttlingWithError.

@Test
public void throttlingWithError() {
    Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(Subscriber<? super String> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            Exception error = new TestException();
            // Should be published since it is first
            publishNext(subscriber, 100, "one");
            // Should be skipped since onError will arrive before the timeout expires
            publishNext(subscriber, 200, "two");
            // Should be published as soon as the timeout expires.
            publishError(subscriber, 300, error);
        }
    });
    Flowable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
    sampled.subscribe(subscriber);
    InOrder inOrder = inOrder(subscriber);
    scheduler.advanceTimeTo(400, TimeUnit.MILLISECONDS);
    inOrder.verify(subscriber).onNext("one");
    inOrder.verify(subscriber).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 54 with BooleanSubscription

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

the class FlowableThrottleFirstTest method throttlingWithCompleted.

@Test
public void throttlingWithCompleted() {
    Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(Subscriber<? super String> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            // publish as it's first
            publishNext(subscriber, 100, "one");
            // skip as it's last within the first 400
            publishNext(subscriber, 300, "two");
            // publish
            publishNext(subscriber, 900, "three");
            // skip
            publishNext(subscriber, 905, "four");
            // Should be published as soon as the timeout expires.
            publishCompleted(subscriber, 1000);
        }
    });
    Flowable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
    sampled.subscribe(subscriber);
    InOrder inOrder = inOrder(subscriber);
    scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
    inOrder.verify(subscriber, times(1)).onNext("one");
    inOrder.verify(subscriber, times(0)).onNext("two");
    inOrder.verify(subscriber, times(1)).onNext("three");
    inOrder.verify(subscriber, times(0)).onNext("four");
    inOrder.verify(subscriber, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 55 with BooleanSubscription

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

the class FlowableTimeoutWithSelectorTest method lateOnTimeoutError.

@Test
public void lateOnTimeoutError() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp = PublishProcessor.create();
            final Subscriber<?>[] sub = { null, null };
            final Flowable<Integer> pp2 = new Flowable<Integer>() {

                int count;

                @Override
                protected void subscribeActual(Subscriber<? super Integer> s) {
                    s.onSubscribe(new BooleanSubscription());
                    sub[count++] = s;
                }
            };
            TestSubscriber<Integer> ts = pp.timeout(Functions.justFunction(pp2)).test();
            pp.onNext(0);
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp.onNext(1);
                }
            };
            final Throwable ex = new TestException();
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    sub[0].onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            ts.assertValueAt(0, 0);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) 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