Search in sources :

Example 21 with TestSubscriber

use of io.reactivex.rxjava3.subscribers.TestSubscriber 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 22 with TestSubscriber

use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowableOnErrorResumeNextViaFlowableTest method normalBackpressure.

@Test
public void normalBackpressure() {
    TestSubscriber<Integer> ts = TestSubscriber.create(0);
    PublishProcessor<Integer> pp = PublishProcessor.create();
    pp.onErrorResumeWith(Flowable.range(3, 2)).subscribe(ts);
    ts.request(2);
    pp.onNext(1);
    pp.onNext(2);
    pp.onError(new TestException("Forced failure"));
    ts.assertValues(1, 2);
    ts.assertNoErrors();
    ts.assertNotComplete();
    ts.request(2);
    ts.assertValues(1, 2, 3, 4);
    ts.assertNoErrors();
    ts.assertComplete();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 23 with TestSubscriber

use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowableOnErrorReturnTest method normalBackpressure.

@Test
public void normalBackpressure() {
    TestSubscriber<Integer> ts = TestSubscriber.create(0);
    PublishProcessor<Integer> pp = PublishProcessor.create();
    pp.onErrorReturn(new Function<Throwable, Integer>() {

        @Override
        public Integer apply(Throwable e) {
            return 3;
        }
    }).subscribe(ts);
    ts.request(2);
    pp.onNext(1);
    pp.onNext(2);
    pp.onError(new TestException("Forced failure"));
    ts.assertValues(1, 2);
    ts.assertNoErrors();
    ts.assertNotComplete();
    ts.request(2);
    ts.assertValues(1, 2, 3);
    ts.assertNoErrors();
    ts.assertComplete();
}
Also used : Function(io.reactivex.rxjava3.functions.Function) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 24 with TestSubscriber

use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowablePublishMulticastTest method dontDropItemsWhenNoReadyConsumers.

@Test
public void dontDropItemsWhenNoReadyConsumers() {
    final MulticastProcessor<Integer> mp = new MulticastProcessor<>(128, true);
    mp.onSubscribe(new BooleanSubscription());
    mp.onNext(1);
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    final MulticastSubscription<Integer> ms1 = new MulticastSubscription<>(ts, mp);
    ts.onSubscribe(ms1);
    assertTrue(mp.add(ms1));
    ms1.set(Long.MIN_VALUE);
    mp.drain();
    assertFalse(mp.queue.isEmpty());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 25 with TestSubscriber

use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.

the class FlowableRetryTest method repeatFloodNoSubscriptionError.

@Test
public void repeatFloodNoSubscriptionError() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    final TestException error = new TestException();
    try {
        final PublishProcessor<Integer> source = PublishProcessor.create();
        final PublishProcessor<Integer> signaller = PublishProcessor.create();
        for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
            TestSubscriber<Integer> ts = source.take(1).map(new Function<Integer, Integer>() {

                @Override
                public Integer apply(Integer v) throws Exception {
                    throw error;
                }
            }).retryWhen(new Function<Flowable<Throwable>, Flowable<Integer>>() {

                @Override
                public Flowable<Integer> apply(Flowable<Throwable> v) throws Exception {
                    return signaller;
                }
            }).test();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
                        source.onNext(1);
                    }
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
                        signaller.offer(1);
                    }
                }
            };
            TestHelper.race(r1, r2);
            ts.cancel();
        }
        if (!errors.isEmpty()) {
            for (Throwable e : errors) {
                e.printStackTrace();
            }
            fail(errors + "");
        }
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) GroupedFlowable(io.reactivex.rxjava3.flowables.GroupedFlowable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)169 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)116 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)106 TestException (io.reactivex.rxjava3.exceptions.TestException)56 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)27 TimeUnit (java.util.concurrent.TimeUnit)19 FlowableRxInvokerProvider (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider)18 FlowableRxInvoker (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker)17 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)15 IOException (java.io.IOException)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Flowable (io.reactivex.rxjava3.core.Flowable)13 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)13 ClientBuilder (javax.ws.rs.client.ClientBuilder)13 MediaType (javax.ws.rs.core.MediaType)13 AbstractResourceInfo (org.apache.cxf.jaxrs.model.AbstractResourceInfo)13 AbstractBusClientServerTestBase (org.apache.cxf.testutil.common.AbstractBusClientServerTestBase)13 Assert.assertTrue (org.junit.Assert.assertTrue)13 BeforeClass (org.junit.BeforeClass)13 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)12