Search in sources :

Example 36 with Flowable

use of io.reactivex.rxjava3.core.Flowable 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());
}
Also used : ForEachWhileSubscriber(io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 37 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class XFlatMapTest method flowableFlowable.

@Test
public void flowableFlowable() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestSubscriber<Integer> ts = Flowable.just(1).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Publisher<Integer>>() {

            @Override
            public Publisher<Integer> apply(Integer v) throws Exception {
                sleep();
                return Flowable.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(ts);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 38 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class XFlatMapTest method singlePublisher.

@Test
public void singlePublisher() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestSubscriber<Integer> ts = Single.just(1).subscribeOn(Schedulers.io()).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

            @Override
            public Publisher<Integer> apply(Integer v) throws Exception {
                sleep();
                return Flowable.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(ts);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 39 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class XFlatMapTest method maybePublisher.

@Test
public void maybePublisher() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestSubscriber<Integer> ts = Maybe.just(1).subscribeOn(Schedulers.io()).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

            @Override
            public Publisher<Integer> apply(Integer v) throws Exception {
                sleep();
                return Flowable.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(ts);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 40 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class FlowableTests method cacheWithCapacity.

@Test
public void cacheWithCapacity() throws InterruptedException {
    final AtomicInteger counter = new AtomicInteger();
    Flowable<String> f = Flowable.<String>unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(final Subscriber<? super String> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            new Thread(new Runnable() {

                @Override
                public void run() {
                    counter.incrementAndGet();
                    subscriber.onNext("one");
                    subscriber.onComplete();
                }
            }).start();
        }
    }).cacheWithInitialCapacity(1);
    // we then expect the following 2 subscriptions to get that same value
    final CountDownLatch latch = new CountDownLatch(2);
    // subscribe once
    f.subscribe(new Consumer<String>() {

        @Override
        public void accept(String v) {
            assertEquals("one", v);
            latch.countDown();
        }
    });
    // subscribe again
    f.subscribe(new Consumer<String>() {

        @Override
        public void accept(String v) {
            assertEquals("one", v);
            latch.countDown();
        }
    });
    if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
        fail("subscriptions did not receive values");
    }
    assertEquals(1, counter.get());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Aggregations

Test (org.junit.Test)177 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)121 TestException (io.reactivex.rxjava3.exceptions.TestException)95 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)67 InOrder (org.mockito.InOrder)41 IOException (java.io.IOException)27 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)22 Disposable (io.reactivex.rxjava3.disposables.Disposable)21 Flowable (io.reactivex.rxjava3.core.Flowable)19 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 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