use of io.reactivex.rxjava3.subscribers.TestSubscriber 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.subscribers.TestSubscriber 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.subscribers.TestSubscriber 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.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableTakeUntilTest method untilPublisherOtherError.
@Test
public void untilPublisherOtherError() {
PublishProcessor<Integer> main = PublishProcessor.create();
PublishProcessor<Integer> other = PublishProcessor.create();
TestSubscriber<Integer> ts = main.takeUntil(other).test();
assertTrue("Main no subscribers?", main.hasSubscribers());
assertTrue("Other no subscribers?", other.hasSubscribers());
other.onError(new TestException());
assertFalse("Main has subscribers?", main.hasSubscribers());
assertFalse("Other has subscribers?", other.hasSubscribers());
ts.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableTimeoutWithSelectorTest method lateOnTimeoutError.
@Test
public void lateOnTimeoutError() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final Subscriber<?>[] sub = { null, null };
final Flowable<Integer> pp2 = new Flowable<Integer>() {
int count;
@Override
protected void subscribeActual(Subscriber<? super Integer> s) {
s.onSubscribe(new BooleanSubscription());
sub[count++] = s;
}
};
TestSubscriber<Integer> ts = pp.timeout(Functions.justFunction(pp2)).test();
pp.onNext(0);
Runnable r1 = new Runnable() {
@Override
public void run() {
pp.onNext(1);
}
};
final Throwable ex = new TestException();
Runnable r2 = new Runnable() {
@Override
public void run() {
sub[0].onError(ex);
}
};
TestHelper.race(r1, r2);
ts.assertValueAt(0, 0);
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
Aggregations