Search in sources :

Example 16 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class FlowableDebounceTest method debounceWithTimeBackpressure.

@Test
public void debounceWithTimeBackpressure() throws InterruptedException {
    TestScheduler scheduler = new TestScheduler();
    TestSubscriberEx<Integer> subscriber = new TestSubscriberEx<>();
    Flowable.merge(Flowable.just(1), Flowable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler)).debounce(20, TimeUnit.MILLISECONDS, scheduler).take(1).subscribe(subscriber);
    scheduler.advanceTimeBy(30, TimeUnit.MILLISECONDS);
    subscriber.assertValue(2);
    subscriber.assertTerminated();
    subscriber.assertNoErrors();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Example 17 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class FlowableTakeUntilPredicateTest method errorIncludesLastValueAsCause.

@Test
public void errorIncludesLastValueAsCause() {
    TestSubscriberEx<String> ts = new TestSubscriberEx<>();
    final TestException e = new TestException("Forced failure");
    Predicate<String> predicate = new Predicate<String>() {

        @Override
        public boolean test(String t) {
            throw e;
        }
    };
    Flowable.just("abc").takeUntil(predicate).subscribe(ts);
    ts.assertTerminated();
    ts.assertNotComplete();
    ts.assertError(TestException.class);
// FIXME last cause value is not saved
// assertTrue(ts.errors().get(0).getCause().getMessage().contains("abc"));
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 18 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class FlowableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout.

@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout() throws InterruptedException {
    // From https://github.com/ReactiveX/RxJava/pull/951
    final Subscription s = mock(Subscription.class);
    Flowable<String> never = Flowable.unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(Subscriber<? super String> subscriber) {
            subscriber.onSubscribe(s);
        }
    });
    TestScheduler testScheduler = new TestScheduler();
    Flowable<String> observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
    TestSubscriberEx<String> subscriber = new TestSubscriberEx<>();
    observableWithTimeout.subscribe(subscriber);
    testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
    subscriber.assertFailureAndMessage(TimeoutException.class, timeoutMessage(1000, TimeUnit.MILLISECONDS));
    verify(s, times(1)).cancel();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 19 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class FlowablePublishTest method syncFusedObserveOn2.

@Test
public void syncFusedObserveOn2() {
    ConnectableFlowable<Integer> cf = Flowable.range(0, 1000).publish();
    Flowable<Integer> obs = cf.observeOn(ImmediateThinScheduler.INSTANCE);
    for (int i = 0; i < 1000; i++) {
        for (int j = 1; j < 6; j++) {
            List<TestSubscriberEx<Integer>> tss = new ArrayList<>();
            for (int k = 1; k < j; k++) {
                TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
                tss.add(ts);
                obs.subscribe(ts);
            }
            Disposable connection = cf.connect();
            for (TestSubscriberEx<Integer> ts : tss) {
                ts.awaitDone(5, TimeUnit.SECONDS).assertSubscribed().assertValueCount(1000).assertNoErrors().assertComplete();
            }
            connection.dispose();
        }
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Example 20 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx in project RxJava by ReactiveX.

the class FlowablePublishTest method subscribeAfterDisconnectThenConnect.

@Test
public void subscribeAfterDisconnectThenConnect() {
    ConnectableFlowable<Integer> source = Flowable.just(1).publish();
    TestSubscriberEx<Integer> ts1 = new TestSubscriberEx<>();
    source.subscribe(ts1);
    Disposable connection = source.connect();
    ts1.assertValue(1);
    ts1.assertNoErrors();
    ts1.assertTerminated();
    source.reset();
    TestSubscriberEx<Integer> ts2 = new TestSubscriberEx<>();
    source.subscribe(ts2);
    Disposable connection2 = source.connect();
    ts2.assertValue(1);
    ts2.assertNoErrors();
    ts2.assertTerminated();
    System.out.println(connection);
    System.out.println(connection2);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)26 TestException (io.reactivex.rxjava3.exceptions.TestException)15 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)12 Disposable (io.reactivex.rxjava3.disposables.Disposable)5 TestSubscriberEx (io.reactivex.rxjava3.testsupport.TestSubscriberEx)5 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)3 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)3 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)2 PublishProcessor (io.reactivex.rxjava3.processors.PublishProcessor)2 Random (java.util.Random)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Assert (org.junit.Assert)2 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 io.reactivex.rxjava3.exceptions (io.reactivex.rxjava3.exceptions)1 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)1 BiFunction (io.reactivex.rxjava3.functions.BiFunction)1 Functions (io.reactivex.rxjava3.internal.functions.Functions)1 FlattenIterableSubscriber (io.reactivex.rxjava3.internal.operators.flowable.FlowableFlattenIterable.FlattenIterableSubscriber)1