use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class SerializedSubscriberTest method completeReentry.
@Test
public void completeReentry() {
final AtomicReference<Subscriber<Integer>> serial = new AtomicReference<>();
TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer v) {
serial.get().onComplete();
serial.get().onComplete();
super.onNext(v);
}
};
SerializedSubscriber<Integer> sobs = new SerializedSubscriber<>(ts);
sobs.onSubscribe(new BooleanSubscription());
serial.set(sobs);
sobs.onNext(1);
ts.assertValue(1);
ts.assertComplete();
ts.assertNoErrors();
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableSubscriberTest method requestToFlowable.
@Test
public void requestToFlowable() {
TestSubscriber<Integer> ts = new TestSubscriber<>(3L);
final AtomicLong requested = new AtomicLong();
Flowable.<Integer>unsafeCreate(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
s.onSubscribe(new Subscription() {
@Override
public void request(long n) {
requested.set(n);
}
@Override
public void cancel() {
}
});
}
}).subscribe(ts);
assertEquals(3, requested.get());
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableSubscriberTest method onNextCrashes.
@Test
public void onNextCrashes() {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
ts.onSubscribe(new BooleanSubscription());
ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
ts.onError(e);
}
}, new Action() {
@Override
public void run() throws Exception {
ts.onComplete();
}
});
BooleanSubscription b = new BooleanSubscription();
s.onSubscribe(b);
s.onNext(1);
assertTrue(b.isCancelled());
ts.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableSubscriberTest method requestFromChainedOperator.
@Test
public void requestFromChainedOperator() throws Throwable {
TestSubscriber<String> s = new TestSubscriber<>(10L);
FlowableOperator<String, String> o = new FlowableOperator<String, String>() {
@Override
public Subscriber<? super String> apply(final Subscriber<? super String> s1) {
return new FlowableSubscriber<String>() {
@Override
public void onSubscribe(Subscription a) {
s1.onSubscribe(a);
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(String t) {
}
};
}
};
Subscriber<? super String> ns = o.apply(s);
final AtomicLong r = new AtomicLong();
// set set the producer at the top of the chain (ns) and it should flow through the operator to the (s) subscriber
// and then it should request up with the value set on the final Subscriber (s)
ns.onSubscribe(new Subscription() {
@Override
public void request(long n) {
r.set(n);
}
@Override
public void cancel() {
}
});
assertEquals(10, r.get());
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableSubscriberTest method suppressAfterCompleteEvents.
@Test
public void suppressAfterCompleteEvents() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
ts.onSubscribe(new BooleanSubscription());
ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
ts.onNext(v);
return true;
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
ts.onError(e);
}
}, new Action() {
@Override
public void run() throws Exception {
ts.onComplete();
}
});
s.onComplete();
s.onNext(1);
s.onError(new TestException());
s.onComplete();
ts.assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
Aggregations