use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleLastTests method testThrottle.
@Test
public void testThrottle() {
Subscriber<Integer> observer = TestHelper.mockSubscriber();
TestScheduler s = new TestScheduler();
PublishProcessor<Integer> o = PublishProcessor.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 FlowableDebounceTest method debounceWithTimeBackpressure.
@Test
public void debounceWithTimeBackpressure() throws InterruptedException {
TestScheduler scheduler = new TestScheduler();
TestSubscriber<Integer> subscriber = new TestSubscriber<Integer>();
Flowable.merge(Flowable.just(1), Flowable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler)).debounce(20, TimeUnit.MILLISECONDS, scheduler).take(1).subscribe(subscriber);
scheduler.advanceTimeBy(30, TimeUnit.MILLISECONDS);
subscriber.assertValue(2);
subscriber.assertTerminated();
subscriber.assertNoErrors();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableDebounceTest method badSource.
@Test
public void badSource() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
new Flowable<Integer>() {
@Override
protected void subscribeActual(Subscriber<? super Integer> observer) {
observer.onSubscribe(new BooleanSubscription());
observer.onComplete();
observer.onNext(1);
observer.onError(new TestException());
observer.onComplete();
}
}.debounce(1, TimeUnit.SECONDS, new TestScheduler()).test().assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingFlowableLatestTest method testSimpleJustNext.
@Test(timeout = 1000, expected = NoSuchElementException.class)
public void testSimpleJustNext() {
TestScheduler scheduler = new TestScheduler();
Flowable<Long> source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
Iterable<Long> iter = source.blockingLatest();
Iterator<Long> it = iter.iterator();
// which onComplete will overwrite the previous value
for (int i = 0; i < 10; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(Long.valueOf(i), it.next());
}
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class BlockingFlowableMostRecentTest method testSingleSourceManyIterators.
@Test(timeout = 1000)
public void testSingleSourceManyIterators() {
TestScheduler scheduler = new TestScheduler();
Flowable<Long> source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
Iterable<Long> iter = source.blockingMostRecent(-1L);
for (int j = 0; j < 3; j++) {
Iterator<Long> it = iter.iterator();
Assert.assertEquals(Long.valueOf(-1), it.next());
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(true, it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
}
}
Aggregations