use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableThrottleFirstTest method testThrottle.
@Test
public void testThrottle() {
Subscriber<Integer> observer = TestHelper.mockSubscriber();
TestScheduler s = new TestScheduler();
PublishProcessor<Integer> o = PublishProcessor.create();
o.throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(observer);
// 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(observer);
inOrder.verify(observer).onNext(1);
inOrder.verify(observer).onNext(3);
inOrder.verify(observer).onNext(7);
inOrder.verify(observer).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnDispose.
@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() {
final PublishProcessor<String> subject = PublishProcessor.create();
final TestScheduler scheduler = new TestScheduler();
final TestSubscriber<String> observer = subject.timeout(100, TimeUnit.MILLISECONDS, scheduler).test();
assertTrue(subject.hasSubscribers());
observer.dispose();
assertFalse(subject.hasSubscribers());
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout.
@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout() throws InterruptedException {
// From https://github.com/ReactiveX/RxJava/pull/951
final Subscription s = mock(Subscription.class);
Flowable<String> never = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(s);
}
});
TestScheduler testScheduler = new TestScheduler();
Flowable<String> observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
Subscriber<String> observer = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<String>(observer);
observableWithTimeout.subscribe(ts);
testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onError(isA(TimeoutException.class));
inOrder.verifyNoMoreInteractions();
verify(s, times(1)).cancel();
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTimeoutTests method setUp.
@Before
public void setUp() {
underlyingSubject = PublishProcessor.create();
testScheduler = new TestScheduler();
withTimeout = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler);
}
use of io.reactivex.schedulers.TestScheduler in project RxJava by ReactiveX.
the class FlowableTakeTimedTest method testTakeTimed.
@Test
public void testTakeTimed() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.take(1, TimeUnit.SECONDS, scheduler);
Subscriber<Object> o = TestHelper.mockSubscriber();
result.subscribe(o);
source.onNext(1);
source.onNext(2);
source.onNext(3);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
source.onNext(4);
InOrder inOrder = inOrder(o);
inOrder.verify(o).onNext(1);
inOrder.verify(o).onNext(2);
inOrder.verify(o).onNext(3);
inOrder.verify(o).onComplete();
inOrder.verifyNoMoreInteractions();
verify(o, never()).onNext(4);
verify(o, never()).onError(any(Throwable.class));
}
Aggregations