Search in sources :

Example 46 with TestScheduler

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

the class BlockingFlowableMostRecentTest method testSingleSourceManyIterators.

@Test(timeout = 1000)
public void testSingleSourceManyIterators() {
    TestScheduler scheduler = new TestScheduler();
    Flowable<Long> source = Flowable.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 47 with TestScheduler

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

the class BlockingFlowableLatestTest method testSimple.

@Test(timeout = 1000)
public void testSimple() {
    TestScheduler scheduler = new TestScheduler();
    Flowable<Long> source = Flowable.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());
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler)

Example 48 with TestScheduler

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

the class BlockingFlowableLatestTest method testHasNextThrows.

@Test(/* timeout = 1000, */
expected = RuntimeException.class)
public void testHasNextThrows() {
    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.hasNext();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler)

Example 49 with TestScheduler

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

the class BlockingFlowableLatestTest method testSameSourceMultipleIterators.

@Test(timeout = 1000)
public void testSameSourceMultipleIterators() {
    TestScheduler scheduler = new TestScheduler();
    Flowable<Long> source = Flowable.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());
    }
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler)

Example 50 with TestScheduler

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

the class CompletableDisposeOnTest method errorAfterCancel.

@Test
public void errorAfterCancel() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestScheduler scheduler = new TestScheduler();
        PublishSubject<Integer> ps = PublishSubject.create();
        TestObserver<Void> to = ps.ignoreElements().unsubscribeOn(scheduler).test();
        to.dispose();
        ps.onError(new TestException());
        to.assertEmpty();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) 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