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