Search in sources :

Example 16 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class SingleZipIterableTest method innerErrorRace.

@Test
public void innerErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp0 = PublishProcessor.create();
            final PublishProcessor<Integer> pp1 = PublishProcessor.create();
            final TestObserver<Object> to = Single.zip(Arrays.asList(pp0.single(0), pp1.single(0)), addString).test();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp0.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    pp1.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            to.assertFailure(TestException.class);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 17 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor 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 18 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableReplayEagerTruncateTest method disposeNoNeedForResetSizeBound.

@Test
public void disposeNoNeedForResetSizeBound() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    ConnectableFlowable<Integer> cf = pp.replay(10, true);
    TestSubscriber<Integer> ts = cf.test();
    Disposable d = cf.connect();
    pp.onNext(1);
    d.dispose();
    ts = cf.test();
    ts.assertEmpty();
    cf.connect();
    ts.assertEmpty();
    pp.onNext(2);
    ts.assertValuesOnly(2);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Example 19 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableReplayEagerTruncateTest method noHeadRetentionErrorSize.

@Test
public void noHeadRetentionErrorSize() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    FlowableReplay<Integer> co = (FlowableReplay<Integer>) source.replay(1, true);
    co.test();
    co.connect();
    BoundedReplayBuffer<Integer> buf = (BoundedReplayBuffer<Integer>) (co.current.get().buffer);
    source.onNext(1);
    source.onNext(2);
    source.onError(new TestException());
    assertNull(buf.get().value);
    Object o = buf.get();
    buf.trimHead();
    assertSame(o, buf.get());
}
Also used : FlowableReplay(io.reactivex.rxjava3.internal.operators.flowable.FlowableReplay) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 20 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableReplayEagerTruncateTest method noHeadRetentionErrorTime.

@Test
public void noHeadRetentionErrorTime() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    FlowableReplay<Integer> co = (FlowableReplay<Integer>) source.replay(1, TimeUnit.MINUTES, Schedulers.computation(), true);
    co.test();
    co.connect();
    BoundedReplayBuffer<Integer> buf = (BoundedReplayBuffer<Integer>) (co.current.get().buffer);
    source.onNext(1);
    source.onNext(2);
    source.onError(new TestException());
    assertNull(buf.get().value);
    Object o = buf.get();
    buf.trimHead();
    assertSame(o, buf.get());
}
Also used : FlowableReplay(io.reactivex.rxjava3.internal.operators.flowable.FlowableReplay) TestException(io.reactivex.rxjava3.exceptions.TestException)

Aggregations

Test (org.junit.Test)124 TestException (io.reactivex.rxjava3.exceptions.TestException)88 InOrder (org.mockito.InOrder)25 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)24 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)18 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)18 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)18 Disposable (io.reactivex.rxjava3.disposables.Disposable)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Assert (org.junit.Assert)8 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)7 io.reactivex.rxjava3.exceptions (io.reactivex.rxjava3.exceptions)6 io.reactivex.rxjava3.processors (io.reactivex.rxjava3.processors)6 PublishProcessor (io.reactivex.rxjava3.processors.PublishProcessor)6 IOException (java.io.IOException)6 TimeUnit (java.util.concurrent.TimeUnit)6 Functions (io.reactivex.rxjava3.internal.functions.Functions)5 FlowableReplay (io.reactivex.rxjava3.internal.operators.flowable.FlowableReplay)4 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)4 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)4