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();
}
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();
}
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);
}
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());
}
}
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();
}
}
Aggregations