use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class FlowableTakeTimedTest method takeTimed.
@Test
public void takeTimed() {
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);
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(Throwable.class));
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class FlowableThrottleFirstTest method throttlingWithError.
@Test
public void throttlingWithError() {
Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
Exception error = new TestException();
// Should be published since it is first
publishNext(subscriber, 100, "one");
// Should be skipped since onError will arrive before the timeout expires
publishNext(subscriber, 200, "two");
// Should be published as soon as the timeout expires.
publishError(subscriber, 300, error);
}
});
Flowable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(subscriber);
InOrder inOrder = inOrder(subscriber);
scheduler.advanceTimeTo(400, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber).onNext("one");
inOrder.verify(subscriber).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class FlowableThrottleFirstTest method before.
@Before
public void before() {
scheduler = new TestScheduler();
innerScheduler = scheduler.createWorker();
subscriber = TestHelper.mockSubscriber();
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class FlowableThrottleFirstTest method throttlingWithCompleted.
@Test
public void throttlingWithCompleted() {
Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
// publish as it's first
publishNext(subscriber, 100, "one");
// skip as it's last within the first 400
publishNext(subscriber, 300, "two");
// publish
publishNext(subscriber, 900, "three");
// skip
publishNext(subscriber, 905, "four");
// Should be published as soon as the timeout expires.
publishCompleted(subscriber, 1000);
}
});
Flowable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(subscriber);
InOrder inOrder = inOrder(subscriber);
scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
inOrder.verify(subscriber, times(1)).onNext("one");
inOrder.verify(subscriber, times(0)).onNext("two");
inOrder.verify(subscriber, times(1)).onNext("three");
inOrder.verify(subscriber, times(0)).onNext("four");
inOrder.verify(subscriber, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class FlowableSkipLastTimedTest method skipLastTimedErrorBeforeTime.
@Test
public void skipLastTimedErrorBeforeTime() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<Integer> source = PublishProcessor.create();
Flowable<Integer> result = source.skipLast(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(1050, TimeUnit.MILLISECONDS);
verify(subscriber).onError(any(TestException.class));
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onNext(any());
}
Aggregations