Search in sources :

Example 11 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.

the class FlowableSkipTimedTest method testSkipTimedErrorBeforeTime.

@Test
public void testSkipTimedErrorBeforeTime() {
    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.onError(new TestException());
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    InOrder inOrder = inOrder(o);
    inOrder.verify(o).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.exceptions.TestException) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 12 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.

the class FlowableTakeTimedTest method testTakeTimedErrorAfterTime.

@Test
public void testTakeTimedErrorAfterTime() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<Integer> source = PublishProcessor.create();
    Flowable<Integer> result = source.take(1, TimeUnit.SECONDS, scheduler);
    Subscriber<Object> o = TestHelper.mockSubscriber();
    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));
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.exceptions.TestException) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 13 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.

the class FlowableTimerTest method timerCancelRace.

@Test
public void timerCancelRace() {
    for (int i = 0; i < 500; i++) {
        final TestSubscriber<Long> ts = new TestSubscriber<Long>();
        final TestScheduler scheduler = new TestScheduler();
        Flowable.timer(1, TimeUnit.SECONDS, scheduler).subscribe(ts);
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                ts.cancel();
            }
        };
        TestHelper.race(r1, r2);
    }
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler)

Example 14 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.

the class BlockingObservableMostRecentTest method testSingleSourceManyIterators.

@Test(timeout = 1000)
public void testSingleSourceManyIterators() {
    TestScheduler scheduler = new TestScheduler();
    Observable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
    Iterable<Long> iter = source.blockingMostRecent(-1L);
    for (int j = 0; j < 3; j++) {
        Iterator<Long> it = iter.iterator();
        Assert.assertEquals(Long.valueOf(-1), it.next());
        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());
    }
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler)

Example 15 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.

the class MaybeDelaySubscriptionTest method timedTestScheduler.

@Test
public void timedTestScheduler() {
    TestScheduler scheduler = new TestScheduler();
    TestObserver<Integer> ts = Maybe.just(1).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler).test();
    ts.assertEmpty();
    scheduler.advanceTimeBy(99, TimeUnit.MILLISECONDS);
    ts.assertEmpty();
    scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
    ts.assertResult(1);
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Aggregations

TestScheduler (io.reactivex.schedulers.TestScheduler)94 Test (org.junit.Test)53 InOrder (org.mockito.InOrder)26 TestException (io.reactivex.exceptions.TestException)11 Worker (io.reactivex.Scheduler.Worker)6 TestSubscriber (io.reactivex.subscribers.TestSubscriber)6 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)5 TestObserver (io.reactivex.observers.TestObserver)5 Disposable (io.reactivex.disposables.Disposable)3 Action (io.reactivex.functions.Action)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 IOException (java.io.IOException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 NonBlockingConnectionPool (org.davidmoten.rx.jdbc.pool.NonBlockingConnectionPool)1 Before (org.junit.Before)1