Search in sources :

Example 51 with TestSubscriber

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

the class FlowableReplayTest method delayedUpstreamSubscription.

@Test
public void delayedUpstreamSubscription() {
    AtomicReference<Subscriber<? super Integer>> ref = new AtomicReference<>();
    Flowable<Integer> f = Flowable.<Integer>unsafeCreate(ref::set);
    TestSubscriber<Integer> ts = f.replay().autoConnect().test();
    AtomicLong requested = new AtomicLong();
    ref.get().onSubscribe(new Subscription() {

        @Override
        public void request(long n) {
            BackpressureHelper.add(requested, n);
        }

        @Override
        public void cancel() {
        }
    });
    assertEquals(Long.MAX_VALUE, requested.get());
    ref.get().onComplete();
    ts.assertResult();
}
Also used : TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 52 with TestSubscriber

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

the class FlowableReplayTest method disposeNoNeedForResetSizeBound.

@Test
public void disposeNoNeedForResetSizeBound() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    ConnectableFlowable<Integer> cf = pp.replay(10);
    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 53 with TestSubscriber

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

the class FlowableSwitchIfEmptyTest method requestsNotLost.

@Test
public void requestsNotLost() throws InterruptedException {
    final TestSubscriber<Long> ts = new TestSubscriber<>(0L);
    Flowable.unsafeCreate(new Publisher<Long>() {

        @Override
        public void subscribe(final Subscriber<? super Long> subscriber) {
            subscriber.onSubscribe(new Subscription() {

                final AtomicBoolean completed = new AtomicBoolean(false);

                @Override
                public void request(long n) {
                    if (n > 0 && completed.compareAndSet(false, true)) {
                        Schedulers.io().createWorker().schedule(new Runnable() {

                            @Override
                            public void run() {
                                subscriber.onComplete();
                            }
                        }, 100, TimeUnit.MILLISECONDS);
                    }
                }

                @Override
                public void cancel() {
                }
            });
        }
    }).switchIfEmpty(Flowable.fromIterable(Arrays.asList(1L, 2L, 3L))).subscribeOn(Schedulers.computation()).subscribe(ts);
    Thread.sleep(50);
    // request while first observable is still finishing (as empty)
    ts.request(1);
    ts.request(1);
    Thread.sleep(500);
    ts.assertNotComplete();
    ts.assertNoErrors();
    ts.assertValueCount(2);
    ts.cancel();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 54 with TestSubscriber

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

the class FlowableSubscribeOnTest method deferredRequestRace.

@Test
public void deferredRequestRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final TestSubscriber<Integer> ts = new TestSubscriber<>(0L);
        Worker w = Schedulers.computation().createWorker();
        final SubscribeOnSubscriber<Integer> so = new SubscribeOnSubscriber<>(ts, w, Flowable.<Integer>never(), true);
        ts.onSubscribe(so);
        final BooleanSubscription bs = new BooleanSubscription();
        try {
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    so.onSubscribe(bs);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    so.request(1);
                }
            };
            TestHelper.race(r1, r2);
        } finally {
            w.dispose();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) SubscribeOnSubscriber(io.reactivex.rxjava3.internal.operators.flowable.FlowableSubscribeOn.SubscribeOnSubscriber) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Example 55 with TestSubscriber

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

the class FlowableThrottleLatestTest method missingBackpressureExceptionLatestComplete.

@Test
public void missingBackpressureExceptionLatestComplete() throws Throwable {
    TestScheduler sch = new TestScheduler();
    Action onCancel = mock(Action.class);
    PublishProcessor<Integer> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = pp.doOnCancel(onCancel).throttleLatest(1, TimeUnit.SECONDS, sch, true).test(1);
    pp.onNext(1);
    pp.onNext(2);
    ts.assertValuesOnly(1);
    pp.onComplete();
    ts.assertFailure(MissingBackpressureException.class, 1);
    verify(onCancel, never()).run();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) 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