Search in sources :

Example 36 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxRelay by JakeWharton.

the class ReplayRelayTest method testReplayTimestampedDirectly.

@Test
public void testReplayTimestampedDirectly() {
    TestScheduler scheduler = new TestScheduler();
    ReplayRelay<Integer> source = ReplayRelay.createWithTime(1, TimeUnit.SECONDS, scheduler);
    source.accept(1);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    Observer<Integer> o = TestHelper.mockObserver();
    source.subscribe(o);
    source.accept(2);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    source.accept(3);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    //source.onComplete();
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    verify(o, never()).onError(any(Throwable.class));
    verify(o, never()).onNext(1);
    verify(o).onNext(2);
    verify(o).onNext(3);
//verify(o).onComplete();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 37 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxRelay by JakeWharton.

the class ReplayRelayTest method timedSkipOld.

@Test
public void timedSkipOld() {
    TestScheduler scheduler = new TestScheduler();
    ReplayRelay<Integer> rp = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
    rp.accept(1);
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    rp.test().assertEmpty();
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 38 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxRelay by JakeWharton.

the class ReplayRelayTest method reentrantDrain.

@Test
public void reentrantDrain() {
    TestScheduler scheduler = new TestScheduler();
    final ReplayRelay<Integer> rp = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
    TestObserver<Integer> ts = new TestObserver<Integer>() {

        @Override
        public void onNext(Integer t) {
            if (t == 1) {
                rp.accept(2);
            }
            super.onNext(t);
        }
    };
    rp.subscribe(ts);
    rp.accept(1);
    ts.assertValues(1, 2);
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 39 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project RxRelay by JakeWharton.

the class ReplayRelayTest method testSizeAndHasAnyValueTimeBounded.

@Test
public void testSizeAndHasAnyValueTimeBounded() {
    TestScheduler ts = new TestScheduler();
    ReplayRelay<Object> rs = ReplayRelay.createWithTime(1, TimeUnit.SECONDS, ts);
    assertEquals(0, rs.size());
    assertFalse(rs.hasValue());
    for (int i = 0; i < 1000; i++) {
        rs.accept(i);
        ts.advanceTimeBy(2, TimeUnit.SECONDS);
        assertEquals(1, rs.size());
        assertTrue(rs.hasValue());
    }
}
Also used : TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 40 with TestScheduler

use of io.reactivex.schedulers.TestScheduler in project rxjava2-jdbc by davidmoten.

the class DatabaseTest method testHealthCheck.

private void testHealthCheck(Predicate<Connection> healthy) throws InterruptedException {
    TestScheduler scheduler = new TestScheduler();
    NonBlockingConnectionPool pool = //
    Pools.nonBlocking().connectionProvider(//
    DatabaseCreator.connectionProvider()).maxIdleTime(10, //
    TimeUnit.MINUTES).idleTimeBeforeHealthCheck(0, //
    TimeUnit.MINUTES).healthy(//
    healthy).returnToPoolDelayAfterHealthCheckFailure(1, //
    TimeUnit.MINUTES).scheduler(//
    scheduler).maxPoolSize(//
    1).build();
    try (Database db = Database.from(pool)) {
        //
        db.select(//
        "select score from person where name=?").parameters(//
        "FRED").getAs(//
        Integer.class).test().assertValueCount(//
        1).assertComplete();
        TestSubscriber<Integer> ts = db.select(//
        "select score from person where name=?").parameters(//
        "FRED").getAs(//
        Integer.class).test().assertValueCount(0);
        scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
        Thread.sleep(200);
        ts.assertValueCount(1);
        Thread.sleep(200);
        //
        ts.assertValue(21).assertComplete();
    }
}
Also used : NonBlockingConnectionPool(org.davidmoten.rx.jdbc.pool.NonBlockingConnectionPool) TestScheduler(io.reactivex.schedulers.TestScheduler)

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