use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableReplayTest method delayedUpstreamSubscription.
@Test
public void delayedUpstreamSubscription() {
AtomicReference<Subscriber<? super Integer>> ref = new AtomicReference<>();
Flowable<Integer> f = Flowable.<Integer>unsafeCreate(ref::set);
TestSubscriber<Integer> ts = f.replay().autoConnect().test();
AtomicLong requested = new AtomicLong();
ref.get().onSubscribe(new Subscription() {
@Override
public void request(long n) {
BackpressureHelper.add(requested, n);
}
@Override
public void cancel() {
}
});
assertEquals(Long.MAX_VALUE, requested.get());
ref.get().onComplete();
ts.assertResult();
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableReplayTest method disposeNoNeedForResetSizeBound.
@Test
public void disposeNoNeedForResetSizeBound() {
PublishProcessor<Integer> pp = PublishProcessor.create();
ConnectableFlowable<Integer> cf = pp.replay(10);
TestSubscriber<Integer> ts = cf.test();
Disposable d = cf.connect();
pp.onNext(1);
d.dispose();
ts = cf.test();
ts.assertEmpty();
cf.connect();
ts.assertEmpty();
pp.onNext(2);
ts.assertValuesOnly(2);
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableSwitchIfEmptyTest method requestsNotLost.
@Test
public void requestsNotLost() throws InterruptedException {
final TestSubscriber<Long> ts = new TestSubscriber<>(0L);
Flowable.unsafeCreate(new Publisher<Long>() {
@Override
public void subscribe(final Subscriber<? super Long> subscriber) {
subscriber.onSubscribe(new Subscription() {
final AtomicBoolean completed = new AtomicBoolean(false);
@Override
public void request(long n) {
if (n > 0 && completed.compareAndSet(false, true)) {
Schedulers.io().createWorker().schedule(new Runnable() {
@Override
public void run() {
subscriber.onComplete();
}
}, 100, TimeUnit.MILLISECONDS);
}
}
@Override
public void cancel() {
}
});
}
}).switchIfEmpty(Flowable.fromIterable(Arrays.asList(1L, 2L, 3L))).subscribeOn(Schedulers.computation()).subscribe(ts);
Thread.sleep(50);
// request while first observable is still finishing (as empty)
ts.request(1);
ts.request(1);
Thread.sleep(500);
ts.assertNotComplete();
ts.assertNoErrors();
ts.assertValueCount(2);
ts.cancel();
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableSubscribeOnTest method deferredRequestRace.
@Test
public void deferredRequestRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = new TestSubscriber<>(0L);
Worker w = Schedulers.computation().createWorker();
final SubscribeOnSubscriber<Integer> so = new SubscribeOnSubscriber<>(ts, w, Flowable.<Integer>never(), true);
ts.onSubscribe(so);
final BooleanSubscription bs = new BooleanSubscription();
try {
Runnable r1 = new Runnable() {
@Override
public void run() {
so.onSubscribe(bs);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
so.request(1);
}
};
TestHelper.race(r1, r2);
} finally {
w.dispose();
}
}
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber 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();
}
Aggregations