use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class AsyncProcessorTest method onErrorCrossCancel.
@Test
@SuppressUndeliverable
public void onErrorCrossCancel() {
AsyncProcessor<Object> p = AsyncProcessor.create();
final TestSubscriber<Object> ts2 = new TestSubscriber<>();
TestSubscriber<Object> ts1 = new TestSubscriber<Object>() {
@Override
public void onError(Throwable t) {
ts2.cancel();
super.onError(t);
}
};
p.subscribe(ts1);
p.subscribe(ts2);
p.onError(new TestException());
ts1.assertFailure(TestException.class);
ts2.assertEmpty();
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class SerializedProcessorTest method onErrorOnErrorRace.
@Test
public void onErrorOnErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final FlowableProcessor<Integer> s = PublishProcessor.<Integer>create().toSerialized();
TestSubscriber<Integer> ts = s.test();
final TestException ex = new TestException();
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Runnable r1 = new Runnable() {
@Override
public void run() {
s.onError(ex);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
s.onError(ex);
}
};
TestHelper.race(r1, r2);
ts.assertFailure(TestException.class);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class SerializedProcessorTest method normal.
@Test
public void normal() {
FlowableProcessor<Integer> s = PublishProcessor.<Integer>create().toSerialized();
TestSubscriber<Integer> ts = s.test();
Flowable.range(1, 10).subscribe(s);
ts.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
assertFalse(s.hasSubscribers());
s.onNext(11);
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
s.onError(new TestException());
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
s.onComplete();
BooleanSubscription bs = new BooleanSubscription();
s.onSubscribe(bs);
assertTrue(bs.isCancelled());
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableBlockingTest method blockinsSubscribeCancelAsync.
@Test
public void blockinsSubscribeCancelAsync() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
final PublishProcessor<Integer> pp = PublishProcessor.create();
final Runnable r1 = new Runnable() {
@Override
public void run() {
ts.cancel();
}
};
final Runnable r2 = new Runnable() {
@Override
public void run() {
pp.onNext(1);
}
};
final AtomicInteger c = new AtomicInteger(2);
Schedulers.computation().scheduleDirect(new Runnable() {
@Override
public void run() {
c.decrementAndGet();
while (c.get() != 0 && !pp.hasSubscribers()) {
}
TestHelper.race(r1, r2);
}
});
c.decrementAndGet();
while (c.get() != 0) {
}
pp.blockingSubscribe(ts);
}
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableConcatMapSingleTest method cancelNoConcurrentClean.
@Test
public void cancelNoConcurrentClean() {
TestSubscriber<Integer> ts = new TestSubscriber<>();
ConcatMapSingleSubscriber<Integer, Integer> operator = new ConcatMapSingleSubscriber<>(ts, Functions.justFunction(Single.<Integer>never()), 16, ErrorMode.IMMEDIATE);
operator.onSubscribe(new BooleanSubscription());
operator.queue.offer(1);
operator.getAndIncrement();
ts.cancel();
assertFalse(operator.queue.isEmpty());
operator.addAndGet(-2);
operator.cancel();
assertTrue(operator.queue.isEmpty());
}
Aggregations