use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class StrictSubscriberTest method cancelAfterOnError.
@Test
public void cancelAfterOnError() {
final List<Object> list = new ArrayList<>();
Subscriber<Object> sub = new Subscriber<Object>() {
Subscription upstream;
@Override
public void onSubscribe(Subscription s) {
this.upstream = s;
}
@Override
public void onNext(Object t) {
list.add(t);
}
@Override
public void onError(Throwable t) {
upstream.cancel();
list.add(t.getMessage());
}
@Override
public void onComplete() {
upstream.cancel();
list.add("Done");
}
};
new Flowable<Object>() {
@Override
protected void subscribeActual(Subscriber<? super Object> s) {
BooleanSubscription b = new BooleanSubscription();
s.onSubscribe(b);
s.onError(new TestException("Forced failure"));
list.add(b.isCancelled());
}
}.subscribe(sub);
assertEquals(Arrays.<Object>asList("Forced failure", false), list);
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableDelayTest method delayWithFlowableSourceThrows.
@Test
public void delayWithFlowableSourceThrows() {
PublishProcessor<Integer> source = PublishProcessor.create();
final PublishProcessor<Integer> delay = PublishProcessor.create();
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Integer t1) {
return delay;
}
};
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(subscriber);
source.delay(delayFunc).subscribe(subscriber);
source.onNext(1);
source.onError(new TestException());
delay.onNext(1);
inOrder.verify(subscriber).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onNext(any());
verify(subscriber, never()).onComplete();
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableDelayTest method delayWithFlowableReorder.
@Test
public void delayWithFlowableReorder() {
int n = 3;
PublishProcessor<Integer> source = PublishProcessor.create();
final List<PublishProcessor<Integer>> subjects = new ArrayList<>();
for (int i = 0; i < n; i++) {
subjects.add(PublishProcessor.<Integer>create());
}
Flowable<Integer> result = source.delay(new Function<Integer, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Integer t1) {
return subjects.get(t1);
}
});
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(subscriber);
result.subscribe(subscriber);
for (int i = 0; i < n; i++) {
source.onNext(i);
}
source.onComplete();
inOrder.verify(subscriber, never()).onNext(anyInt());
inOrder.verify(subscriber, never()).onComplete();
for (int i = n - 1; i >= 0; i--) {
subjects.get(i).onComplete();
inOrder.verify(subscriber).onNext(i);
}
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 FlowableDelayTest method delayWithFlowableSubscriptionThrows.
@Test
public void delayWithFlowableSubscriptionThrows() {
PublishProcessor<Integer> source = PublishProcessor.create();
final PublishProcessor<Integer> delay = PublishProcessor.create();
Supplier<Flowable<Integer>> subFunc = new Supplier<Flowable<Integer>>() {
@Override
public Flowable<Integer> get() {
return delay;
}
};
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Integer t1) {
return delay;
}
};
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(subscriber);
source.delay(Flowable.defer(subFunc), delayFunc).subscribe(subscriber);
source.onNext(1);
delay.onError(new TestException());
source.onNext(2);
inOrder.verify(subscriber).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onNext(any());
verify(subscriber, never()).onComplete();
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableDelayTest method delayWithFlowableDelayFunctionThrows.
@Test
public void delayWithFlowableDelayFunctionThrows() {
PublishProcessor<Integer> source = PublishProcessor.create();
Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Integer t1) {
throw new TestException();
}
};
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(subscriber);
source.delay(delayFunc).subscribe(subscriber);
source.onNext(1);
inOrder.verify(subscriber).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onNext(any());
verify(subscriber, never()).onComplete();
}
Aggregations