use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class TestObserverTest method testTerminalOneKind.
@Test
public void testTerminalOneKind() {
TestSubscriber<Integer> to = new TestSubscriber<Integer>();
to.onError(new TestException());
to.onComplete();
try {
to.assertTerminated();
} catch (AssertionError ex) {
// this is expected
return;
}
fail("Failed to report multiple kinds of events!");
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class ReplayProcessorTest method reentrantDrainBackpressured.
@Test
public void reentrantDrainBackpressured() {
TestScheduler scheduler = new TestScheduler();
final ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(1L) {
@Override
public void onNext(Integer t) {
if (t == 1) {
rp.onNext(2);
}
super.onNext(t);
}
};
rp.subscribe(ts);
rp.onNext(1);
rp.onComplete();
ts.request(1);
ts.assertResult(1, 2);
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class TrampolineSchedulerTest method testTrampolineWorkerHandlesConcurrentScheduling.
/**
* 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 testTrampolineWorkerHandlesConcurrentScheduling() {
final Worker trampolineWorker = Schedulers.trampoline().createWorker();
final Subscriber<Object> observer = TestHelper.mockSubscriber();
final TestSubscriber<Disposable> ts = new TestSubscriber<Disposable>(observer);
// 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.awaitTerminalEvent();
ts.assertNoErrors();
}
use of io.reactivex.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<Integer>();
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.subscribers.TestSubscriber in project rxjava2-jdbc by davidmoten.
the class PoolTest method testConnectionPoolRecylesFirst.
@Test
public void testConnectionPoolRecylesFirst() {
Database db = DatabaseCreator.create(2);
TestSubscriber<Connection> ts = //
db.connections().doOnNext(//
System.out::println).doOnNext(c -> {
c.close();
}).test(//
4);
//
ts.assertValueCount(4).assertNotTerminated();
List<Object> list = ts.getEvents().get(0);
// all 4 connections released were the same
assertTrue(list.get(0) == list.get(1));
assertTrue(list.get(0) == list.get(2));
assertTrue(list.get(0) == list.get(3));
}
Aggregations