use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowablePublishFunctionTest method oneStartOnly.
@Test
public void oneStartOnly() {
final AtomicInteger startCount = new AtomicInteger();
TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onStart() {
startCount.incrementAndGet();
}
};
PublishProcessor<Integer> pp = PublishProcessor.create();
pp.publish(f -> f.take(1)).subscribe(ts);
Assert.assertEquals(1, startCount.get());
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableOnErrorResumeNextViaFlowableTest method normalBackpressure.
@Test
public void normalBackpressure() {
TestSubscriber<Integer> ts = TestSubscriber.create(0);
PublishProcessor<Integer> pp = PublishProcessor.create();
pp.onErrorResumeWith(Flowable.range(3, 2)).subscribe(ts);
ts.request(2);
pp.onNext(1);
pp.onNext(2);
pp.onError(new TestException("Forced failure"));
ts.assertValues(1, 2);
ts.assertNoErrors();
ts.assertNotComplete();
ts.request(2);
ts.assertValues(1, 2, 3, 4);
ts.assertNoErrors();
ts.assertComplete();
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableOnErrorReturnTest method normalBackpressure.
@Test
public void normalBackpressure() {
TestSubscriber<Integer> ts = TestSubscriber.create(0);
PublishProcessor<Integer> pp = PublishProcessor.create();
pp.onErrorReturn(new Function<Throwable, Integer>() {
@Override
public Integer apply(Throwable e) {
return 3;
}
}).subscribe(ts);
ts.request(2);
pp.onNext(1);
pp.onNext(2);
pp.onError(new TestException("Forced failure"));
ts.assertValues(1, 2);
ts.assertNoErrors();
ts.assertNotComplete();
ts.request(2);
ts.assertValues(1, 2, 3);
ts.assertNoErrors();
ts.assertComplete();
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowablePublishMulticastTest method dontDropItemsWhenNoReadyConsumers.
@Test
public void dontDropItemsWhenNoReadyConsumers() {
final MulticastProcessor<Integer> mp = new MulticastProcessor<>(128, true);
mp.onSubscribe(new BooleanSubscription());
mp.onNext(1);
TestSubscriber<Integer> ts = new TestSubscriber<>();
final MulticastSubscription<Integer> ms1 = new MulticastSubscription<>(ts, mp);
ts.onSubscribe(ms1);
assertTrue(mp.add(ms1));
ms1.set(Long.MIN_VALUE);
mp.drain();
assertFalse(mp.queue.isEmpty());
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableRetryTest method repeatFloodNoSubscriptionError.
@Test
public void repeatFloodNoSubscriptionError() {
List<Throwable> errors = TestHelper.trackPluginErrors();
final TestException error = new TestException();
try {
final PublishProcessor<Integer> source = PublishProcessor.create();
final PublishProcessor<Integer> signaller = PublishProcessor.create();
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
TestSubscriber<Integer> ts = source.take(1).map(new Function<Integer, Integer>() {
@Override
public Integer apply(Integer v) throws Exception {
throw error;
}
}).retryWhen(new Function<Flowable<Throwable>, Flowable<Integer>>() {
@Override
public Flowable<Integer> apply(Flowable<Throwable> v) throws Exception {
return signaller;
}
}).test();
Runnable r1 = new Runnable() {
@Override
public void run() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
source.onNext(1);
}
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
signaller.offer(1);
}
}
};
TestHelper.race(r1, r2);
ts.cancel();
}
if (!errors.isEmpty()) {
for (Throwable e : errors) {
e.printStackTrace();
}
fail(errors + "");
}
} finally {
RxJavaPlugins.reset();
}
}
Aggregations