use of io.reactivex.rxjava3.core.Flowable 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();
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldSwitchToOtherIfOnNextNotWithinTimeout.
@Test
public void shouldSwitchToOtherIfOnNextNotWithinTimeout() {
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.onNext("Two");
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();
}
use of io.reactivex.rxjava3.core.Flowable 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.Flowable 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.Flowable 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();
}
Aggregations