use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableRetryWithPredicateTest method retryTwice.
@Test
public void retryTwice() {
Flowable<Integer> source = Flowable.unsafeCreate(new Publisher<Integer>() {
int count;
@Override
public void subscribe(Subscriber<? super Integer> t1) {
t1.onSubscribe(new BooleanSubscription());
count++;
t1.onNext(0);
t1.onNext(1);
if (count == 1) {
t1.onError(new TestException());
return;
}
t1.onNext(2);
t1.onNext(3);
t1.onComplete();
}
});
Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(subscriber);
source.retry(retryTwice).subscribe(subscriber);
inOrder.verify(subscriber).onNext(0);
inOrder.verify(subscriber).onNext(1);
inOrder.verify(subscriber).onNext(0);
inOrder.verify(subscriber).onNext(1);
inOrder.verify(subscriber).onNext(2);
inOrder.verify(subscriber).onNext(3);
inOrder.verify(subscriber).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableRetryWithPredicateTest method retryTwiceAndGiveUp.
@Test
public void retryTwiceAndGiveUp() {
Flowable<Integer> source = Flowable.unsafeCreate(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> t1) {
t1.onSubscribe(new BooleanSubscription());
t1.onNext(0);
t1.onNext(1);
t1.onError(new TestException());
}
});
Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(subscriber);
source.retry(retryTwice).subscribe(subscriber);
inOrder.verify(subscriber).onNext(0);
inOrder.verify(subscriber).onNext(1);
inOrder.verify(subscriber).onNext(0);
inOrder.verify(subscriber).onNext(1);
inOrder.verify(subscriber).onNext(0);
inOrder.verify(subscriber).onNext(1);
inOrder.verify(subscriber).onError(any(TestException.class));
verify(subscriber, never()).onComplete();
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableSubscribeOnTest method deferredRequestRace.
@Test
public void deferredRequestRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = new TestSubscriber<>(0L);
Worker w = Schedulers.computation().createWorker();
final SubscribeOnSubscriber<Integer> so = new SubscribeOnSubscriber<>(ts, w, Flowable.<Integer>never(), true);
ts.onSubscribe(so);
final BooleanSubscription bs = new BooleanSubscription();
try {
Runnable r1 = new Runnable() {
@Override
public void run() {
so.onSubscribe(bs);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
so.request(1);
}
};
TestHelper.race(r1, r2);
} finally {
w.dispose();
}
}
}
use of io.reactivex.rxjava3.core.Flowable 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.core.Flowable 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();
}
Aggregations