use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ReplayProcessorTest method timedNoOutdatedData.
@Test
public void timedNoOutdatedData() {
TestScheduler scheduler = new TestScheduler();
ReplayProcessor<Integer> source = ReplayProcessor.createWithTime(2, TimeUnit.SECONDS, scheduler);
source.onNext(1);
source.onComplete();
source.test().assertResult(1);
source.test().assertResult(1);
scheduler.advanceTimeBy(3, TimeUnit.SECONDS);
source.test().assertResult();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ReplayProcessorTest method timedSkipOld.
@Test
public void timedSkipOld() {
TestScheduler scheduler = new TestScheduler();
ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
rp.onNext(1);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
rp.test().assertEmpty();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ReplayProcessorTest method reentrantDrain.
@Test
public void reentrantDrain() {
TestScheduler scheduler = new TestScheduler();
final ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer t) {
if (t == 1) {
rp.onNext(2);
}
super.onNext(t);
}
};
rp.subscribe(ts);
rp.onNext(1);
rp.onComplete();
ts.assertResult(1, 2);
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableThrottleLastTests method testThrottle.
@Test
public void testThrottle() {
Observer<Integer> observer = TestHelper.mockObserver();
TestScheduler s = new TestScheduler();
PublishSubject<Integer> o = PublishSubject.create();
o.throttleLast(500, TimeUnit.MILLISECONDS, s).subscribe(observer);
// send events with simulated time increments
s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
// skip
o.onNext(1);
// deliver
o.onNext(2);
s.advanceTimeTo(501, TimeUnit.MILLISECONDS);
// skip
o.onNext(3);
s.advanceTimeTo(600, TimeUnit.MILLISECONDS);
// skip
o.onNext(4);
s.advanceTimeTo(700, TimeUnit.MILLISECONDS);
// skip
o.onNext(5);
// deliver
o.onNext(6);
s.advanceTimeTo(1001, TimeUnit.MILLISECONDS);
// deliver
o.onNext(7);
s.advanceTimeTo(1501, TimeUnit.MILLISECONDS);
o.onComplete();
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onNext(2);
inOrder.verify(observer).onNext(6);
inOrder.verify(observer).onNext(7);
inOrder.verify(observer).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class TestSchedulerTest method timedRunnableToString.
@Test
public void timedRunnableToString() {
TimedRunnable r = new TimedRunnable((TestWorker) new TestScheduler().createWorker(), 5, new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
}
@Override
public String toString() {
return "Runnable";
}
}, 1);
assertEquals("TimedRunnable(time = 5, run = Runnable)", r.toString());
}
Aggregations