Search in sources :

Example 56 with TestSubscriber

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

the class FlowableThrottleLatestTest method reentrantComplete.

@Test
public void reentrantComplete() {
    TestScheduler sch = new TestScheduler();
    final PublishProcessor<Integer> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            if (t == 1) {
                pp.onNext(2);
            }
            if (t == 2) {
                pp.onComplete();
            }
        }
    };
    pp.throttleLatest(1, TimeUnit.SECONDS, sch).subscribe(ts);
    pp.onNext(1);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertResult(1, 2);
}
Also used : TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 57 with TestSubscriber

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

the class FlowableTimeoutTests method shouldSwitchToOtherIfOnCompletedNotWithinTimeout.

@Test
public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() {
    Flowable<String> other = Flowable.just("a", "b", "c");
    Flowable<String> source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other);
    Subscriber<String> subscriber = TestHelper.mockSubscriber();
    TestSubscriber<String> ts = new TestSubscriber<>(subscriber);
    source.subscribe(ts);
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    underlyingSubject.onNext("One");
    testScheduler.advanceTimeBy(4, TimeUnit.SECONDS);
    underlyingSubject.onComplete();
    InOrder inOrder = inOrder(subscriber);
    inOrder.verify(subscriber, times(1)).onNext("One");
    inOrder.verify(subscriber, times(1)).onNext("a");
    inOrder.verify(subscriber, times(1)).onNext("b");
    inOrder.verify(subscriber, times(1)).onNext("c");
    inOrder.verify(subscriber, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
    ts.cancel();
}
Also used : InOrder(org.mockito.InOrder) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber)

Example 58 with TestSubscriber

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

the class FlowableTimeoutTests method shouldSwitchToOtherIfOnNextNotWithinTimeout.

@Test
public void shouldSwitchToOtherIfOnNextNotWithinTimeout() {
    Flowable<String> other = Flowable.just("a", "b", "c");
    Flowable<String> source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other);
    Subscriber<String> subscriber = TestHelper.mockSubscriber();
    TestSubscriber<String> ts = new TestSubscriber<>(subscriber);
    source.subscribe(ts);
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    underlyingSubject.onNext("One");
    testScheduler.advanceTimeBy(4, TimeUnit.SECONDS);
    underlyingSubject.onNext("Two");
    InOrder inOrder = inOrder(subscriber);
    inOrder.verify(subscriber, times(1)).onNext("One");
    inOrder.verify(subscriber, times(1)).onNext("a");
    inOrder.verify(subscriber, times(1)).onNext("b");
    inOrder.verify(subscriber, times(1)).onNext("c");
    inOrder.verify(subscriber, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
    ts.cancel();
}
Also used : InOrder(org.mockito.InOrder) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber)

Example 59 with TestSubscriber

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

the class FlowableTakeUntilTest method untilPublisherOtherError.

@Test
public void untilPublisherOtherError() {
    PublishProcessor<Integer> main = PublishProcessor.create();
    PublishProcessor<Integer> other = PublishProcessor.create();
    TestSubscriber<Integer> ts = main.takeUntil(other).test();
    assertTrue("Main no subscribers?", main.hasSubscribers());
    assertTrue("Other no subscribers?", other.hasSubscribers());
    other.onError(new TestException());
    assertFalse("Main has subscribers?", main.hasSubscribers());
    assertFalse("Other has subscribers?", other.hasSubscribers());
    ts.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 60 with TestSubscriber

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

the class FlowableTimeoutWithSelectorTest method lateOnTimeoutError.

@Test
public void lateOnTimeoutError() {
    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) {
                    s.onSubscribe(new BooleanSubscription());
                    sub[count++] = s;
                }
            };
            TestSubscriber<Integer> ts = pp.timeout(Functions.justFunction(pp2)).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)

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