Search in sources :

Example 36 with PublishProcessor

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

the class FlowableReplayTest method disposeNoNeedForResetTimeAndSIzeBound.

@Test
public void disposeNoNeedForResetTimeAndSIzeBound() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    ConnectableFlowable<Integer> cf = pp.replay(10, 10, TimeUnit.MINUTES);
    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 37 with PublishProcessor

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

the class FlowableReplayTest method disposeNoNeedForResetSizeBound.

@Test
public void disposeNoNeedForResetSizeBound() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    ConnectableFlowable<Integer> cf = pp.replay(10);
    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 38 with PublishProcessor

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

the class FlowableThrottleLatestTest method missingBackpressureExceptionLatestComplete.

@Test
public void missingBackpressureExceptionLatestComplete() throws Throwable {
    TestScheduler sch = new TestScheduler();
    Action onCancel = mock(Action.class);
    PublishProcessor<Integer> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = pp.doOnCancel(onCancel).throttleLatest(1, TimeUnit.SECONDS, sch, true).test(1);
    pp.onNext(1);
    pp.onNext(2);
    ts.assertValuesOnly(1);
    pp.onComplete();
    ts.assertFailure(MissingBackpressureException.class, 1);
    verify(onCancel, never()).run();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 39 with PublishProcessor

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

the class FlowableThrottleLatestTest method reentrantComplete.

@Test
public void reentrantComplete() {
    TestScheduler sch = new TestScheduler();
    final PublishProcessor<Integer> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            if (t == 1) {
                pp.onNext(2);
            }
            if (t == 2) {
                pp.onComplete();
            }
        }
    };
    pp.throttleLatest(1, TimeUnit.SECONDS, sch).subscribe(ts);
    pp.onNext(1);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertResult(1, 2);
}
Also used : TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 40 with PublishProcessor

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

the class FlowableTakeTimedTest method takeTimed.

@Test
public void takeTimed() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Integer> source = PublishProcessor.create();
    Flowable<Integer> result = source.take(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);
    InOrder inOrder = inOrder(subscriber);
    inOrder.verify(subscriber).onNext(1);
    inOrder.verify(subscriber).onNext(2);
    inOrder.verify(subscriber).onNext(3);
    inOrder.verify(subscriber).onComplete();
    inOrder.verifyNoMoreInteractions();
    verify(subscriber, never()).onNext(4);
    verify(subscriber, never()).onError(any(Throwable.class));
}
Also used : InOrder(org.mockito.InOrder) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) 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