use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class CompletableDisposeOnTest method normal.
@Test
public void normal() {
TestScheduler scheduler = new TestScheduler();
final int[] call = { 0 };
Completable.complete().doOnDispose(new Action() {
@Override
public void run() throws Exception {
call[0]++;
}
}).unsubscribeOn(scheduler).test().assertResult();
scheduler.triggerActions();
assertEquals(0, call[0]);
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingFlowableLatestTest method testNextThrows.
@Test(timeout = 1000, expected = RuntimeException.class)
public void testNextThrows() {
TestScheduler scheduler = new TestScheduler();
Flowable<Long> source = Flowable.<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 FlowableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyErrored.
@Test
@Ignore("s should be considered cancelled upon executing onError and not expect downstream to call cancel")
public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyErrored() throws InterruptedException {
// From https://github.com/ReactiveX/RxJava/pull/951
final Subscription s = mock(Subscription.class);
Flowable<String> immediatelyError = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(s);
subscriber.onError(new IOException("Error"));
}
});
TestScheduler testScheduler = new TestScheduler();
Flowable<String> observableWithTimeout = immediatelyError.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
Subscriber<String> observer = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<String>(observer);
observableWithTimeout.subscribe(ts);
testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onError(isA(IOException.class));
inOrder.verifyNoMoreInteractions();
verify(s, times(1)).cancel();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTimeoutTests 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 Subscription s = mock(Subscription.class);
Flowable<String> immediatelyComplete = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(s);
subscriber.onComplete();
}
});
TestScheduler testScheduler = new TestScheduler();
Flowable<String> observableWithTimeout = immediatelyComplete.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
Subscriber<String> observer = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<String>(observer);
observableWithTimeout.subscribe(ts);
testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onComplete();
inOrder.verifyNoMoreInteractions();
verify(s, times(1)).cancel();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableSkipTimedTest method testSkipTimedFinishBeforeTime.
@Test
public void testSkipTimedFinishBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> o = TestHelper.mockSubscriber();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onComplete();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
InOrder inOrder = inOrder(o);
inOrder.verify(o).onComplete();
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onError(any(Throwable.class));
}
Aggregations