use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class SingleSwitchOnNextTest method delaySwitch.
@Test
public void delaySwitch() {
PublishProcessor<Single<Integer>> pp = PublishProcessor.create();
TestSubscriber<Integer> ts = Single.switchOnNextDelayError(pp).test();
assertTrue(pp.hasSubscribers());
ts.assertEmpty();
SingleSubject<Integer> ss1 = SingleSubject.create();
SingleSubject<Integer> ss2 = SingleSubject.create();
pp.onNext(ss1);
assertTrue(ss1.hasObservers());
pp.onNext(ss2);
assertFalse(ss1.hasObservers());
assertTrue(ss2.hasObservers());
assertTrue(ss2.hasObservers());
ss2.onError(new TestException());
assertTrue(pp.hasSubscribers());
ts.assertEmpty();
pp.onComplete();
ts.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class TrampolineSchedulerTest method trampolineWorkerHandlesConcurrentScheduling.
/**
* This is a regression test for #1702. Concurrent work scheduling that is improperly synchronized can cause an
* action to be added or removed onto the priority queue during a poll, which can result in NPEs during queue
* sifting. While it is difficult to isolate the issue directly, we can easily trigger the behavior by spamming the
* trampoline with enqueue requests from multiple threads concurrently.
*/
@Test
public void trampolineWorkerHandlesConcurrentScheduling() {
final Worker trampolineWorker = Schedulers.trampoline().createWorker();
final Subscriber<Object> subscriber = TestHelper.mockSubscriber();
final TestSubscriber<Disposable> ts = new TestSubscriber<>(subscriber);
// Spam the trampoline with actions.
Flowable.range(0, 50).flatMap(new Function<Integer, Publisher<Disposable>>() {
@Override
public Publisher<Disposable> apply(Integer count) {
return Flowable.interval(1, TimeUnit.MICROSECONDS).map(new Function<Long, Disposable>() {
@Override
public Disposable apply(Long ount1) {
return trampolineWorker.schedule(Functions.EMPTY_RUNNABLE);
}
}).take(100);
}
}).subscribeOn(Schedulers.computation()).subscribe(ts);
ts.awaitDone(5, TimeUnit.SECONDS);
ts.assertNoErrors();
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class SingleCacheTest method crossCancelOnError.
@Test
public void crossCancelOnError() {
PublishSubject<Integer> ps = PublishSubject.create();
Single<Integer> cache = ps.single(-99).cache();
final TestSubscriber<Integer> ts1 = new TestSubscriber<>();
TestSubscriber<Integer> ts2 = new TestSubscriber<Integer>() {
@Override
public void onError(Throwable t) {
super.onError(t);
ts1.cancel();
}
};
cache.toFlowable().subscribe(ts2);
cache.toFlowable().subscribe(ts1);
ps.onError(new TestException());
ts1.assertNoValues().assertNoErrors().assertNotComplete();
ts2.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class SafeSubscriberTest method dispose.
@Test
public void dispose() {
TestSubscriber<Integer> ts = new TestSubscriber<>();
SafeSubscriber<Integer> so = new SafeSubscriber<>(ts);
BooleanSubscription bs = new BooleanSubscription();
so.onSubscribe(bs);
ts.dispose();
assertTrue(bs.isCancelled());
// assertTrue(so.isDisposed());
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class TestSubscriberTest method interruptTerminalEventAwaitAndUnsubscribe.
@Test
public void interruptTerminalEventAwaitAndUnsubscribe() {
TestSubscriber<Integer> ts = new TestSubscriber<>();
final Thread t0 = Thread.currentThread();
Worker w = Schedulers.computation().createWorker();
try {
w.schedule(new Runnable() {
@Override
public void run() {
t0.interrupt();
}
}, 200, TimeUnit.MILLISECONDS);
try {
ts.awaitDone(5, TimeUnit.SECONDS);
} catch (RuntimeException allowed) {
assertTrue(allowed.toString(), allowed.getCause() instanceof InterruptedException);
}
ts.dispose();
if (!ts.isCancelled()) {
fail("Did not unsubscribe!");
}
} finally {
w.dispose();
}
}
Aggregations