Search in sources :

Example 16 with ConnectableFlowable

use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.

the class FlowableReplayTest method disposeNoNeedForResetSizeBound.

@Test
public void disposeNoNeedForResetSizeBound() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    ConnectableFlowable<Integer> cf = pp.replay(10);
    TestSubscriber<Integer> ts = cf.test();
    Disposable d = cf.connect();
    pp.onNext(1);
    d.dispose();
    ts = cf.test();
    ts.assertEmpty();
    cf.connect();
    ts.assertEmpty();
    pp.onNext(2);
    ts.assertValuesOnly(2);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Example 17 with ConnectableFlowable

use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.

the class FlowablePublishTest method observeOn.

@Test
public void observeOn() {
    ConnectableFlowable<Integer> cf = Flowable.range(0, 1000).hide().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 18 with ConnectableFlowable

use of io.reactivex.rxjava3.flowables.ConnectableFlowable 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 19 with ConnectableFlowable

use of io.reactivex.rxjava3.flowables.ConnectableFlowable 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 20 with ConnectableFlowable

use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.

the class FlowablePublishTest method publish.

@Test
public void publish() throws InterruptedException {
    final AtomicInteger counter = new AtomicInteger();
    ConnectableFlowable<String> f = Flowable.unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(final Subscriber<? super String> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            new Thread(new Runnable() {

                @Override
                public void run() {
                    counter.incrementAndGet();
                    subscriber.onNext("one");
                    subscriber.onComplete();
                }
            }).start();
        }
    }).publish();
    final CountDownLatch latch = new CountDownLatch(2);
    // subscribe once
    f.subscribe(new Consumer<String>() {

        @Override
        public void accept(String v) {
            assertEquals("one", v);
            latch.countDown();
        }
    });
    // subscribe again
    f.subscribe(new Consumer<String>() {

        @Override
        public void accept(String v) {
            assertEquals("one", v);
            latch.countDown();
        }
    });
    Disposable connection = f.connect();
    try {
        if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
            fail("subscriptions did not receive values");
        }
        assertEquals(1, counter.get());
    } finally {
        connection.dispose();
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) HasUpstreamPublisher(io.reactivex.rxjava3.internal.fuseable.HasUpstreamPublisher) Test(org.junit.Test)

Aggregations

Disposable (io.reactivex.rxjava3.disposables.Disposable)25 Test (org.junit.Test)14 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)4 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)3 TestException (io.reactivex.rxjava3.exceptions.TestException)2 ConnectableFlowable (io.reactivex.rxjava3.flowables.ConnectableFlowable)2 ScalarSubscription (io.reactivex.rxjava3.internal.subscriptions.ScalarSubscription)2 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)2 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)2 Observable (io.reactivex.rxjava3.core.Observable)1 Observer (io.reactivex.rxjava3.core.Observer)1 HasUpstreamPublisher (io.reactivex.rxjava3.internal.fuseable.HasUpstreamPublisher)1 ImmediateThinScheduler (io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler)1 ConnectConsumer (io.reactivex.rxjava3.internal.util.ConnectConsumer)1 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)1 ParallelFlowable (io.reactivex.rxjava3.parallel.ParallelFlowable)1 IOException (java.io.IOException)1