use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableSkipTimedTest method skipTimedFinishBeforeTime.
@Test
public void skipTimedFinishBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onComplete();
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
InOrder inOrder = inOrder(o);
inOrder.verify(o).onComplete();
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableSkipTimedTest method skipTimed.
@Test
public void skipTimed() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
source.onNext(5);
source.onNext(6);
source.onComplete();
InOrder inOrder = inOrder(o);
inOrder.verify(o, never()).onNext(1);
inOrder.verify(o, never()).onNext(2);
inOrder.verify(o, never()).onNext(3);
inOrder.verify(o).onNext(4);
inOrder.verify(o).onNext(5);
inOrder.verify(o).onNext(6);
inOrder.verify(o).onComplete();
inOrder.verifyNoMoreInteractions();
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class ObservableSkipTimedTest method skipTimedErrorBeforeTime.
@Test
public void skipTimedErrorBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Integer> result = source.skip(1, TimeUnit.SECONDS, scheduler);
Observer<Object> o = TestHelper.mockObserver();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
source.onError(new TestException());
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
InOrder inOrder = inOrder(o);
inOrder.verify(o).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleLastTests method throttle.
@Test
public void throttle() {
Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
TestScheduler s = new TestScheduler();
PublishProcessor<Integer> o = PublishProcessor.create();
o.throttleLast(500, TimeUnit.MILLISECONDS, s).subscribe(subscriber);
// 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(subscriber);
inOrder.verify(subscriber).onNext(2);
inOrder.verify(subscriber).onNext(6);
inOrder.verify(subscriber).onNext(7);
inOrder.verify(subscriber).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleWithTimeoutTests method throttle.
@Test
public void throttle() {
Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
TestScheduler s = new TestScheduler();
PublishProcessor<Integer> o = PublishProcessor.create();
o.throttleWithTimeout(500, TimeUnit.MILLISECONDS, s).subscribe(subscriber);
// 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(subscriber);
inOrder.verify(subscriber).onNext(2);
inOrder.verify(subscriber).onNext(6);
inOrder.verify(subscriber).onNext(7);
inOrder.verify(subscriber).onComplete();
inOrder.verifyNoMoreInteractions();
}
Aggregations