use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableRetryTest method retryWhenTrampolineScheduler.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void retryWhenTrampolineScheduler() {
TestSubscriber<Integer> ts = TestSubscriber.create();
Flowable.just(1).concatWith(Flowable.<Integer>error(new TestException())).subscribeOn(Schedulers.trampoline()).retryWhen((Function) new Function<Flowable, Flowable>() {
@Override
public Flowable apply(Flowable f) {
return f.take(2);
}
}).subscribe(ts);
ts.assertValues(1, 1);
ts.assertNoErrors();
ts.assertComplete();
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableSkipTest method backpressureMultipleSmallAsyncRequests.
@Test
public void backpressureMultipleSmallAsyncRequests() throws InterruptedException {
final AtomicLong requests = new AtomicLong(0);
TestSubscriber<Long> ts = new TestSubscriber<>(0L);
Flowable.interval(100, TimeUnit.MILLISECONDS).doOnRequest(new LongConsumer() {
@Override
public void accept(long n) {
requests.addAndGet(n);
}
}).skip(4).subscribe(ts);
Thread.sleep(100);
ts.request(1);
ts.request(1);
Thread.sleep(100);
ts.cancel();
ts.assertNoErrors();
assertEquals(6, requests.get());
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableMergeWithCompletableTest method normalBackpressured.
@Test
public void normalBackpressured() {
final TestSubscriber<Integer> ts = new TestSubscriber<>(0L);
Flowable.range(1, 5).mergeWith(Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
ts.onNext(100);
}
})).subscribe(ts);
ts.assertValue(100).requestMore(2).assertValues(100, 1, 2).requestMore(2).assertValues(100, 1, 2, 3, 4).requestMore(1).assertResult(100, 1, 2, 3, 4, 5);
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableFilterTest method withBackpressure2.
/**
* Make sure we are adjusting subscriber.request() for filtered items.
* @throws InterruptedException if the test is interrupted
*/
@Test
public void withBackpressure2() throws InterruptedException {
Flowable<Integer> w = Flowable.range(1, Flowable.bufferSize() * 2);
Flowable<Integer> f = w.filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t1) {
return t1 > 100;
}
});
final CountDownLatch latch = new CountDownLatch(1);
final TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onComplete() {
System.out.println("onComplete");
latch.countDown();
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
latch.countDown();
}
@Override
public void onNext(Integer t) {
System.out.println("Received: " + t);
// request more each time we receive
request(1);
}
};
// this means it will only request 1 item and expect to receive more
ts.request(1);
f.subscribe(ts);
// this will wait forever unless OperatorTake handles the request(n) on filtered items
latch.await();
}
use of io.reactivex.rxjava3.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class FlowableFilterTest method withBackpressure.
/**
* Make sure we are adjusting subscriber.request() for filtered items.
* @throws InterruptedException if the test is interrupted
* @throws InterruptedException if the test is interrupted
*/
@Test
public void withBackpressure() throws InterruptedException {
Flowable<String> w = Flowable.just("one", "two", "three");
Flowable<String> f = w.filter(new Predicate<String>() {
@Override
public boolean test(String t1) {
return t1.equals("three");
}
});
final CountDownLatch latch = new CountDownLatch(1);
TestSubscriber<String> ts = new TestSubscriber<String>() {
@Override
public void onComplete() {
System.out.println("onComplete");
latch.countDown();
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
latch.countDown();
}
@Override
public void onNext(String t) {
System.out.println("Received: " + t);
// request more each time we receive
request(1);
}
};
// this means it will only request "one" and "two", expecting to receive them before requesting more
ts.request(2);
f.subscribe(ts);
// this will wait forever unless OperatorTake handles the request(n) on filtered items
latch.await();
}
Aggregations