use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.
the class FlowablePublishTest method disposeResets.
@Test
public void disposeResets() {
PublishProcessor<Integer> pp = PublishProcessor.create();
ConnectableFlowable<Integer> cf = pp.publish();
assertFalse(pp.hasSubscribers());
Disposable d = cf.connect();
assertTrue(pp.hasSubscribers());
d.dispose();
assertFalse(pp.hasSubscribers());
TestSubscriber<Integer> ts = cf.test();
cf.connect();
assertTrue(pp.hasSubscribers());
pp.onNext(1);
ts.assertValuesOnly(1);
}
use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.
the class FlowablePublishTest method noDisconnectSomeoneElse.
@Test
public void noDisconnectSomeoneElse() {
ConnectableFlowable<Object> source = Flowable.never().publish();
Disposable connection1 = source.connect();
Disposable connection2 = source.connect();
connection1.dispose();
Disposable connection3 = source.connect();
connection2.dispose();
assertTrue(checkPublishDisposed(connection1));
assertTrue(checkPublishDisposed(connection2));
assertFalse(checkPublishDisposed(connection3));
}
use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.
the class FlowablePublishTest method subscribeDisconnectRace.
@Test
public void subscribeDisconnectRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final ConnectableFlowable<Integer> cf = pp.publish();
final Disposable d = cf.connect();
final TestSubscriber<Integer> ts = new TestSubscriber<>();
Runnable r1 = new Runnable() {
@Override
public void run() {
d.dispose();
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
cf.subscribe(ts);
}
};
TestHelper.race(r1, r2);
}
}
use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.
the class FlowableReplayEagerTruncateTest method issue2191_SchedulerUnsubscribe.
/**
* Specifically test interaction with a Scheduler with subscribeOn.
*
* @throws Throwable functional interfaces declare throws Exception
*/
@SuppressWarnings("unchecked")
@Test
public void issue2191_SchedulerUnsubscribe() throws Throwable {
// setup mocks
Consumer<Integer> sourceNext = mock(Consumer.class);
Action sourceCompleted = mock(Action.class);
Action sourceUnsubscribed = mock(Action.class);
final Scheduler mockScheduler = mock(Scheduler.class);
final Disposable mockSubscription = mock(Disposable.class);
Worker spiedWorker = workerSpy(mockSubscription);
Subscriber<Integer> mockObserverBeforeConnect = TestHelper.mockSubscriber();
Subscriber<Integer> mockObserverAfterConnect = TestHelper.mockSubscriber();
when(mockScheduler.createWorker()).thenReturn(spiedWorker);
// Flowable under test
ConnectableFlowable<Integer> replay = Flowable.just(1, 2, 3).doOnNext(sourceNext).doOnCancel(sourceUnsubscribed).doOnComplete(sourceCompleted).subscribeOn(mockScheduler).replay();
replay.subscribe(mockObserverBeforeConnect);
replay.subscribe(mockObserverBeforeConnect);
replay.connect();
replay.subscribe(mockObserverAfterConnect);
replay.subscribe(mockObserverAfterConnect);
verify(mockObserverBeforeConnect, times(2)).onSubscribe((Subscription) any());
verify(mockObserverAfterConnect, times(2)).onSubscribe((Subscription) any());
// verify interactions
verify(sourceNext, times(1)).accept(1);
verify(sourceNext, times(1)).accept(2);
verify(sourceNext, times(1)).accept(3);
verify(sourceCompleted, times(1)).run();
verify(mockScheduler, times(1)).createWorker();
verify(spiedWorker, times(1)).schedule((Runnable) notNull());
verifyObserverMock(mockObserverBeforeConnect, 2, 6);
verifyObserverMock(mockObserverAfterConnect, 2, 6);
// FIXME publish calls cancel too
verify(spiedWorker, times(1)).dispose();
verify(sourceUnsubscribed, never()).run();
verifyNoMoreInteractions(sourceNext);
verifyNoMoreInteractions(sourceCompleted);
verifyNoMoreInteractions(sourceUnsubscribed);
verifyNoMoreInteractions(spiedWorker);
verifyNoMoreInteractions(mockSubscription);
verifyNoMoreInteractions(mockScheduler);
verifyNoMoreInteractions(mockObserverBeforeConnect);
verifyNoMoreInteractions(mockObserverAfterConnect);
}
use of io.reactivex.rxjava3.flowables.ConnectableFlowable in project RxJava by ReactiveX.
the class FlowableReplayEagerTruncateTest method connectConsumerThrows.
@Test
public void connectConsumerThrows() {
ConnectableFlowable<Integer> cf = Flowable.range(1, 2).replay();
try {
cf.connect(new Consumer<Disposable>() {
@Override
public void accept(Disposable t) throws Exception {
throw new TestException();
}
});
fail("Should have thrown");
} catch (TestException ex) {
// expected
}
cf.test().assertEmpty().cancel();
cf.connect();
cf.test().assertResult(1, 2);
}
Aggregations