use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchIfEmptyTest method testSwitchTriggerUnsubscribe.
@Test
public void testSwitchTriggerUnsubscribe() throws Exception {
final BooleanSubscription bs = new BooleanSubscription();
Flowable<Long> withProducer = Flowable.unsafeCreate(new Publisher<Long>() {
@Override
public void subscribe(final Subscriber<? super Long> subscriber) {
subscriber.onSubscribe(bs);
subscriber.onNext(42L);
}
});
Flowable.<Long>empty().switchIfEmpty(withProducer).lift(new FlowableOperator<Long, Long>() {
@Override
public Subscriber<? super Long> apply(final Subscriber<? super Long> child) {
return new DefaultSubscriber<Long>() {
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Long aLong) {
cancel();
}
};
}
}).subscribe();
assertTrue(bs.isCancelled());
// FIXME no longer assertable
// assertTrue(sub.isUnsubscribed());
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchTest method testSwitchWithError.
@Test
public void testSwitchWithError() {
Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {
@Override
public void subscribe(Subscriber<? super Flowable<String>> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 50, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(final Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 50, "one");
publishNext(observer, 100, "two");
}
}));
publishNext(observer, 200, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 0, "three");
publishNext(observer, 100, "four");
}
}));
publishError(observer, 250, new TestException());
}
});
Flowable<String> sampled = Flowable.switchOnNext(source);
sampled.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(anyString());
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("one");
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(175, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("two");
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(225, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("three");
verify(observer, never()).onComplete();
verify(observer, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(350, TimeUnit.MILLISECONDS);
inOrder.verify(observer, never()).onNext(anyString());
verify(observer, never()).onComplete();
verify(observer, times(1)).onError(any(TestException.class));
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchTest method badInnerSource.
@Test
public void badInnerSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Flowable.just(1).hide().switchMap(Functions.justFunction(new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> observer) {
observer.onSubscribe(new BooleanSubscription());
observer.onError(new TestException());
observer.onComplete();
observer.onError(new TestException());
observer.onComplete();
}
})).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchTest method testUnsubscribe.
@Test
public void testUnsubscribe() {
final AtomicBoolean isUnsubscribed = new AtomicBoolean();
Flowable.switchOnNext(Flowable.unsafeCreate(new Publisher<Flowable<Integer>>() {
@Override
public void subscribe(final Subscriber<? super Flowable<Integer>> subscriber) {
BooleanSubscription bs = new BooleanSubscription();
subscriber.onSubscribe(bs);
subscriber.onNext(Flowable.just(1));
isUnsubscribed.set(bs.isCancelled());
}
})).take(1).subscribe();
assertTrue("Switch doesn't propagate 'unsubscribe'", isUnsubscribed.get());
}
use of io.reactivex.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchTest method testSwitchWhenOuterCompleteBeforeInner.
@Test
public void testSwitchWhenOuterCompleteBeforeInner() {
Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {
@Override
public void subscribe(Subscriber<? super Flowable<String>> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 50, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
publishNext(observer, 70, "one");
publishNext(observer, 100, "two");
publishCompleted(observer, 200);
}
}));
publishCompleted(observer, 60);
}
});
Flowable<String> sampled = Flowable.switchOnNext(source);
sampled.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(350, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(2)).onNext(anyString());
inOrder.verify(observer, times(1)).onComplete();
}
Aggregations