use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableThrottleWithTimeoutTests method testThrottle.
@Test
public void testThrottle() {
Observer<Integer> observer = TestHelper.mockObserver();
TestScheduler s = new TestScheduler();
PublishSubject<Integer> o = PublishSubject.create();
o.throttleWithTimeout(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 at 1300 after 500ms has passed since onNext(5)
o.onNext(6);
s.advanceTimeTo(1300, TimeUnit.MILLISECONDS);
// deliver
o.onNext(7);
s.advanceTimeTo(1800, 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 ReplayProcessorTest method reentrantDrainBackpressured.
@Test
public void reentrantDrainBackpressured() {
TestScheduler scheduler = new TestScheduler();
final ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1L) {
@Override
public void onNext(Integer t) {
if (t == 1) {
rp.onNext(2);
}
super.onNext(t);
}
};
rp.subscribe(ts);
rp.onNext(1);
rp.onComplete();
ts.request(1);
ts.assertResult(1, 2);
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ReplayProcessorTest method testReplayTimestampedAfterTermination.
@Test
public void testReplayTimestampedAfterTermination() {
TestScheduler scheduler = new TestScheduler();
ReplayProcessor<Integer> source = ReplayProcessor.createWithTime(1, TimeUnit.SECONDS, scheduler);
source.onNext(1);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(2);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(3);
source.onComplete();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Subscriber<Integer> o = TestHelper.mockSubscriber();
source.subscribe(o);
verify(o, never()).onNext(1);
verify(o, never()).onNext(2);
verify(o, never()).onNext(3);
verify(o).onComplete();
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ReplayProcessorTest method testSizeAndHasAnyValueTimeBounded.
@Test
public void testSizeAndHasAnyValueTimeBounded() {
TestScheduler ts = new TestScheduler();
ReplayProcessor<Object> rs = ReplayProcessor.createWithTime(1, TimeUnit.SECONDS, ts);
assertEquals(0, rs.size());
assertFalse(rs.hasValue());
for (int i = 0; i < 1000; i++) {
rs.onNext(i);
assertEquals(1, rs.size());
assertTrue(rs.hasValue());
ts.advanceTimeBy(2, TimeUnit.SECONDS);
assertEquals(0, rs.size());
assertFalse(rs.hasValue());
}
rs.onComplete();
assertEquals(0, rs.size());
assertFalse(rs.hasValue());
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ReplayProcessorTest method testReplayTimestampedDirectly.
@Test
public void testReplayTimestampedDirectly() {
TestScheduler scheduler = new TestScheduler();
ReplayProcessor<Integer> source = ReplayProcessor.createWithTime(1, TimeUnit.SECONDS, scheduler);
source.onNext(1);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Subscriber<Integer> o = TestHelper.mockSubscriber();
source.subscribe(o);
source.onNext(2);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(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