Search in sources :

Example 36 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project retrofit by square.

the class RxJava3CallAdapterFactory method get.

@Override
@Nullable
public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
    Class<?> rawType = getRawType(returnType);
    if (rawType == Completable.class) {
        // can only be created with a single configuration.
        return new RxJava3CallAdapter(Void.class, scheduler, isAsync, false, true, false, false, false, true);
    }
    boolean isFlowable = rawType == Flowable.class;
    boolean isSingle = rawType == Single.class;
    boolean isMaybe = rawType == Maybe.class;
    if (rawType != Observable.class && !isFlowable && !isSingle && !isMaybe) {
        return null;
    }
    boolean isResult = false;
    boolean isBody = false;
    Type responseType;
    if (!(returnType instanceof ParameterizedType)) {
        String name = isFlowable ? "Flowable" : isSingle ? "Single" : isMaybe ? "Maybe" : "Observable";
        throw new IllegalStateException(name + " return type must be parameterized" + " as " + name + "<Foo> or " + name + "<? extends Foo>");
    }
    Type observableType = getParameterUpperBound(0, (ParameterizedType) returnType);
    Class<?> rawObservableType = getRawType(observableType);
    if (rawObservableType == Response.class) {
        if (!(observableType instanceof ParameterizedType)) {
            throw new IllegalStateException("Response must be parameterized" + " as Response<Foo> or Response<? extends Foo>");
        }
        responseType = getParameterUpperBound(0, (ParameterizedType) observableType);
    } else if (rawObservableType == Result.class) {
        if (!(observableType instanceof ParameterizedType)) {
            throw new IllegalStateException("Result must be parameterized" + " as Result<Foo> or Result<? extends Foo>");
        }
        responseType = getParameterUpperBound(0, (ParameterizedType) observableType);
        isResult = true;
    } else {
        responseType = observableType;
        isBody = true;
    }
    return new RxJava3CallAdapter(responseType, scheduler, isAsync, isResult, isBody, isFlowable, isSingle, isMaybe, false);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Observable(io.reactivex.rxjava3.core.Observable) Nullable(javax.annotation.Nullable)

Example 37 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project smallrye-mutiny by smallrye.

the class MultiConvertFromTest method testCreatingFromAMaybeNeverEmitting.

@Test
public void testCreatingFromAMaybeNeverEmitting() {
    AtomicBoolean cancelled = new AtomicBoolean();
    Multi<Integer> multi = Multi.createFrom().converter(MultiRx3Converters.fromMaybe(), Maybe.<Integer>never().doOnDispose(() -> cancelled.set(true)));
    assertThat(multi).isNotNull();
    multi.subscribe().with(i -> {
    }).cancel();
    assertThat(cancelled).isTrue();
}
Also used : Test(org.junit.jupiter.api.Test) AssertSubscriber(io.smallrye.mutiny.helpers.test.AssertSubscriber) Maybe(io.reactivex.rxjava3.core.Maybe) Single(io.reactivex.rxjava3.core.Single) Flowable(io.reactivex.rxjava3.core.Flowable) Observable(io.reactivex.rxjava3.core.Observable) MultiRx3Converters(io.smallrye.mutiny.converters.multi.MultiRx3Converters) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) Completable(io.reactivex.rxjava3.core.Completable) Multi(io.smallrye.mutiny.Multi) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.jupiter.api.Test)

Example 38 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project smallrye-mutiny by smallrye.

the class FromMaybe method from.

@Override
public Uni<T> from(Maybe<T> instance) {
    return Uni.createFrom().emitter(sink -> {
        Disposable disposable = instance.subscribe(sink::complete, sink::fail, () -> sink.complete(null));
        sink.onTermination(() -> {
            if (!disposable.isDisposed()) {
                disposable.dispose();
            }
        });
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Example 39 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project cxf by apache.

the class JAXRSRxJava3MaybeTest method testGetHelloWorldEmpty.

@Test
public void testGetHelloWorldEmpty() throws Exception {
    String address = "http://localhost:" + PORT + "/rx3/maybe/empty";
    final Flowable<Response> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get();
    final TestSubscriber<Response> subscriber = new TestSubscriber<>();
    obs.subscribe(subscriber);
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertValue(r -> !r.hasEntity()).assertComplete();
}
Also used : Response(javax.ws.rs.core.Response) Flowable(io.reactivex.rxjava3.core.Flowable) BeforeClass(org.junit.BeforeClass) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) TimeUnit(java.util.concurrent.TimeUnit) ClientBuilder(javax.ws.rs.client.ClientBuilder) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) MediaType(javax.ws.rs.core.MediaType) Response(javax.ws.rs.core.Response) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 40 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project cxf by apache.

the class JAXRSRxJava3MaybeTest method testGetHelloWorldJson.

@Test
public void testGetHelloWorldJson() throws Exception {
    String address = "http://localhost:" + PORT + "/rx3/maybe/textJson";
    final Flowable<HelloWorldBean> obs = ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new FlowableRxInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(FlowableRxInvoker.class).get(HelloWorldBean.class);
    final TestSubscriber<HelloWorldBean> subscriber = new TestSubscriber<>();
    obs.subscribe(subscriber);
    subscriber.await(3, TimeUnit.SECONDS);
    subscriber.assertValue(r -> "Hello".equals(r.getGreeting()) && "World".equals(r.getAudience())).assertComplete();
}
Also used : Flowable(io.reactivex.rxjava3.core.Flowable) BeforeClass(org.junit.BeforeClass) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) Assert.assertTrue(org.junit.Assert.assertTrue) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) TimeUnit(java.util.concurrent.TimeUnit) ClientBuilder(javax.ws.rs.client.ClientBuilder) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) MediaType(javax.ws.rs.core.MediaType) Response(javax.ws.rs.core.Response) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) FlowableRxInvokerProvider(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) FlowableRxInvoker(org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)55 TestException (io.reactivex.rxjava3.exceptions.TestException)38 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)13 Maybe (io.reactivex.rxjava3.core.Maybe)12 InOrder (org.mockito.InOrder)12 Flowable (io.reactivex.rxjava3.core.Flowable)10 Observable (io.reactivex.rxjava3.core.Observable)10 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 Single (io.reactivex.rxjava3.core.Single)8 IOException (java.io.IOException)8 Predicate (io.reactivex.rxjava3.functions.Predicate)6 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 Type (java.lang.reflect.Type)6 Test (org.junit.jupiter.api.Test)6 TestObserver (io.reactivex.rxjava3.observers.TestObserver)5 Completable (io.reactivex.rxjava3.core.Completable)4 Action (io.reactivex.rxjava3.functions.Action)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 FlowableRxInvoker (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker)4 FlowableRxInvokerProvider (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider)4