use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableReplayTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> observer) {
observer.onSubscribe(new BooleanSubscription());
observer.onError(new TestException("First"));
observer.onNext(1);
observer.onError(new TestException("Second"));
observer.onComplete();
}
}.replay().autoConnect().test().assertFailureAndMessage(TestException.class, "First");
TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableReplayTest method delayedUpstreamOnSubscribe.
@Test
public void delayedUpstreamOnSubscribe() {
final Subscriber<?>[] sub = { null };
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
sub[0] = s;
}
}.replay().connect().dispose();
BooleanSubscription bs = new BooleanSubscription();
sub[0].onSubscribe(bs);
assertTrue(bs.isCancelled());
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableRetryTest method testSourceObservableCallsUnsubscribe.
@Test
public void testSourceObservableCallsUnsubscribe() throws InterruptedException {
final AtomicInteger subsCount = new AtomicInteger(0);
final TestSubscriber<String> ts = new TestSubscriber<String>();
Publisher<String> onSubscribe = new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> s) {
BooleanSubscription bs = new BooleanSubscription();
// https://github.com/ReactiveX/RxJava/issues/1024
if (!bs.isCancelled()) {
subsCount.incrementAndGet();
s.onError(new RuntimeException("failed"));
// it unsubscribes the child directly
// this simulates various error/completion scenarios that could occur
// or just a source that proactively triggers cleanup
// FIXME can't unsubscribe child
// s.unsubscribe();
bs.cancel();
} else {
s.onError(new RuntimeException());
}
}
};
Flowable.unsafeCreate(onSubscribe).retry(3).subscribe(ts);
// 1 + 3 retries
assertEquals(4, subsCount.get());
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableMergeDelayErrorTest method testMergeSourceWhichDoesntPropagateExceptionBack.
@Test
@Ignore("Subscribers should not throw")
public void testMergeSourceWhichDoesntPropagateExceptionBack() {
Flowable<Integer> source = Flowable.unsafeCreate(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> t1) {
t1.onSubscribe(new BooleanSubscription());
try {
t1.onNext(0);
} catch (Throwable swallow) {
}
t1.onNext(1);
t1.onComplete();
}
});
Flowable<Integer> result = Flowable.mergeDelayError(source, Flowable.just(2));
final Subscriber<Integer> o = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(o);
result.subscribe(new DefaultSubscriber<Integer>() {
int calls;
@Override
public void onNext(Integer t) {
if (calls++ == 0) {
throw new TestException();
}
o.onNext(t);
}
@Override
public void onError(Throwable e) {
o.onError(e);
}
@Override
public void onComplete() {
o.onComplete();
}
});
/*
* If the child onNext throws, why would we keep accepting values from
* other sources?
*/
inOrder.verify(o).onNext(2);
inOrder.verify(o, never()).onNext(0);
inOrder.verify(o, never()).onNext(1);
inOrder.verify(o, never()).onNext(anyInt());
inOrder.verify(o).onError(any(TestException.class));
verify(o, never()).onComplete();
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableElementAtTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onNext(1);
subscriber.onNext(2);
subscriber.onError(new TestException());
subscriber.onComplete();
}
}.elementAt(0).toFlowable().test().assertResult(1);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
TestHelper.checkBadSourceFlowable(new Function<Flowable<Integer>, Object>() {
@Override
public Object apply(Flowable<Integer> f) throws Exception {
return f.elementAt(0);
}
}, false, null, 1);
TestHelper.checkBadSourceFlowable(new Function<Flowable<Integer>, Object>() {
@Override
public Object apply(Flowable<Integer> f) throws Exception {
return f.elementAt(0, 1);
}
}, false, null, 1, 1);
TestHelper.checkBadSourceFlowable(new Function<Flowable<Integer>, Object>() {
@Override
public Object apply(Flowable<Integer> f) throws Exception {
return f.elementAt(0).toFlowable();
}
}, false, null, 1);
TestHelper.checkBadSourceFlowable(new Function<Flowable<Integer>, Object>() {
@Override
public Object apply(Flowable<Integer> f) throws Exception {
return f.elementAt(0, 1).toFlowable();
}
}, false, null, 1, 1);
}
Aggregations