use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableObserveOnTest method asycFusedPollThrows.
@Test
public void asycFusedPollThrows() {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
@SuppressWarnings("unchecked") BaseObserveOnSubscriber<Integer> oo = (BaseObserveOnSubscriber<Integer>) subscriber;
oo.sourceMode = QueueFuseable.ASYNC;
oo.requested.lazySet(1);
oo.queue = new SimpleQueue<Integer>() {
@Override
public boolean offer(Integer value) {
return false;
}
@Override
public boolean offer(Integer v1, Integer v2) {
return false;
}
@Nullable
@Override
public Integer poll() throws Exception {
throw new TestException();
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public void clear() {
}
};
oo.clear();
oo.trySchedule();
}
}.observeOn(Schedulers.single()).test(0L).awaitDone(5, TimeUnit.SECONDS).assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableObserveOnTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestScheduler scheduler = new TestScheduler();
TestSubscriber<Integer> ts = new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onComplete();
subscriber.onNext(1);
subscriber.onError(new TestException());
subscriber.onComplete();
}
}.observeOn(scheduler).test();
scheduler.triggerActions();
ts.assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableObserveOnTest method observeOnTheSameSchedulerTwice.
@Test
public void observeOnTheSameSchedulerTwice() {
Scheduler scheduler = ImmediateThinScheduler.INSTANCE;
Flowable<Integer> f = Flowable.just(1, 2, 3);
Flowable<Integer> f2 = f.observeOn(scheduler);
Subscriber<Object> subscriber1 = TestHelper.mockSubscriber();
Subscriber<Object> subscriber2 = TestHelper.mockSubscriber();
InOrder inOrder1 = inOrder(subscriber1);
InOrder inOrder2 = inOrder(subscriber2);
f2.subscribe(subscriber1);
f2.subscribe(subscriber2);
inOrder1.verify(subscriber1, times(1)).onNext(1);
inOrder1.verify(subscriber1, times(1)).onNext(2);
inOrder1.verify(subscriber1, times(1)).onNext(3);
inOrder1.verify(subscriber1, times(1)).onComplete();
verify(subscriber1, never()).onError(any(Throwable.class));
inOrder1.verifyNoMoreInteractions();
inOrder2.verify(subscriber2, times(1)).onNext(1);
inOrder2.verify(subscriber2, times(1)).onNext(2);
inOrder2.verify(subscriber2, times(1)).onNext(3);
inOrder2.verify(subscriber2, times(1)).onComplete();
verify(subscriber2, never()).onError(any(Throwable.class));
inOrder2.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableReplayEagerTruncateTest method issue2191_SchedulerUnsubscribeOnError.
/**
* Specifically test interaction with a Scheduler with subscribeOn.
*
* @throws Throwable functional interfaces declare throws Exception
*/
@SuppressWarnings("unchecked")
@Test
public void issue2191_SchedulerUnsubscribeOnError() throws Throwable {
// setup mocks
Consumer<Integer> sourceNext = mock(Consumer.class);
Action sourceCompleted = mock(Action.class);
Consumer<Throwable> sourceError = mock(Consumer.class);
Action sourceUnsubscribed = mock(Action.class);
final Scheduler mockScheduler = mock(Scheduler.class);
final Disposable mockSubscription = mock(Disposable.class);
Worker spiedWorker = workerSpy(mockSubscription);
Subscriber<Integer> mockObserverBeforeConnect = TestHelper.mockSubscriber();
Subscriber<Integer> mockObserverAfterConnect = TestHelper.mockSubscriber();
when(mockScheduler.createWorker()).thenReturn(spiedWorker);
// Flowable under test
Function<Integer, Integer> mockFunc = mock(Function.class);
IllegalArgumentException illegalArgumentException = new IllegalArgumentException();
when(mockFunc.apply(1)).thenReturn(1);
when(mockFunc.apply(2)).thenThrow(illegalArgumentException);
ConnectableFlowable<Integer> replay = Flowable.just(1, 2, 3).map(mockFunc).doOnNext(sourceNext).doOnCancel(sourceUnsubscribed).doOnComplete(sourceCompleted).doOnError(sourceError).subscribeOn(mockScheduler).replay();
replay.subscribe(mockObserverBeforeConnect);
replay.subscribe(mockObserverBeforeConnect);
replay.connect();
replay.subscribe(mockObserverAfterConnect);
replay.subscribe(mockObserverAfterConnect);
verify(mockObserverBeforeConnect, times(2)).onSubscribe((Subscription) any());
verify(mockObserverAfterConnect, times(2)).onSubscribe((Subscription) any());
// verify interactions
verify(mockScheduler, times(1)).createWorker();
verify(spiedWorker, times(1)).schedule((Runnable) notNull());
verify(sourceNext, times(1)).accept(1);
verify(sourceError, times(1)).accept(illegalArgumentException);
verifyObserver(mockObserverBeforeConnect, 2, 2, illegalArgumentException);
verifyObserver(mockObserverAfterConnect, 2, 2, illegalArgumentException);
// FIXME publish also calls cancel
verify(spiedWorker, times(1)).dispose();
verify(sourceUnsubscribed, never()).run();
verifyNoMoreInteractions(sourceNext);
verifyNoMoreInteractions(sourceCompleted);
verifyNoMoreInteractions(sourceError);
verifyNoMoreInteractions(sourceUnsubscribed);
verifyNoMoreInteractions(spiedWorker);
verifyNoMoreInteractions(mockSubscription);
verifyNoMoreInteractions(mockScheduler);
verifyNoMoreInteractions(mockObserverBeforeConnect);
verifyNoMoreInteractions(mockObserverAfterConnect);
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableReplayEagerTruncateTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onError(new TestException("First"));
subscriber.onNext(1);
subscriber.onError(new TestException("Second"));
subscriber.onComplete();
}
}.replay().autoConnect().to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
} finally {
RxJavaPlugins.reset();
}
}
Aggregations