Search in sources :

Example 1 with PublishProcessor

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

the class FlowableFlatMapStreamTest method mapperThrowsWhenUpstreamErrors.

@Test
public void mapperThrowsWhenUpstreamErrors() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        PublishProcessor<Integer> pp = PublishProcessor.create();
        AtomicInteger counter = new AtomicInteger();
        TestSubscriber<Integer> ts = pp.hide().concatMapStream(v -> {
            if (counter.getAndIncrement() == 0) {
                return Stream.of(1, 2);
            }
            pp.onError(new IOException());
            throw new TestException();
        }).test();
        pp.onNext(1);
        pp.onNext(2);
        ts.assertFailure(IOException.class, 1, 2);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) java.util.stream(java.util.stream) IOException(java.io.IOException) Test(org.junit.Test) io.reactivex.rxjava3.exceptions(io.reactivex.rxjava3.exceptions) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) Mockito(org.mockito.Mockito) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with PublishProcessor

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

the class FlowableFlatMapStreamTest method upstreamCancelled.

@Test
public void upstreamCancelled() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    AtomicInteger calls = new AtomicInteger();
    TestSubscriber<Integer> ts = pp.flatMapStream(v -> Stream.of(v + 1, v + 2).onClose(() -> calls.getAndIncrement())).test(1);
    assertTrue(pp.hasSubscribers());
    pp.onNext(1);
    ts.assertValuesOnly(2);
    ts.cancel();
    assertFalse(pp.hasSubscribers());
    assertEquals(1, calls.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) java.util.stream(java.util.stream) IOException(java.io.IOException) Test(org.junit.Test) io.reactivex.rxjava3.exceptions(io.reactivex.rxjava3.exceptions) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) Mockito(org.mockito.Mockito) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 3 with PublishProcessor

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

the class FlowableZipIterableTest method zipIterableNextThrows.

@Test
public void zipIterableNextThrows() {
    PublishProcessor<String> r1 = PublishProcessor.create();
    /* define a Subscriber to receive aggregated events */
    Subscriber<String> subscriber = TestHelper.mockSubscriber();
    InOrder io = inOrder(subscriber);
    Iterable<String> r2 = new Iterable<String>() {

        @Override
        public Iterator<String> iterator() {
            return new Iterator<String>() {

                @Override
                public boolean hasNext() {
                    return true;
                }

                @Override
                public String next() {
                    throw new TestException();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            };
        }
    };
    r1.zipWith(r2, zipr2).subscribe(subscriber);
    r1.onError(new TestException());
    io.verify(subscriber).onError(any(TestException.class));
    verify(subscriber, never()).onNext(any(String.class));
    verify(subscriber, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) CrashingIterable(io.reactivex.rxjava3.internal.util.CrashingIterable) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 4 with PublishProcessor

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

the class MaybeAmbTest 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<Integer> to = Maybe.amb(Arrays.asList(pp0.singleElement(), pp1.singleElement())).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 5 with PublishProcessor

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

the class MaybeCacheTest method crossCancelOnError.

@Test
public void crossCancelOnError() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    PublishProcessor<Integer> pp = PublishProcessor.create();
    Maybe<Integer> source = pp.singleElement().cache();
    source.subscribe(Functions.emptyConsumer(), new Consumer<Object>() {

        @Override
        public void accept(Object v) throws Exception {
            ts.cancel();
        }
    });
    source.toFlowable().subscribe(ts);
    pp.onError(new TestException());
    ts.assertEmpty();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

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