use of io.reactivex.rxjava3.core.Flowable 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.core.Flowable 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.core.Flowable 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));
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableTakeTest2 method cancelIgnored.
@Test
public void cancelIgnored() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
BooleanSubscription bs = new BooleanSubscription();
s.onSubscribe(bs);
assertTrue(bs.isCancelled());
s.onNext(1);
s.onComplete();
s.onError(new TestException());
s.onSubscribe(null);
}
}.take(0).test().assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
TestHelper.assertError(errors, 1, NullPointerException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableTakeUntilPredicateTest method sourceThrows.
@Test
public void sourceThrows() {
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
Flowable.just(1).concatWith(Flowable.<Integer>error(new TestException())).concatWith(Flowable.just(2)).takeUntil(new Predicate<Integer>() {
@Override
public boolean test(Integer v) {
return false;
}
}).subscribe(subscriber);
verify(subscriber).onNext(1);
verify(subscriber, never()).onNext(2);
verify(subscriber).onError(any(TestException.class));
verify(subscriber, never()).onComplete();
}
Aggregations