Search in sources :

Example 21 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class SingleFlatMapTest method flatMapPublisherCancelDuringSingle.

@Test
public void flatMapPublisherCancelDuringSingle() {
    final AtomicBoolean disposed = new AtomicBoolean();
    TestSubscriberEx<Integer> ts = Single.<Integer>never().doOnDispose(new Action() {

        @Override
        public void run() throws Exception {
            disposed.set(true);
        }
    }).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

        @Override
        public Publisher<Integer> apply(Integer v) throws Exception {
            return Flowable.range(v, 5);
        }
    }).to(TestHelper.<Integer>testConsumer()).assertNoValues().assertNotTerminated();
    assertFalse(disposed.get());
    ts.cancel();
    assertTrue(disposed.get());
    ts.assertNotTerminated();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 22 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class SingleFlatMapTest method flatMapPublisherCancelDuringFlowable.

@Test
public void flatMapPublisherCancelDuringFlowable() {
    final AtomicBoolean disposed = new AtomicBoolean();
    TestSubscriberEx<Integer> ts = Single.just(1).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

        @Override
        public Publisher<Integer> apply(Integer v) throws Exception {
            return Flowable.<Integer>never().doOnCancel(new Action() {

                @Override
                public void run() throws Exception {
                    disposed.set(true);
                }
            });
        }
    }).to(TestHelper.<Integer>testConsumer()).assertNoValues().assertNotTerminated();
    assertFalse(disposed.get());
    ts.cancel();
    assertTrue(disposed.get());
    ts.assertNotTerminated();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 23 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class StrictSubscriberTest method doubleOnSubscribe.

@Test
public void doubleOnSubscribe() {
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
    SubscriberWrapper<Integer> wrapper = new SubscriberWrapper<>(ts);
    new Flowable<Integer>() {

        @Override
        protected void subscribeActual(Subscriber<? super Integer> s) {
            BooleanSubscription b1 = new BooleanSubscription();
            s.onSubscribe(b1);
            BooleanSubscription b2 = new BooleanSubscription();
            s.onSubscribe(b2);
            assertTrue(b1.isCancelled());
            assertTrue(b2.isCancelled());
        }
    }.subscribe(wrapper);
    ts.assertFailure(IllegalStateException.class);
    assertTrue(ts.errors().toString(), ts.errors().get(0).getMessage().contains("2.12"));
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriberEx(io.reactivex.rxjava3.testsupport.TestSubscriberEx) Test(org.junit.Test)

Example 24 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class FlowableOnBackpressureReduceTest method createDelayedSubscriber.

private <T> TestSubscriberEx<T> createDelayedSubscriber() {
    return new TestSubscriberEx<T>(1L) {

        final Random rnd = new Random();

        @Override
        public void onNext(T t) {
            super.onNext(t);
            if (rnd.nextDouble() < 0.001) {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
            request(1);
        }
    };
}
Also used : Random(java.util.Random) TestSubscriberEx(io.reactivex.rxjava3.testsupport.TestSubscriberEx)

Example 25 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class FlowableIgnoreElementsTest method errorReceivedFlowable.

@Test
public void errorReceivedFlowable() {
    TestSubscriberEx<Object> ts = new TestSubscriberEx<>();
    TestException ex = new TestException("boo");
    Flowable.error(ex).ignoreElements().toFlowable().subscribe(ts);
    ts.assertNoValues();
    ts.assertTerminated();
    ts.assertError(TestException.class);
    ts.assertErrorMessage("boo");
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)26 TestException (io.reactivex.rxjava3.exceptions.TestException)15 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)12 Disposable (io.reactivex.rxjava3.disposables.Disposable)5 TestSubscriberEx (io.reactivex.rxjava3.testsupport.TestSubscriberEx)5 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)3 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)3 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)2 PublishProcessor (io.reactivex.rxjava3.processors.PublishProcessor)2 Random (java.util.Random)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Assert (org.junit.Assert)2 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 io.reactivex.rxjava3.exceptions (io.reactivex.rxjava3.exceptions)1 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)1 BiFunction (io.reactivex.rxjava3.functions.BiFunction)1 Functions (io.reactivex.rxjava3.internal.functions.Functions)1 FlattenIterableSubscriber (io.reactivex.rxjava3.internal.operators.flowable.FlowableFlattenIterable.FlattenIterableSubscriber)1