Search in sources :

Example 21 with ConnectableFlowable

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

the class RxJavaPluginsTest method overrideConnectableFlowable.

@SuppressWarnings("rawtypes")
@Test
public void overrideConnectableFlowable() {
    try {
        RxJavaPlugins.setOnConnectableFlowableAssembly(new Function<ConnectableFlowable, ConnectableFlowable>() {

            @Override
            public ConnectableFlowable apply(ConnectableFlowable co) throws Exception {
                return new ConnectableFlowable() {

                    @Override
                    public void connect(Consumer connection) {
                    }

                    @Override
                    public void reset() {
                    // nothing to do in this test
                    }

                    @SuppressWarnings("unchecked")
                    @Override
                    protected void subscribeActual(Subscriber subscriber) {
                        subscriber.onSubscribe(new ScalarSubscription(subscriber, 10));
                    }
                };
            }
        });
        Flowable.just(1).publish().autoConnect().test().assertResult(10);
    } finally {
        RxJavaPlugins.reset();
    }
    Flowable.just(1).publish().autoConnect().test().assertResult(1);
}
Also used : ConnectableFlowable(io.reactivex.rxjava3.flowables.ConnectableFlowable) ScalarSubscription(io.reactivex.rxjava3.internal.subscriptions.ScalarSubscription) Test(org.junit.Test)

Example 22 with ConnectableFlowable

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

the class ConnectableFlowable method connect.

/**
 * Instructs the {@code ConnectableFlowable} to begin emitting the items from its underlying
 * {@link Flowable} to its {@link Subscriber}s.
 * <p>
 * To disconnect from a synchronous source, use the {@link #connect(io.reactivex.rxjava3.functions.Consumer)} method.
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>The behavior is determined by the implementor of this abstract class.</dd>
 * </dl>
 *
 * @return the subscription representing the connection
 * @see <a href="http://reactivex.io/documentation/operators/connect.html">ReactiveX documentation: Connect</a>
 */
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable connect() {
    ConnectConsumer cc = new ConnectConsumer();
    connect(cc);
    return cc.disposable;
}
Also used : ConnectConsumer(io.reactivex.rxjava3.internal.util.ConnectConsumer)

Example 23 with ConnectableFlowable

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

the class FlowablePublishTest method disposeNoNeedForReset.

@Test
public void disposeNoNeedForReset() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    ConnectableFlowable<Integer> cf = pp.publish();
    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) Test(org.junit.Test)

Example 24 with ConnectableFlowable

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

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

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