use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableReplayTest method timedAndSizedTruncationError.
@Test
public void timedAndSizedTruncationError() {
TestScheduler test = new TestScheduler();
SizeAndTimeBoundReplayBuffer<Integer> buf = new SizeAndTimeBoundReplayBuffer<>(2, 2000, TimeUnit.MILLISECONDS, test, false);
Assert.assertFalse(buf.hasCompleted());
Assert.assertFalse(buf.hasError());
List<Integer> values = new ArrayList<>();
buf.next(1);
test.advanceTimeBy(1, TimeUnit.SECONDS);
buf.next(2);
test.advanceTimeBy(1, TimeUnit.SECONDS);
buf.collect(values);
Assert.assertEquals(Arrays.asList(2), values);
buf.next(3);
buf.next(4);
values.clear();
buf.collect(values);
Assert.assertEquals(Arrays.asList(3, 4), values);
test.advanceTimeBy(2, TimeUnit.SECONDS);
buf.next(5);
values.clear();
buf.collect(values);
Assert.assertEquals(Arrays.asList(5), values);
Assert.assertFalse(buf.hasCompleted());
Assert.assertFalse(buf.hasError());
test.advanceTimeBy(2, TimeUnit.SECONDS);
buf.error(new TestException());
values.clear();
buf.collect(values);
Assert.assertTrue(values.isEmpty());
Assert.assertEquals(1, buf.size);
Assert.assertFalse(buf.hasCompleted());
Assert.assertTrue(buf.hasError());
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleLatestTest method missingBackpressureExceptionFirst.
@Test
public void missingBackpressureExceptionFirst() throws Throwable {
TestScheduler sch = new TestScheduler();
Action onCancel = mock(Action.class);
Flowable.just(1, 2).doOnCancel(onCancel).throttleLatest(1, TimeUnit.MINUTES, sch).test(0).assertFailure(MissingBackpressureException.class);
verify(onCancel).run();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleLatestTest method missingBackpressureExceptionLatestComplete.
@Test
public void missingBackpressureExceptionLatestComplete() throws Throwable {
TestScheduler sch = new TestScheduler();
Action onCancel = mock(Action.class);
PublishProcessor<Integer> pp = PublishProcessor.create();
TestSubscriber<Integer> ts = pp.doOnCancel(onCancel).throttleLatest(1, TimeUnit.SECONDS, sch, true).test(1);
pp.onNext(1);
pp.onNext(2);
ts.assertValuesOnly(1);
pp.onComplete();
ts.assertFailure(MissingBackpressureException.class, 1);
verify(onCancel, never()).run();
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleLatestTest method reentrantComplete.
@Test
public void reentrantComplete() {
TestScheduler sch = new TestScheduler();
final PublishProcessor<Integer> pp = PublishProcessor.create();
TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer t) {
super.onNext(t);
if (t == 1) {
pp.onNext(2);
}
if (t == 2) {
pp.onComplete();
}
}
};
pp.throttleLatest(1, TimeUnit.SECONDS, sch).subscribe(ts);
pp.onNext(1);
sch.advanceTimeBy(1, TimeUnit.SECONDS);
ts.assertResult(1, 2);
}
use of io.reactivex.rxjava3.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldSwitchToOtherIfOnCompletedNotWithinTimeout.
@Test
public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() {
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.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.verify(subscriber, times(1)).onNext("c");
inOrder.verify(subscriber, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
ts.cancel();
}
Aggregations