Search in sources :

Example 66 with TestSubscriber

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

the class AsyncProcessorTest method onErrorCrossCancel.

@Test
@SuppressUndeliverable
public void onErrorCrossCancel() {
    AsyncProcessor<Object> p = AsyncProcessor.create();
    final TestSubscriber<Object> ts2 = new TestSubscriber<>();
    TestSubscriber<Object> ts1 = new TestSubscriber<Object>() {

        @Override
        public void onError(Throwable t) {
            ts2.cancel();
            super.onError(t);
        }
    };
    p.subscribe(ts1);
    p.subscribe(ts2);
    p.onError(new TestException());
    ts1.assertFailure(TestException.class);
    ts2.assertEmpty();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 67 with TestSubscriber

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

the class SerializedProcessorTest method onErrorOnErrorRace.

@Test
public void onErrorOnErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final FlowableProcessor<Integer> s = PublishProcessor.<Integer>create().toSerialized();
        TestSubscriber<Integer> ts = s.test();
        final TestException ex = new TestException();
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    s.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    s.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            ts.assertFailure(TestException.class);
            TestHelper.assertUndeliverable(errors, 0, TestException.class);
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 68 with TestSubscriber

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

the class SerializedProcessorTest method normal.

@Test
public void normal() {
    FlowableProcessor<Integer> s = PublishProcessor.<Integer>create().toSerialized();
    TestSubscriber<Integer> ts = s.test();
    Flowable.range(1, 10).subscribe(s);
    ts.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    assertFalse(s.hasSubscribers());
    s.onNext(11);
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        s.onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
    s.onComplete();
    BooleanSubscription bs = new BooleanSubscription();
    s.onSubscribe(bs);
    assertTrue(bs.isCancelled());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 69 with TestSubscriber

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

the class FlowableBlockingTest method blockinsSubscribeCancelAsync.

@Test
public void blockinsSubscribeCancelAsync() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final TestSubscriber<Integer> ts = new TestSubscriber<>();
        final PublishProcessor<Integer> pp = PublishProcessor.create();
        final Runnable r1 = new Runnable() {

            @Override
            public void run() {
                ts.cancel();
            }
        };
        final Runnable r2 = new Runnable() {

            @Override
            public void run() {
                pp.onNext(1);
            }
        };
        final AtomicInteger c = new AtomicInteger(2);
        Schedulers.computation().scheduleDirect(new Runnable() {

            @Override
            public void run() {
                c.decrementAndGet();
                while (c.get() != 0 && !pp.hasSubscribers()) {
                }
                TestHelper.race(r1, r2);
            }
        });
        c.decrementAndGet();
        while (c.get() != 0) {
        }
        pp.blockingSubscribe(ts);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 70 with TestSubscriber

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

the class FlowableConcatMapSingleTest method cancelNoConcurrentClean.

@Test
public void cancelNoConcurrentClean() {
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    ConcatMapSingleSubscriber<Integer, Integer> operator = new ConcatMapSingleSubscriber<>(ts, Functions.justFunction(Single.<Integer>never()), 16, ErrorMode.IMMEDIATE);
    operator.onSubscribe(new BooleanSubscription());
    operator.queue.offer(1);
    operator.getAndIncrement();
    ts.cancel();
    assertFalse(operator.queue.isEmpty());
    operator.addAndGet(-2);
    operator.cancel();
    assertTrue(operator.queue.isEmpty());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) ConcatMapSingleSubscriber(io.reactivex.rxjava3.internal.operators.mixed.FlowableConcatMapSingle.ConcatMapSingleSubscriber) 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