Search in sources :

Example 21 with PublishProcessor

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

the class FlowableReplayEagerTruncateTest method disposeNoNeedForResetTimeAndSIzeBound.

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

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

the class FlowableReplayEagerTruncateTest method disposeNoNeedForResetTimeBound.

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

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

the class FlowableRetryTest method unsubscribeFromRetry.

@Test
public void unsubscribeFromRetry() {
    PublishProcessor<Integer> processor = PublishProcessor.create();
    final AtomicInteger count = new AtomicInteger(0);
    Disposable sub = processor.retry().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer n) {
            count.incrementAndGet();
        }
    });
    processor.onNext(1);
    sub.dispose();
    processor.onNext(2);
    assertEquals(1, count.get());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Example 24 with PublishProcessor

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

the class FlowablePublishFunctionTest method oneStartOnly.

@Test
public void oneStartOnly() {
    final AtomicInteger startCount = new AtomicInteger();
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {

        @Override
        public void onStart() {
            startCount.incrementAndGet();
        }
    };
    PublishProcessor<Integer> pp = PublishProcessor.create();
    pp.publish(f -> f.take(1)).subscribe(ts);
    Assert.assertEquals(1, startCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) io.reactivex.rxjava3.exceptions(io.reactivex.rxjava3.exceptions) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TimeUnit(java.util.concurrent.TimeUnit) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) PublishProcessor(io.reactivex.rxjava3.processors.PublishProcessor) Functions(io.reactivex.rxjava3.internal.functions.Functions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) org.reactivestreams(org.reactivestreams) org.junit(org.junit) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) io.reactivex.rxjava3.testsupport(io.reactivex.rxjava3.testsupport) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber)

Example 25 with PublishProcessor

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

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