use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxRelay by JakeWharton.
the class ReplayRelayTest method takeSizeAndTime.
@Test
public void takeSizeAndTime() {
TestScheduler scheduler = new TestScheduler();
ReplayRelay<Integer> rp = ReplayRelay.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
rp.accept(1);
rp.accept(2);
rp.accept(3);
rp.take(1).test().assertResult(2);
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTakeLastTimedTest method takeLastTimedThrowingSource.
@Test
public void takeLastTimedThrowingSource() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Object> source = PublishProcessor.create();
Flowable<Object> result = source.takeLast(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
InOrder inOrder = inOrder(subscriber);
result.subscribe(subscriber);
// T: 0ms
source.onNext(1);
scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
// T: 250ms
source.onNext(2);
scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
// T: 500ms
source.onNext(3);
scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
// T: 750ms
source.onNext(4);
scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
// T: 1000ms
source.onNext(5);
scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
// T: 1250ms
source.onError(new TestException());
inOrder.verify(subscriber, times(1)).onError(any(TestException.class));
verify(subscriber, never()).onNext(any());
verify(subscriber, never()).onComplete();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTakeTimedTest method takeTimedErrorAfterTime.
@Test
public void takeTimedErrorAfterTime() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.take(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
result.subscribe(subscriber);
source.onNext(1);
source.onNext(2);
source.onNext(3);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
source.onError(new TestException());
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber).onNext(1);
inOrder.verify(subscriber).onNext(2);
inOrder.verify(subscriber).onNext(3);
inOrder.verify(subscriber).onComplete();
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onNext(4);
verify(subscriber, never()).onError(any(TestException.class));
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTakeTimedTest method takeTimedErrorBeforeTime.
@Test
public void takeTimedErrorBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.take(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
result.subscribe(subscriber);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onError(new TestException());
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber).onNext(1);
inOrder.verify(subscriber).onNext(2);
inOrder.verify(subscriber).onNext(3);
inOrder.verify(subscriber).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onNext(4);
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleFirstTest method throttle.
@Test
public void throttle() {
Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
TestScheduler s = new TestScheduler();
PublishProcessor<Integer> o = PublishProcessor.create();
o.throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(subscriber);
// send events with simulated time increments
s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
// deliver
o.onNext(1);
// skip
o.onNext(2);
s.advanceTimeTo(501, TimeUnit.MILLISECONDS);
// deliver
o.onNext(3);
s.advanceTimeTo(600, TimeUnit.MILLISECONDS);
// skip
o.onNext(4);
s.advanceTimeTo(700, TimeUnit.MILLISECONDS);
// skip
o.onNext(5);
// skip
o.onNext(6);
s.advanceTimeTo(1001, TimeUnit.MILLISECONDS);
// deliver
o.onNext(7);
s.advanceTimeTo(1501, TimeUnit.MILLISECONDS);
o.onComplete();
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber).onNext(1);
inOrder.verify(subscriber).onNext(3);
inOrder.verify(subscriber).onNext(7);
inOrder.verify(subscriber).onComplete();
inOrder.verifyNoMoreInteractions();
}
Aggregations