use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class QueueDrainHelperTest method postCompleteEmpty.
@Test
public void postCompleteEmpty() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
AtomicLong state = new AtomicLong();
BooleanSupplier isCancelled = new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return false;
}
};
ts.onSubscribe(new BooleanSubscription());
QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
ts.assertResult();
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class ParallelJoinTest method overflowSlowpath.
@Test
public void overflowSlowpath() {
@SuppressWarnings("unchecked") final Subscriber<? super Integer>[] subs = new Subscriber[1];
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1) {
@Override
public void onNext(Integer t) {
super.onNext(t);
subs[0].onNext(2);
subs[0].onNext(3);
}
};
new ParallelFlowable<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer>[] subscribers) {
subs[0] = subscribers[0];
subscribers[0].onSubscribe(new BooleanSubscription());
subscribers[0].onNext(1);
}
@Override
public int parallelism() {
return 1;
}
}.sequential(1).subscribe(ts);
ts.assertFailure(MissingBackpressureException.class, 1);
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class ParallelJoinTest method overflowSlowpathDelayError.
@Test
public void overflowSlowpathDelayError() {
@SuppressWarnings("unchecked") final Subscriber<? super Integer>[] subs = new Subscriber[1];
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1) {
@Override
public void onNext(Integer t) {
super.onNext(t);
if (t == 1) {
subs[0].onNext(2);
subs[0].onNext(3);
}
}
};
new ParallelFlowable<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer>[] subscribers) {
subs[0] = subscribers[0];
subscribers[0].onSubscribe(new BooleanSubscription());
subscribers[0].onNext(1);
}
@Override
public int parallelism() {
return 1;
}
}.sequentialDelayError(1).subscribe(ts);
ts.request(1);
ts.assertFailure(MissingBackpressureException.class, 1, 2);
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class AsyncProcessorTest method onErrorCrossCancel.
@Test
public void onErrorCrossCancel() {
AsyncProcessor<Object> p = AsyncProcessor.create();
final TestSubscriber<Object> ts2 = new TestSubscriber<Object>();
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.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class TestObserverTest method testGetEvents.
@Test
public void testGetEvents() {
TestSubscriber<Integer> to = new TestSubscriber<Integer>();
to.onSubscribe(EmptySubscription.INSTANCE);
to.onNext(1);
to.onNext(2);
assertEquals(Arrays.<Object>asList(Arrays.asList(1, 2), Collections.emptyList(), Collections.emptyList()), to.getEvents());
to.onComplete();
assertEquals(Arrays.<Object>asList(Arrays.asList(1, 2), Collections.emptyList(), Collections.singletonList(Notification.createOnComplete())), to.getEvents());
TestException ex = new TestException();
TestSubscriber<Integer> to2 = new TestSubscriber<Integer>();
to2.onSubscribe(EmptySubscription.INSTANCE);
to2.onNext(1);
to2.onNext(2);
assertEquals(Arrays.<Object>asList(Arrays.asList(1, 2), Collections.emptyList(), Collections.emptyList()), to2.getEvents());
to2.onError(ex);
assertEquals(Arrays.<Object>asList(Arrays.asList(1, 2), Collections.singletonList(ex), Collections.emptyList()), to2.getEvents());
}
Aggregations