use of io.reactivex.rxjava3.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);
assertEquals(1, rs.size());
assertTrue(rs.hasValue());
ts.advanceTimeBy(2, TimeUnit.SECONDS);
assertEquals(0, rs.size());
assertFalse(rs.hasValue());
}
}
use of io.reactivex.rxjava3.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.rxjava3.schedulers.TestScheduler in project RxRelay by JakeWharton.
the class ReplayRelayTest method timeAndSizeRemoveCorrectNumberOfOld.
@Test
public void timeAndSizeRemoveCorrectNumberOfOld() {
TestScheduler scheduler = new TestScheduler();
ReplayRelay<Integer> rs = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
rs.accept(1);
rs.accept(2);
// remove 1 due to maxSize, size == 2
rs.accept(3);
scheduler.advanceTimeBy(2, TimeUnit.SECONDS);
// remove 2 due to maxSize, remove 3 due to age, size == 1
rs.accept(4);
// size == 2
rs.accept(5);
rs.test().assertValuesOnly(4, 5);
}
use of io.reactivex.rxjava3.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.rxjava3.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();
}
Aggregations