Search in sources :

Example 6 with ConnectableObservable

use of io.reactivex.rxjava3.observables.ConnectableObservable in project RxJava by ReactiveX.

the class RxJavaPluginsTest method overrideConnectableObservable.

@SuppressWarnings("rawtypes")
@Test
public void overrideConnectableObservable() {
    try {
        RxJavaPlugins.setOnConnectableObservableAssembly(new Function<ConnectableObservable, ConnectableObservable>() {

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

                    @Override
                    public void connect(Consumer connection) {
                    }

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

                    @SuppressWarnings("unchecked")
                    @Override
                    protected void subscribeActual(Observer observer) {
                        observer.onSubscribe(Disposable.empty());
                        observer.onNext(10);
                        observer.onComplete();
                    }
                };
            }
        });
        Observable.just(1).publish().autoConnect().test().assertResult(10);
    } finally {
        RxJavaPlugins.reset();
    }
    Observable.just(1).publish().autoConnect().test().assertResult(1);
}
Also used : Observer(io.reactivex.rxjava3.core.Observer) ConnectableObservable(io.reactivex.rxjava3.observables.ConnectableObservable) Test(org.junit.Test)

Example 7 with ConnectableObservable

use of io.reactivex.rxjava3.observables.ConnectableObservable in project RxJava by ReactiveX.

the class ConnectableObservable method connect.

/**
 * Instructs the {@code ConnectableObservable} to begin emitting the items from its underlying
 * {@link Observable} to its {@link Observer}s.
 * <p>
 * To disconnect from a synchronous source, use the {@link #connect(Consumer)} method.
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>The behavior is determined by the implementor of this abstract class.</dd>
 * </dl>
 *
 * @return the {@link Disposable} 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 8 with ConnectableObservable

use of io.reactivex.rxjava3.observables.ConnectableObservable in project RxJava by ReactiveX.

the class ObservableReplayTest method connectConsumerThrows.

@Test
public void connectConsumerThrows() {
    ConnectableObservable<Integer> co = Observable.range(1, 2).replay();
    try {
        co.connect(new Consumer<Disposable>() {

            @Override
            public void accept(Disposable t) throws Exception {
                throw new TestException();
            }
        });
        fail("Should have thrown");
    } catch (TestException ex) {
    // expected
    }
    co.test().assertEmpty().dispose();
    co.connect();
    co.test().assertResult(1, 2);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 9 with ConnectableObservable

use of io.reactivex.rxjava3.observables.ConnectableObservable in project RxJava by ReactiveX.

the class ObservableReplayEagerTruncateTest method disposeNoNeedForResetTimeBound.

@Test
public void disposeNoNeedForResetTimeBound() {
    PublishSubject<Integer> ps = PublishSubject.create();
    ConnectableObservable<Integer> co = ps.replay(10, TimeUnit.MINUTES, Schedulers.single(), true);
    TestObserver<Integer> to = co.test();
    Disposable d = co.connect();
    ps.onNext(1);
    d.dispose();
    to = co.test();
    to.assertEmpty();
    co.connect();
    to.assertEmpty();
    ps.onNext(2);
    to.assertValuesOnly(2);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Example 10 with ConnectableObservable

use of io.reactivex.rxjava3.observables.ConnectableObservable in project RxJava by ReactiveX.

the class ObservableReplayEagerTruncateTest method disposeNoNeedForResetSizeBound.

@Test
public void disposeNoNeedForResetSizeBound() {
    PublishSubject<Integer> ps = PublishSubject.create();
    ConnectableObservable<Integer> co = ps.replay(10, true);
    TestObserver<Integer> to = co.test();
    Disposable d = co.connect();
    ps.onNext(1);
    d.dispose();
    to = co.test();
    to.assertEmpty();
    co.connect();
    to.assertEmpty();
    ps.onNext(2);
    to.assertValuesOnly(2);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Aggregations

Disposable (io.reactivex.rxjava3.disposables.Disposable)4 Test (org.junit.Test)4 TestException (io.reactivex.rxjava3.exceptions.TestException)3 Observer (io.reactivex.rxjava3.core.Observer)2 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)2 Observable (io.reactivex.rxjava3.core.Observable)1 ConnectableFlowable (io.reactivex.rxjava3.flowables.ConnectableFlowable)1 ImmediateThinScheduler (io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler)1 ScalarSubscription (io.reactivex.rxjava3.internal.subscriptions.ScalarSubscription)1 ConnectConsumer (io.reactivex.rxjava3.internal.util.ConnectConsumer)1 ParallelFlowable (io.reactivex.rxjava3.parallel.ParallelFlowable)1 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)1