Search in sources :

Example 61 with TestSubscriber

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

the class FlowableTimeoutWithSelectorTest method lateOnTimeoutFallbackRace.

@Test
public void lateOnTimeoutFallbackRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp = PublishProcessor.create();
            final Subscriber<?>[] sub = { null, null };
            final Flowable<Integer> pp2 = new Flowable<Integer>() {

                int count;

                @Override
                protected void subscribeActual(Subscriber<? super Integer> s) {
                    assertFalse(((Disposable) s).isDisposed());
                    s.onSubscribe(new BooleanSubscription());
                    sub[count++] = s;
                }
            };
            TestSubscriber<Integer> ts = pp.timeout(Functions.justFunction(pp2), Flowable.<Integer>never()).test();
            pp.onNext(0);
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp.onNext(1);
                }
            };
            final Throwable ex = new TestException();
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    sub[0].onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            ts.assertValueAt(0, 0);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 62 with TestSubscriber

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

the class FlowableTimeoutWithSelectorTest method onCompleteOnTimeoutRaceFallback.

@Test
public void onCompleteOnTimeoutRaceFallback() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp = PublishProcessor.create();
            final Subscriber<?>[] sub = { null, null };
            final Flowable<Integer> pp2 = new Flowable<Integer>() {

                int count;

                @Override
                protected void subscribeActual(Subscriber<? super Integer> s) {
                    assertFalse(((Disposable) s).isDisposed());
                    s.onSubscribe(new BooleanSubscription());
                    sub[count++] = s;
                }
            };
            TestSubscriber<Integer> ts = pp.timeout(Functions.justFunction(pp2), Flowable.<Integer>never()).test();
            pp.onNext(0);
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp.onComplete();
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    sub[0].onComplete();
                }
            };
            TestHelper.race(r1, r2);
            ts.assertValueAt(0, 0);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 63 with TestSubscriber

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

the class FlowableTimerTest method timerInterruptible.

@Test
public void timerInterruptible() throws Exception {
    ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
    try {
        for (Scheduler s : new Scheduler[] { Schedulers.single(), Schedulers.computation(), Schedulers.newThread(), Schedulers.io(), Schedulers.from(exec, true) }) {
            final AtomicBoolean interrupted = new AtomicBoolean();
            TestSubscriber<Long> ts = Flowable.timer(1, TimeUnit.MILLISECONDS, s).map(new Function<Long, Long>() {

                @Override
                public Long apply(Long v) throws Exception {
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException ex) {
                        interrupted.set(true);
                    }
                    return v;
                }
            }).test();
            Thread.sleep(500);
            ts.cancel();
            Thread.sleep(500);
            assertTrue(s.getClass().getSimpleName(), interrupted.get());
        }
    } finally {
        exec.shutdown();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Function(io.reactivex.rxjava3.functions.Function)

Example 64 with TestSubscriber

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

the class ParallelJoinTest method overflowSlowpathDelayError.

@Test
public void overflowSlowpathDelayError() {
    @SuppressWarnings("unchecked") final Subscriber<? super Integer>[] subs = new Subscriber[1];
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1) {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            if (t == 1) {
                subs[0].onNext(2);
                subs[0].onNext(3);
            }
        }
    };
    new ParallelFlowable<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer>[] subscribers) {
            subs[0] = subscribers[0];
            subscribers[0].onSubscribe(new BooleanSubscription());
            subscribers[0].onNext(1);
        }

        @Override
        public int parallelism() {
            return 1;
        }
    }.sequentialDelayError(1).subscribe(ts);
    ts.request(1);
    ts.assertFailure(MissingBackpressureException.class, 1, 2);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Subscriber(org.reactivestreams.Subscriber) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 65 with TestSubscriber

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

the class ParallelJoinTest method overflowSlowpath.

@Test
public void overflowSlowpath() {
    @SuppressWarnings("unchecked") final Subscriber<? super Integer>[] subs = new Subscriber[1];
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1) {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            subs[0].onNext(2);
            subs[0].onNext(3);
        }
    };
    new ParallelFlowable<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer>[] subscribers) {
            subs[0] = subscribers[0];
            subscribers[0].onSubscribe(new BooleanSubscription());
            subscribers[0].onNext(1);
        }

        @Override
        public int parallelism() {
            return 1;
        }
    }.sequential(1).subscribe(ts);
    ts.assertFailure(MissingBackpressureException.class, 1);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Subscriber(org.reactivestreams.Subscriber) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) 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