use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class FlowablePublishTest method testNoDisconnectSomeoneElse.
@Test
public void testNoDisconnectSomeoneElse() {
ConnectableFlowable<Object> source = Flowable.never().publish();
Disposable s1 = source.connect();
Disposable s2 = source.connect();
s1.dispose();
Disposable s3 = source.connect();
s2.dispose();
assertTrue(checkPublishDisposed(s1));
assertTrue(checkPublishDisposed(s2));
assertFalse(checkPublishDisposed(s3));
}
use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class FlowableRepeatTest method shouldDisposeInnerObservable.
@Test
public void shouldDisposeInnerObservable() {
final PublishProcessor<Object> subject = PublishProcessor.create();
final Disposable disposable = Flowable.just("Leak").repeatWhen(new Function<Flowable<Object>, Flowable<Object>>() {
@Override
public Flowable<Object> apply(Flowable<Object> completions) throws Exception {
return completions.switchMap(new Function<Object, Flowable<Object>>() {
@Override
public Flowable<Object> apply(Object ignore) throws Exception {
return subject;
}
});
}
}).subscribe();
assertTrue(subject.hasSubscribers());
disposable.dispose();
assertFalse(subject.hasSubscribers());
}
use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class FlowableReplayTest method testIssue2191_SchedulerUnsubscribeOnError.
/**
* Specifically test interaction with a Scheduler with subscribeOn.
*
* @throws Exception functional interfaces declare throws Exception
*/
@SuppressWarnings("unchecked")
@Test
public void testIssue2191_SchedulerUnsubscribeOnError() throws Exception {
// setup mocks
Consumer<Integer> sourceNext = mock(Consumer.class);
Action sourceCompleted = mock(Action.class);
Consumer<Throwable> sourceError = mock(Consumer.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
Function<Integer, Integer> mockFunc = mock(Function.class);
IllegalArgumentException illegalArgumentException = new IllegalArgumentException();
when(mockFunc.apply(1)).thenReturn(1);
when(mockFunc.apply(2)).thenThrow(illegalArgumentException);
ConnectableFlowable<Integer> replay = Flowable.just(1, 2, 3).map(mockFunc).doOnNext(sourceNext).doOnCancel(sourceUnsubscribed).doOnComplete(sourceCompleted).doOnError(sourceError).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(mockScheduler, times(1)).createWorker();
verify(spiedWorker, times(1)).schedule((Runnable) notNull());
verify(sourceNext, times(1)).accept(1);
verify(sourceError, times(1)).accept(illegalArgumentException);
verifyObserver(mockObserverBeforeConnect, 2, 2, illegalArgumentException);
verifyObserver(mockObserverAfterConnect, 2, 2, illegalArgumentException);
// FIXME no longer supported
// verify(spiedWorker, times(1)).isUnsubscribed();
// FIXME publish also calls cancel
verify(spiedWorker, times(1)).dispose();
verify(sourceUnsubscribed, never()).run();
verifyNoMoreInteractions(sourceNext);
verifyNoMoreInteractions(sourceCompleted);
verifyNoMoreInteractions(sourceError);
verifyNoMoreInteractions(sourceUnsubscribed);
verifyNoMoreInteractions(spiedWorker);
verifyNoMoreInteractions(mockSubscription);
verifyNoMoreInteractions(mockScheduler);
verifyNoMoreInteractions(mockObserverBeforeConnect);
verifyNoMoreInteractions(mockObserverAfterConnect);
}
use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class FlowableReplayTest method connectConsumerThrows.
@Test
public void connectConsumerThrows() {
ConnectableFlowable<Integer> co = Flowable.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().cancel();
co.connect();
co.test().assertResult(1, 2);
}
use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class FlowableRetryTest method shouldDisposeInnerObservable.
@Test
public void shouldDisposeInnerObservable() {
final PublishProcessor<Object> subject = PublishProcessor.create();
final Disposable disposable = Flowable.error(new RuntimeException("Leak")).retryWhen(new Function<Flowable<Throwable>, Flowable<Object>>() {
@Override
public Flowable<Object> apply(Flowable<Throwable> errors) throws Exception {
return errors.switchMap(new Function<Throwable, Flowable<Object>>() {
@Override
public Flowable<Object> apply(Throwable ignore) throws Exception {
return subject;
}
});
}
}).subscribe();
assertTrue(subject.hasSubscribers());
disposable.dispose();
assertFalse(subject.hasSubscribers());
}
Aggregations