use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchTest method switchWithError.
@Test
public void switchWithError() {
Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {
@Override
public void subscribe(Subscriber<? super Flowable<String>> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(final Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 50, "one");
publishNext(subscriber, 100, "two");
}
}));
publishNext(subscriber, 200, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 0, "three");
publishNext(subscriber, 100, "four");
}
}));
publishError(subscriber, 250, new TestException());
}
});
Flowable<String> sampled = Flowable.switchOnNext(source);
sampled.subscribe(subscriber);
InOrder inOrder = inOrder(subscriber);
scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, never()).onNext(anyString());
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, times(1)).onNext("one");
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(175, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, times(1)).onNext("two");
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(225, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, times(1)).onNext("three");
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(350, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, never()).onNext(anyString());
verify(subscriber, never()).onComplete();
verify(subscriber, times(1)).onError(any(TestException.class));
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchTest method switchIssue737.
@Test
public void switchIssue737() {
// https://github.com/ReactiveX/RxJava/issues/737
Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {
@Override
public void subscribe(Subscriber<? super Flowable<String>> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 0, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 10, "1-one");
publishNext(subscriber, 20, "1-two");
// The following events will be ignored
publishNext(subscriber, 30, "1-three");
publishCompleted(subscriber, 40);
}
}));
publishNext(subscriber, 25, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 10, "2-one");
publishNext(subscriber, 20, "2-two");
publishNext(subscriber, 30, "2-three");
publishCompleted(subscriber, 40);
}
}));
publishCompleted(subscriber, 30);
}
});
Flowable<String> sampled = Flowable.switchOnNext(source);
sampled.subscribe(subscriber);
scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber, times(1)).onNext("1-one");
inOrder.verify(subscriber, times(1)).onNext("1-two");
inOrder.verify(subscriber, times(1)).onNext("2-one");
inOrder.verify(subscriber, times(1)).onNext("2-two");
inOrder.verify(subscriber, times(1)).onNext("2-three");
inOrder.verify(subscriber, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchTest method switchWhenInnerCompleteBeforeOuter.
@Test
public void switchWhenInnerCompleteBeforeOuter() {
Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {
@Override
public void subscribe(Subscriber<? super Flowable<String>> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 10, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 0, "one");
publishNext(subscriber, 10, "two");
publishCompleted(subscriber, 20);
}
}));
publishNext(subscriber, 100, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 0, "three");
publishNext(subscriber, 10, "four");
publishCompleted(subscriber, 20);
}
}));
publishCompleted(subscriber, 200);
}
});
Flowable<String> sampled = Flowable.switchOnNext(source);
sampled.subscribe(subscriber);
InOrder inOrder = inOrder(subscriber);
scheduler.advanceTimeTo(150, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, never()).onComplete();
inOrder.verify(subscriber, times(1)).onNext("one");
inOrder.verify(subscriber, times(1)).onNext("two");
inOrder.verify(subscriber, times(1)).onNext("three");
inOrder.verify(subscriber, times(1)).onNext("four");
scheduler.advanceTimeTo(250, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, never()).onNext(anyString());
inOrder.verify(subscriber, times(1)).onComplete();
}
use of io.reactivex.rxjava3.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> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onError(new TestException());
subscriber.onComplete();
subscriber.onError(new TestException());
subscriber.onComplete();
}
})).test().assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.
the class FlowableSwitchTest method switchWithSubsequenceComplete.
@Test
public void switchWithSubsequenceComplete() {
Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {
@Override
public void subscribe(Subscriber<? super Flowable<String>> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 50, "one");
publishNext(subscriber, 100, "two");
}
}));
publishNext(subscriber, 130, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishCompleted(subscriber, 0);
}
}));
publishNext(subscriber, 150, Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
publishNext(subscriber, 50, "three");
}
}));
}
});
Flowable<String> sampled = Flowable.switchOnNext(source);
sampled.subscribe(subscriber);
InOrder inOrder = inOrder(subscriber);
scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, never()).onNext(anyString());
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, times(1)).onNext("one");
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
scheduler.advanceTimeTo(250, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, times(1)).onNext("three");
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
}
Aggregations