Search in sources :

Example 11 with TestSubscriberEx

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

the class FlowablePublishTest method asyncFusedObserveOn.

@Test
public void asyncFusedObserveOn() {
    ConnectableFlowable<Integer> cf = Flowable.range(0, 1000).observeOn(ImmediateThinScheduler.INSTANCE).publish();
    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);
                cf.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 12 with TestSubscriberEx

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

the class FlowablePublishTest method syncFusedObserveOn.

@Test
public void syncFusedObserveOn() {
    ConnectableFlowable<Integer> cf = Flowable.range(0, 1000).publish();
    Flowable<Integer> obs = cf.observeOn(Schedulers.computation());
    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 13 with TestSubscriberEx

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

the class AsyncProcessorTest method onErrorCancelRace.

@Test
@SuppressUndeliverable
public void onErrorCancelRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final AsyncProcessor<Object> p = AsyncProcessor.create();
        final TestSubscriberEx<Object> ts1 = p.to(TestHelper.<Object>testConsumer());
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                ts1.cancel();
            }
        };
        final TestException ex = new TestException();
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                p.onError(ex);
            }
        };
        TestHelper.race(r1, r2);
        if (ts1.errors().size() != 0) {
            ts1.assertFailure(TestException.class);
        } else {
            ts1.assertEmpty();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 14 with TestSubscriberEx

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

the class HalfSerializerSubscriberTest method onErrorOnCompleteRace.

@Test
@SuppressUndeliverable
public void onErrorOnCompleteRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final AtomicInteger wip = new AtomicInteger();
        final AtomicThrowable error = new AtomicThrowable();
        final TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
        ts.onSubscribe(new BooleanSubscription());
        final TestException ex = new TestException();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                HalfSerializer.onError(ts, ex, wip, error);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                HalfSerializer.onComplete(ts, wip, error);
            }
        };
        TestHelper.race(r1, r2);
        if (ts.completions() != 0) {
            ts.assertResult();
        } else {
            ts.assertFailure(TestException.class);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 15 with TestSubscriberEx

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

the class StrictSubscriberTest method normalOnError.

@Test
public void normalOnError() {
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
    SubscriberWrapper<Integer> wrapper = new SubscriberWrapper<>(ts);
    Flowable.range(1, 5).concatWith(Flowable.<Integer>error(new TestException())).subscribe(wrapper);
    ts.assertFailure(TestException.class, 1, 2, 3, 4, 5);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriberEx(io.reactivex.rxjava3.testsupport.TestSubscriberEx) 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