use of io.reactivex.rxjava3.core.Scheduler 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.Scheduler 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.Scheduler 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.Scheduler in project RxJava by ReactiveX.
the class ObservableObserveOnTest method observeOnTheSameSchedulerTwice.
@Test
public void observeOnTheSameSchedulerTwice() {
Scheduler scheduler = ImmediateThinScheduler.INSTANCE;
Observable<Integer> o = Observable.just(1, 2, 3);
Observable<Integer> o2 = o.observeOn(scheduler);
Observer<Object> observer1 = TestHelper.mockObserver();
Observer<Object> observer2 = TestHelper.mockObserver();
InOrder inOrder1 = inOrder(observer1);
InOrder inOrder2 = inOrder(observer2);
o2.subscribe(observer1);
o2.subscribe(observer2);
inOrder1.verify(observer1, times(1)).onNext(1);
inOrder1.verify(observer1, times(1)).onNext(2);
inOrder1.verify(observer1, times(1)).onNext(3);
inOrder1.verify(observer1, times(1)).onComplete();
verify(observer1, never()).onError(any(Throwable.class));
inOrder1.verifyNoMoreInteractions();
inOrder2.verify(observer2, times(1)).onNext(1);
inOrder2.verify(observer2, times(1)).onNext(2);
inOrder2.verify(observer2, times(1)).onNext(3);
inOrder2.verify(observer2, times(1)).onComplete();
verify(observer2, never()).onError(any(Throwable.class));
inOrder2.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ObservableSkipLastTimedTest method skipLastTimedErrorBeforeTime.
@Test
public void skipLastTimedErrorBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skipLast(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onError(new TestException());
scheduler.advanceTimeBy(1050, TimeUnit.MILLISECONDS);
verify(o).onError(any(TestException.class));
verify(o, never()).onComplete();
verify(o, never()).onNext(any());
}
Aggregations