Search in sources :

Example 76 with TestSubscriber

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

the class HalfSerializerSubscriberTest method reentrantOnNextOnComplete.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantOnNextOnComplete() {
    final AtomicInteger wip = new AtomicInteger();
    final AtomicThrowable error = new AtomicThrowable();
    final Subscriber[] a = { null };
    final TestSubscriber ts = new TestSubscriber();
    FlowableSubscriber s = new FlowableSubscriber() {

        @Override
        public void onSubscribe(Subscription s) {
            ts.onSubscribe(s);
        }

        @Override
        public void onNext(Object t) {
            if (t.equals(1)) {
                HalfSerializer.onComplete(a[0], wip, error);
            }
            ts.onNext(t);
        }

        @Override
        public void onError(Throwable t) {
            ts.onError(t);
        }

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    };
    a[0] = s;
    s.onSubscribe(new BooleanSubscription());
    HalfSerializer.onNext(s, 1, wip, error);
    ts.assertResult(1);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 77 with TestSubscriber

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

the class HalfSerializerSubscriberTest method reentrantErrorOnError.

@Test
@SuppressUndeliverable
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantErrorOnError() {
    final AtomicInteger wip = new AtomicInteger();
    final AtomicThrowable error = new AtomicThrowable();
    final Subscriber[] a = { null };
    final TestSubscriber ts = new TestSubscriber();
    FlowableSubscriber s = new FlowableSubscriber() {

        @Override
        public void onSubscribe(Subscription s) {
            ts.onSubscribe(s);
        }

        @Override
        public void onNext(Object t) {
            ts.onNext(t);
        }

        @Override
        public void onError(Throwable t) {
            ts.onError(t);
            HalfSerializer.onError(a[0], new IOException(), wip, error);
        }

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    };
    a[0] = s;
    s.onSubscribe(new BooleanSubscription());
    HalfSerializer.onError(s, new TestException(), wip, error);
    ts.assertFailure(TestException.class);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) IOException(java.io.IOException) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 78 with TestSubscriber

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

the class DeferredScalarSubscriberTest method emissionRequestRace.

@Test
public void emissionRequestRace() {
    Worker w = Schedulers.computation().createWorker();
    try {
        for (int i = 0; i < 10000; i++) {
            final TestSubscriber<Integer> ts = TestSubscriber.create(0L);
            TestingDeferredScalarSubscriber ds = new TestingDeferredScalarSubscriber(ts);
            ds.setupDownstream();
            ds.onNext(1);
            final AtomicInteger ready = new AtomicInteger(2);
            w.schedule(new Runnable() {

                @Override
                public void run() {
                    ready.decrementAndGet();
                    while (ready.get() != 0) {
                    }
                    ts.request(1);
                }
            });
            ready.decrementAndGet();
            while (ready.get() != 0) {
            }
            ds.onComplete();
            ts.awaitDone(5, TimeUnit.SECONDS);
            ts.assertValues(1);
            ts.assertNoErrors();
            ts.assertComplete();
        }
    } finally {
        w.dispose();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Example 79 with TestSubscriber

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

the class QueueDrainSubscriberTest method acceptBadRequest.

@Test
public void acceptBadRequest() {
    TestSubscriber<Integer> ts = new TestSubscriber<>(0);
    Disposable d = Disposable.empty();
    QueueDrainSubscriber<Integer, Integer, Integer> qd = createUnordered(ts, d);
    ts.onSubscribe(new BooleanSubscription());
    assertTrue(qd.accept(ts, 0));
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        qd.requested(-1);
        TestHelper.assertError(errors, 0, IllegalArgumentException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
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 80 with TestSubscriber

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

the class QueueDrainSubscriberTest method orderedFastPathRequest1.

@Test
public void orderedFastPathRequest1() {
    TestSubscriber<Integer> ts = new TestSubscriber<>(1);
    Disposable d = Disposable.empty();
    QueueDrainSubscriber<Integer, Integer, Integer> qd = createOrdered(ts, d);
    ts.onSubscribe(new BooleanSubscription());
    qd.requested(1);
    qd.onNext(1);
    ts.assertValuesOnly(1);
}
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)

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