use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableTakeTimedTest method testTakeTimedErrorAfterTime.
@Test
public void testTakeTimedErrorAfterTime() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.take(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
source.onError(new TestException());
InOrder inOrder = inOrder(o);
inOrder.verify(o).onNext(1);
inOrder.verify(o).onNext(2);
inOrder.verify(o).onNext(3);
inOrder.verify(o).onComplete();
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(4);
verify(o, never()).onError(any(TestException.class));
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableSkipTimedTest method testSkipTimedErrorAfterTime.
@Test
public void testSkipTimedErrorAfterTime() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
source.onNext(5);
source.onNext(6);
source.onError(new TestException());
InOrder inOrder = inOrder(o);
inOrder.verify(o, never()).onNext(1);
inOrder.verify(o, never()).onNext(2);
inOrder.verify(o, never()).onNext(3);
inOrder.verify(o).onNext(4);
inOrder.verify(o).onNext(5);
inOrder.verify(o).onNext(6);
inOrder.verify(o).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(o, never()).onComplete();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableSkipTimedTest method testSkipTimed.
@Test
public void testSkipTimed() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
source.onNext(5);
source.onNext(6);
source.onComplete();
InOrder inOrder = inOrder(o);
inOrder.verify(o, never()).onNext(1);
inOrder.verify(o, never()).onNext(2);
inOrder.verify(o, never()).onNext(3);
inOrder.verify(o).onNext(4);
inOrder.verify(o).onNext(5);
inOrder.verify(o).onNext(6);
inOrder.verify(o).onComplete();
inOrder.verifyNoMoreInteractions();
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class SchedulerWhenTest method testSyncMaxConcurrent.
@Test
public void testSyncMaxConcurrent() {
TestScheduler tSched = new TestScheduler();
SchedulerWhen sched = maxConcurrentScheduler(tSched);
TestSubscriber<Long> tSub = TestSubscriber.create();
syncWork(sched).subscribe(tSub);
tSub.assertValueCount(0);
tSched.advanceTimeBy(0, SECONDS);
// since all the work is synchronous nothing is blocked and its all done
tSub.assertValueCount(5);
tSub.assertComplete();
sched.dispose();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class SingleTimeoutTest method shouldUnsubscribeFromUnderlyingSubscriptionOnDispose.
@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() {
final PublishSubject<String> subject = PublishSubject.create();
final TestScheduler scheduler = new TestScheduler();
final TestObserver<String> observer = subject.single("").timeout(100, TimeUnit.MILLISECONDS, scheduler).test();
assertTrue(subject.hasObservers());
observer.dispose();
assertFalse(subject.hasObservers());
}
Aggregations