Search in sources :

Example 1 with TestSubscriberEx

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

the class FlowableOnBackpressureReduceTest method exceptionFromReducer.

@Test
public void exceptionFromReducer() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<>(0);
    source.onBackpressureReduce((l, r) -> {
        throw new TestException("Test exception");
    }).subscribe(ts);
    source.onNext(1);
    source.onNext(2);
    TestHelper.assertError(ts.errors(), 0, TestException.class, "Test exception");
}
Also used : Flowable(io.reactivex.rxjava3.core.Flowable) TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestSubscriberEx(io.reactivex.rxjava3.testsupport.TestSubscriberEx) Test(org.junit.Test) Random(java.util.Random) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) TimeUnit(java.util.concurrent.TimeUnit) PublishProcessor(io.reactivex.rxjava3.processors.PublishProcessor) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) BiFunction(io.reactivex.rxjava3.functions.BiFunction) Assert(org.junit.Assert) TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriberEx(io.reactivex.rxjava3.testsupport.TestSubscriberEx) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 2 with TestSubscriberEx

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

the class FlowableOnBackpressureReduceWithTest method exceptionFromSupplier.

@Test
public void exceptionFromSupplier() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    TestSubscriberEx<List<Integer>> ts = new TestSubscriberEx<>(0L);
    source.onBackpressureReduce(() -> {
        throw new TestException("Test exception");
    }, createTestReducer()).subscribe(ts);
    source.onNext(1);
    source.onNext(2);
    TestHelper.assertError(ts.errors(), 0, TestException.class, "Test exception");
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriberEx(io.reactivex.rxjava3.testsupport.TestSubscriberEx) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 3 with TestSubscriberEx

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

the class FlowableMapTest method mapFilterMapperCrashFused.

@Test
public void mapFilterMapperCrashFused() {
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<Integer>().setInitialFusionMode(QueueFuseable.ANY);
    Flowable.range(1, 2).hide().map(new Function<Integer, Integer>() {

        @Override
        public Integer apply(Integer v) throws Exception {
            throw new TestException();
        }
    }).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer v) throws Exception {
            return true;
        }
    }).subscribe(ts);
    ts.assertFuseable().assertFusionMode(QueueFuseable.NONE).assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException)

Example 4 with TestSubscriberEx

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

the class TestSubscriberExTest method interruptTerminalEventAwaitAndUnsubscribe.

@Test
public void interruptTerminalEventAwaitAndUnsubscribe() {
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
    final Thread t0 = Thread.currentThread();
    Worker w = Schedulers.computation().createWorker();
    try {
        w.schedule(new Runnable() {

            @Override
            public void run() {
                t0.interrupt();
            }
        }, 200, TimeUnit.MILLISECONDS);
        try {
            ts.awaitDone(5, TimeUnit.SECONDS);
        } catch (RuntimeException allowed) {
            assertTrue(allowed.toString(), allowed.getCause() instanceof InterruptedException);
        }
        ts.dispose();
        if (!ts.isCancelled()) {
            fail("Did not unsubscribe!");
        }
    } finally {
        w.dispose();
    }
}
Also used : Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Example 5 with TestSubscriberEx

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

the class TestSubscriberExTest method interruptTerminalEventAwaitTimed.

@Test
public void interruptTerminalEventAwaitTimed() {
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
    final Thread t0 = Thread.currentThread();
    Worker w = Schedulers.computation().createWorker();
    try {
        w.schedule(new Runnable() {

            @Override
            public void run() {
                t0.interrupt();
            }
        }, 200, TimeUnit.MILLISECONDS);
        try {
            if (ts.await(5, TimeUnit.SECONDS)) {
                fail("Did not interrupt wait!");
            }
        } catch (InterruptedException expected) {
        // expected
        }
    } finally {
        // clear interrupted flag
        Thread.interrupted();
        w.dispose();
    }
}
Also used : Worker(io.reactivex.rxjava3.core.Scheduler.Worker) 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