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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations