Search in sources :

Example 26 with TestSubscriber

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();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) GroupedFlowable(io.reactivex.rxjava3.flowables.GroupedFlowable) Test(org.junit.Test)

Example 27 with TestSubscriber

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());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 28 with TestSubscriber

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);
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 29 with TestSubscriber

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();
}
Also used : TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 30 with TestSubscriber

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();
}
Also used : TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

Test (org.junit.Test)169 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)116 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)106 TestException (io.reactivex.rxjava3.exceptions.TestException)56 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)27 TimeUnit (java.util.concurrent.TimeUnit)19 FlowableRxInvokerProvider (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider)18 FlowableRxInvoker (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker)17 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)15 IOException (java.io.IOException)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Flowable (io.reactivex.rxjava3.core.Flowable)13 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)13 ClientBuilder (javax.ws.rs.client.ClientBuilder)13 MediaType (javax.ws.rs.core.MediaType)13 AbstractResourceInfo (org.apache.cxf.jaxrs.model.AbstractResourceInfo)13 AbstractBusClientServerTestBase (org.apache.cxf.testutil.common.AbstractBusClientServerTestBase)13 Assert.assertTrue (org.junit.Assert.assertTrue)13 BeforeClass (org.junit.BeforeClass)13 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)12