use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingObservableLatestTest method testNextThrows.
@Test(timeout = 1000, expected = RuntimeException.class)
public void testNextThrows() {
TestScheduler scheduler = new TestScheduler();
Observable<Long> source = Observable.<Long>error(new RuntimeException("Forced failure!")).subscribeOn(scheduler);
Iterable<Long> iter = source.blockingLatest();
Iterator<Long> it = iter.iterator();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
it.next();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingObservableLatestTest method testSimple.
@Test(timeout = 1000)
public void testSimple() {
TestScheduler scheduler = new TestScheduler();
Observable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
Iterable<Long> iter = source.blockingLatest();
Iterator<Long> it = iter.iterator();
// which onComplete will overwrite the previous value
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(true, it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingObservableLatestTest method testSameSourceMultipleIterators.
@Test(timeout = 1000)
public void testSameSourceMultipleIterators() {
TestScheduler scheduler = new TestScheduler();
Observable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
Iterable<Long> iter = source.blockingLatest();
for (int j = 0; j < 3; j++) {
Iterator<Long> it = iter.iterator();
// which onComplete will overwrite the previous value
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(true, it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
}
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableSwitchTest method before.
@Before
public void before() {
scheduler = new TestScheduler();
innerScheduler = scheduler.createWorker();
observer = TestHelper.mockObserver();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyComplete.
@Test
@Ignore("s should be considered cancelled upon executing onComplete and not expect downstream to call cancel")
public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyComplete() {
// From https://github.com/ReactiveX/RxJava/pull/951
final Disposable s = mock(Disposable.class);
Observable<String> immediatelyComplete = Observable.unsafeCreate(new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> observer) {
observer.onSubscribe(s);
observer.onComplete();
}
});
TestScheduler testScheduler = new TestScheduler();
Observable<String> observableWithTimeout = immediatelyComplete.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
Observer<String> observer = TestHelper.mockObserver();
TestObserver<String> ts = new TestObserver<String>(observer);
observableWithTimeout.subscribe(ts);
testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onComplete();
inOrder.verifyNoMoreInteractions();
verify(s, times(1)).dispose();
}
Aggregations