Search in sources :

Example 71 with TestSubscriber

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

the class FlowableConcatMapMaybeTest method cancelNoConcurrentClean.

@Test
public void cancelNoConcurrentClean() {
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    ConcatMapMaybeSubscriber<Integer, Integer> operator = new ConcatMapMaybeSubscriber<>(ts, Functions.justFunction(Maybe.<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) ConcatMapMaybeSubscriber(io.reactivex.rxjava3.internal.operators.mixed.FlowableConcatMapMaybe.ConcatMapMaybeSubscriber) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 72 with TestSubscriber

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

the class MaybeMergeArrayTest method errorRace.

@Test
public void errorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishSubject<Integer> ps1 = PublishSubject.create();
            final PublishSubject<Integer> ps2 = PublishSubject.create();
            TestSubscriber<Integer> ts = Maybe.mergeArray(ps1.singleElement(), ps2.singleElement()).test();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

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

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

Example 73 with TestSubscriber

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

the class SchedulerWhenTest method syncDelaySubscription.

@Test
public void syncDelaySubscription() {
    final TestScheduler tSched = new TestScheduler();
    SchedulerWhen sched = throttleScheduler(tSched);
    TestSubscriber<Long> tSub = TestSubscriber.create();
    syncWork(sched).subscribe(tSub);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(0, SECONDS);
    tSub.assertValueCount(1);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(3);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(4);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(5);
    tSub.assertComplete();
    sched.dispose();
}
Also used : SchedulerWhen(io.reactivex.rxjava3.internal.schedulers.SchedulerWhen) Test(org.junit.Test)

Example 74 with TestSubscriber

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

the class SchedulerWhenTest method asyncDelaySubscription.

@Test
public void asyncDelaySubscription() {
    final TestScheduler tSched = new TestScheduler();
    SchedulerWhen sched = throttleScheduler(tSched);
    TestSubscriber<Long> tSub = TestSubscriber.create();
    asyncWork(sched).subscribe(tSub);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(0, SECONDS);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(1);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(1);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(2);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(3);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(3);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(4);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(4);
    tSched.advanceTimeBy(1, SECONDS);
    tSub.assertValueCount(5);
    tSub.assertComplete();
    sched.dispose();
}
Also used : SchedulerWhen(io.reactivex.rxjava3.internal.schedulers.SchedulerWhen) Test(org.junit.Test)

Example 75 with TestSubscriber

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

the class SchedulerWhenTest method syncMaxConcurrent.

@Test
public void syncMaxConcurrent() {
    TestScheduler tSched = new TestScheduler();
    SchedulerWhen sched = maxConcurrentScheduler(tSched);
    TestSubscriber<Long> tSub = TestSubscriber.create();
    syncWork(sched).subscribe(tSub);
    tSub.assertValueCount(0);
    tSched.advanceTimeBy(0, SECONDS);
    // since all the work is synchronous nothing is blocked and its all done
    tSub.assertValueCount(5);
    tSub.assertComplete();
    sched.dispose();
}
Also used : SchedulerWhen(io.reactivex.rxjava3.internal.schedulers.SchedulerWhen) 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