Search in sources :

Example 91 with PublishProcessor

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

the class FlowableTimeoutTests method shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout.

@Test
public void shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout() {
    PublishProcessor<String> other = PublishProcessor.create();
    Flowable<String> source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other);
    Subscriber<String> subscriber = TestHelper.mockSubscriber();
    TestSubscriber<String> ts = new TestSubscriber<>(subscriber);
    source.subscribe(ts);
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    underlyingSubject.onNext("One");
    testScheduler.advanceTimeBy(4, TimeUnit.SECONDS);
    underlyingSubject.onNext("Two");
    other.onNext("a");
    other.onNext("b");
    ts.cancel();
    // The following messages should not be delivered.
    other.onNext("c");
    other.onNext("d");
    other.onComplete();
    InOrder inOrder = inOrder(subscriber);
    inOrder.verify(subscriber, times(1)).onNext("One");
    inOrder.verify(subscriber, times(1)).onNext("a");
    inOrder.verify(subscriber, times(1)).onNext("b");
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber)

Example 92 with PublishProcessor

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

the class FlowableSkipTimedTest method skipTimedErrorAfterTime.

@Test
public void skipTimedErrorAfterTime() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Integer> source = PublishProcessor.create();
    Flowable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
    Subscriber<Object> subscriber = TestHelper.mockSubscriber();
    result.subscribe(subscriber);
    source.onNext(1);
    source.onNext(2);
    source.onNext(3);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    source.onNext(4);
    source.onNext(5);
    source.onNext(6);
    source.onError(new TestException());
    InOrder inOrder = inOrder(subscriber);
    inOrder.verify(subscriber, never()).onNext(1);
    inOrder.verify(subscriber, never()).onNext(2);
    inOrder.verify(subscriber, never()).onNext(3);
    inOrder.verify(subscriber).onNext(4);
    inOrder.verify(subscriber).onNext(5);
    inOrder.verify(subscriber).onNext(6);
    inOrder.verify(subscriber).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(subscriber, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 93 with PublishProcessor

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

the class FlowablePublishTest method disposeNoNeedForReset.

@Test
public void disposeNoNeedForReset() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    ConnectableFlowable<Integer> cf = pp.publish();
    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) Test(org.junit.Test)

Example 94 with PublishProcessor

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

the class FlowablePublishTest method disposeResets.

@Test
public void disposeResets() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    ConnectableFlowable<Integer> cf = pp.publish();
    assertFalse(pp.hasSubscribers());
    Disposable d = cf.connect();
    assertTrue(pp.hasSubscribers());
    d.dispose();
    assertFalse(pp.hasSubscribers());
    TestSubscriber<Integer> ts = cf.test();
    cf.connect();
    assertTrue(pp.hasSubscribers());
    pp.onNext(1);
    ts.assertValuesOnly(1);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Example 95 with PublishProcessor

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

the class FlowablePublishTest method subscribeDisconnectRace.

@Test
public void subscribeDisconnectRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final PublishProcessor<Integer> pp = PublishProcessor.create();
        final ConnectableFlowable<Integer> cf = pp.publish();
        final Disposable d = cf.connect();
        final TestSubscriber<Integer> ts = new TestSubscriber<>();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                d.dispose();
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                cf.subscribe(ts);
            }
        };
        TestHelper.race(r1, r2);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) 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