Search in sources :

Example 81 with Flowable

use of io.reactivex.rxjava3.core.Flowable 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 82 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class FlowableRepeatTest method noCancelPreviousRepeatWhen.

@Test
public void noCancelPreviousRepeatWhen() {
    final AtomicInteger counter = new AtomicInteger();
    Flowable<Integer> source = Flowable.just(1).doOnCancel(new Action() {

        @Override
        public void run() throws Exception {
            counter.getAndIncrement();
        }
    });
    final AtomicInteger times = new AtomicInteger();
    source.repeatWhen(new Function<Flowable<Object>, Flowable<?>>() {

        @Override
        public Flowable<?> apply(Flowable<Object> e) throws Exception {
            return e.takeWhile(new Predicate<Object>() {

                @Override
                public boolean test(Object v) throws Exception {
                    return times.getAndIncrement() < 4;
                }
            });
        }
    }).test().assertResult(1, 1, 1, 1, 1);
    assertEquals(0, counter.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Flowable(io.reactivex.rxjava3.core.Flowable) Test(org.junit.Test)

Example 83 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class ParallelJoinTest method onNextMissingBackpressureDelayErrorRace.

@Test
public void onNextMissingBackpressureDelayErrorRace() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
            AtomicReference<Subscriber<? super Integer>> ref1 = new AtomicReference<>();
            AtomicReference<Subscriber<? super Integer>> ref2 = new AtomicReference<>();
            Flowable<Integer> f1 = new Flowable<Integer>() {

                @Override
                public void subscribeActual(Subscriber<? super Integer> s) {
                    s.onSubscribe(new BooleanSubscription());
                    ref1.set(s);
                }
            };
            Flowable<Integer> f2 = new Flowable<Integer>() {

                @Override
                public void subscribeActual(Subscriber<? super Integer> s) {
                    s.onSubscribe(new BooleanSubscription());
                    ref2.set(s);
                }
            };
            ParallelFlowable.fromArray(f1, f2).sequentialDelayError(1).test(0);
            TestHelper.race(() -> {
                ref1.get().onNext(1);
                ref1.get().onNext(2);
            }, () -> {
                ref2.get().onNext(3);
                ref2.get().onNext(4);
            });
            errors.clear();
        }
    });
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Subscriber(org.reactivestreams.Subscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 84 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class ParallelSortedJoinTest method error3.

@Test
public void error3() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.<Integer>error(new TestException()).parallel().sorted(Functions.<Integer>naturalComparator()).test(0).assertFailure(TestException.class);
        assertTrue(errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 85 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class ParallelSortedJoinTest method error.

@Test
public void error() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.<Integer>error(new TestException()).parallel().sorted(Functions.<Integer>naturalComparator()).test().assertFailure(TestException.class);
        assertTrue(errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)159 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)121 TestException (io.reactivex.rxjava3.exceptions.TestException)95 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)49 InOrder (org.mockito.InOrder)41 IOException (java.io.IOException)27 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)22 Disposable (io.reactivex.rxjava3.disposables.Disposable)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)11 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)9 java.util (java.util)9 Assert (org.junit.Assert)9 Subscriber (org.reactivestreams.Subscriber)9 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)8 java.util.concurrent.atomic (java.util.concurrent.atomic)8 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)7 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)7 Functions (io.reactivex.rxjava3.internal.functions.Functions)7 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)7