use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleLatestTest method normalEmitLast.
@Test
public void normalEmitLast() {
TestScheduler sch = new TestScheduler();
PublishProcessor<Integer> pp = PublishProcessor.create();
TestSubscriber<Integer> ts = pp.throttleLatest(1, TimeUnit.SECONDS, sch, true).test();
pp.onNext(1);
ts.assertValuesOnly(1);
pp.onNext(2);
ts.assertValuesOnly(1);
pp.onNext(3);
ts.assertValuesOnly(1);
sch.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertValuesOnly(1, 3);
pp.onNext(4);
ts.assertValuesOnly(1, 3);
pp.onNext(5);
sch.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertValuesOnly(1, 3, 5);
sch.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertValuesOnly(1, 3, 5);
pp.onNext(6);
ts.assertValuesOnly(1, 3, 5, 6);
pp.onNext(7);
pp.onComplete();
ts.assertResult(1, 3, 5, 6, 7);
sch.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertResult(1, 3, 5, 6, 7);
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleLatestTest method normal.
@Test
public void normal() {
TestScheduler sch = new TestScheduler();
PublishProcessor<Integer> pp = PublishProcessor.create();
TestSubscriber<Integer> ts = pp.throttleLatest(1, TimeUnit.SECONDS, sch).test();
pp.onNext(1);
ts.assertValuesOnly(1);
pp.onNext(2);
ts.assertValuesOnly(1);
pp.onNext(3);
ts.assertValuesOnly(1);
sch.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertValuesOnly(1, 3);
pp.onNext(4);
ts.assertValuesOnly(1, 3);
pp.onNext(5);
sch.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertValuesOnly(1, 3, 5);
sch.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertValuesOnly(1, 3, 5);
pp.onNext(6);
ts.assertValuesOnly(1, 3, 5, 6);
pp.onNext(7);
pp.onComplete();
ts.assertResult(1, 3, 5, 6);
sch.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertResult(1, 3, 5, 6);
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleLatestTest method missingBackpressureExceptionLatest.
@Test
public void missingBackpressureExceptionLatest() throws Throwable {
TestScheduler sch = new TestScheduler();
Action onCancel = mock(Action.class);
TestSubscriber<Integer> ts = Flowable.just(1, 2).concatWith(Flowable.<Integer>never()).doOnCancel(onCancel).throttleLatest(1, TimeUnit.SECONDS, sch, true).test(1);
sch.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertFailure(MissingBackpressureException.class, 1);
verify(onCancel).run();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout.
@Test
public void shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout() {
PublishProcessor<String> other = PublishProcessor.create();
Flowable<String> source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<>(subscriber);
source.subscribe(ts);
testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
underlyingSubject.onNext("One");
testScheduler.advanceTimeBy(4, TimeUnit.SECONDS);
underlyingSubject.onNext("Two");
other.onNext("a");
other.onNext("b");
ts.cancel();
// The following messages should not be delivered.
other.onNext("c");
other.onNext("d");
other.onComplete();
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber, times(1)).onNext("One");
inOrder.verify(subscriber, times(1)).onNext("a");
inOrder.verify(subscriber, times(1)).onNext("b");
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldSwitchToOtherIfOnErrorNotWithinTimeout.
@Test
public void shouldSwitchToOtherIfOnErrorNotWithinTimeout() {
Flowable<String> other = Flowable.just("a", "b", "c");
Flowable<String> source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<>(subscriber);
source.subscribe(ts);
testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
underlyingSubject.onNext("One");
testScheduler.advanceTimeBy(4, TimeUnit.SECONDS);
underlyingSubject.onError(new UnsupportedOperationException());
InOrder inOrder = inOrder(subscriber);
inOrder.verify(subscriber, times(1)).onNext("One");
inOrder.verify(subscriber, times(1)).onNext("a");
inOrder.verify(subscriber, times(1)).onNext("b");
inOrder.verify(subscriber, times(1)).onNext("c");
inOrder.verify(subscriber, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
ts.cancel();
}
Aggregations