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());
}
use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class FlowablePublishTest method testSubscribeAfterDisconnectThenConnect.
@Test
public void testSubscribeAfterDisconnectThenConnect() {
ConnectableFlowable<Integer> source = Flowable.just(1).publish();
TestSubscriber<Integer> ts1 = new TestSubscriber<Integer>();
source.subscribe(ts1);
Disposable s = source.connect();
ts1.assertValue(1);
ts1.assertNoErrors();
ts1.assertTerminated();
TestSubscriber<Integer> ts2 = new TestSubscriber<Integer>();
source.subscribe(ts2);
Disposable s2 = source.connect();
ts2.assertValue(1);
ts2.assertNoErrors();
ts2.assertTerminated();
System.out.println(s);
System.out.println(s2);
}
use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class FlowablePublishTest method syncFusedObserveOn2.
@Test
public void syncFusedObserveOn2() {
ConnectableFlowable<Integer> co = Flowable.range(0, 1000).publish();
Flowable<Integer> obs = co.observeOn(ImmediateThinScheduler.INSTANCE);
for (int i = 0; i < 1000; i++) {
for (int j = 1; j < 6; j++) {
List<TestSubscriber<Integer>> tss = new ArrayList<TestSubscriber<Integer>>();
for (int k = 1; k < j; k++) {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
tss.add(ts);
obs.subscribe(ts);
}
Disposable s = co.connect();
for (TestSubscriber<Integer> ts : tss) {
ts.awaitDone(5, TimeUnit.SECONDS).assertSubscribed().assertValueCount(1000).assertNoErrors().assertComplete();
}
s.dispose();
}
}
}
use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.
the class FlowableRefCountTest method onlyFirstShouldSubscribeAndLastUnsubscribe.
@Test
public void onlyFirstShouldSubscribeAndLastUnsubscribe() {
final AtomicInteger subscriptionCount = new AtomicInteger();
final AtomicInteger unsubscriptionCount = new AtomicInteger();
Flowable<Integer> observable = Flowable.unsafeCreate(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> observer) {
subscriptionCount.incrementAndGet();
observer.onSubscribe(new Subscription() {
@Override
public void request(long n) {
}
@Override
public void cancel() {
unsubscriptionCount.incrementAndGet();
}
});
}
});
Flowable<Integer> refCounted = observable.publish().refCount();
Disposable first = refCounted.subscribe();
assertEquals(1, subscriptionCount.get());
Disposable second = refCounted.subscribe();
assertEquals(1, subscriptionCount.get());
first.dispose();
assertEquals(0, unsubscriptionCount.get());
second.dispose();
assertEquals(1, unsubscriptionCount.get());
}
Aggregations