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