Search in sources :

Example 11 with Flowable

use of io.reactivex.Flowable in project spring-framework by spring-projects.

the class HttpEntityArgumentResolverTests method emptyBodyWithFlowable.

@Test
public void emptyBodyWithFlowable() throws Exception {
    ResolvableType type = httpEntityType(Flowable.class, String.class);
    HttpEntity<Flowable<String>> entity = resolveValueWithEmptyBody(type);
    StepVerifier.create(entity.getBody()).expectNextCount(0).expectComplete().verify();
}
Also used : ResolvableType(org.springframework.core.ResolvableType) Flowable(io.reactivex.Flowable) Test(org.junit.Test)

Example 12 with Flowable

use of io.reactivex.Flowable in project retrofit by square.

the class RxJava2CallAdapterFactoryTest method rawResponseTypeThrows.

@Test
public void rawResponseTypeThrows() {
    Type observableType = new TypeToken<Observable<Response>>() {
    }.getType();
    try {
        factory.get(observableType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Response must be parameterized as Response<Foo> or Response<? extends Foo>");
    }
    Type singleType = new TypeToken<Single<Response>>() {
    }.getType();
    try {
        factory.get(singleType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Response must be parameterized as Response<Foo> or Response<? extends Foo>");
    }
    Type maybeType = new TypeToken<Maybe<Response>>() {
    }.getType();
    try {
        factory.get(maybeType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Response must be parameterized as Response<Foo> or Response<? extends Foo>");
    }
    Type flowableType = new TypeToken<Flowable<Response>>() {
    }.getType();
    try {
        factory.get(flowableType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Response must be parameterized as Response<Foo> or Response<? extends Foo>");
    }
}
Also used : Type(java.lang.reflect.Type) Maybe(io.reactivex.Maybe) Single(io.reactivex.Single) Observable(io.reactivex.Observable) Flowable(io.reactivex.Flowable) Test(org.junit.Test)

Example 13 with Flowable

use of io.reactivex.Flowable in project retrofit by square.

the class RxJava2CallAdapterFactoryTest method rawResultTypeThrows.

@Test
public void rawResultTypeThrows() {
    Type observableType = new TypeToken<Observable<Result>>() {
    }.getType();
    try {
        factory.get(observableType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Result must be parameterized as Result<Foo> or Result<? extends Foo>");
    }
    Type singleType = new TypeToken<Single<Result>>() {
    }.getType();
    try {
        factory.get(singleType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Result must be parameterized as Result<Foo> or Result<? extends Foo>");
    }
    Type maybeType = new TypeToken<Maybe<Result>>() {
    }.getType();
    try {
        factory.get(maybeType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Result must be parameterized as Result<Foo> or Result<? extends Foo>");
    }
    Type flowableType = new TypeToken<Flowable<Result>>() {
    }.getType();
    try {
        factory.get(flowableType, NO_ANNOTATIONS, retrofit);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Result must be parameterized as Result<Foo> or Result<? extends Foo>");
    }
}
Also used : Type(java.lang.reflect.Type) Maybe(io.reactivex.Maybe) Single(io.reactivex.Single) Observable(io.reactivex.Observable) Flowable(io.reactivex.Flowable) Test(org.junit.Test)

Example 14 with Flowable

use of io.reactivex.Flowable in project retrofit by square.

the class RxJava2CallAdapterFactoryTest method responseTypes.

@Test
public void responseTypes() {
    Type oBodyClass = new TypeToken<Observable<String>>() {
    }.getType();
    assertThat(factory.get(oBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sBodyClass = new TypeToken<Single<String>>() {
    }.getType();
    assertThat(factory.get(sBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mBodyClass = new TypeToken<Maybe<String>>() {
    }.getType();
    assertThat(factory.get(sBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fBodyClass = new TypeToken<Flowable<String>>() {
    }.getType();
    assertThat(factory.get(sBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oBodyWildcard = new TypeToken<Observable<? extends String>>() {
    }.getType();
    assertThat(factory.get(oBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sBodyWildcard = new TypeToken<Single<? extends String>>() {
    }.getType();
    assertThat(factory.get(sBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mBodyWildcard = new TypeToken<Maybe<? extends String>>() {
    }.getType();
    assertThat(factory.get(sBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fBodyWildcard = new TypeToken<Flowable<? extends String>>() {
    }.getType();
    assertThat(factory.get(sBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oBodyGeneric = new TypeToken<Observable<List<String>>>() {
    }.getType();
    assertThat(factory.get(oBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
    Type sBodyGeneric = new TypeToken<Single<List<String>>>() {
    }.getType();
    assertThat(factory.get(sBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
    Type mBodyGeneric = new TypeToken<Maybe<List<String>>>() {
    }.getType();
    assertThat(factory.get(sBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
    Type fBodyGeneric = new TypeToken<Flowable<List<String>>>() {
    }.getType();
    assertThat(factory.get(sBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
    }.getType());
    Type oResponseClass = new TypeToken<Observable<Response<String>>>() {
    }.getType();
    assertThat(factory.get(oResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResponseClass = new TypeToken<Single<Response<String>>>() {
    }.getType();
    assertThat(factory.get(sResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mResponseClass = new TypeToken<Maybe<Response<String>>>() {
    }.getType();
    assertThat(factory.get(sResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fResponseClass = new TypeToken<Flowable<Response<String>>>() {
    }.getType();
    assertThat(factory.get(sResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oResponseWildcard = new TypeToken<Observable<Response<? extends String>>>() {
    }.getType();
    assertThat(factory.get(oResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResponseWildcard = new TypeToken<Single<Response<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mResponseWildcard = new TypeToken<Maybe<Response<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fResponseWildcard = new TypeToken<Flowable<Response<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oResultClass = new TypeToken<Observable<Result<String>>>() {
    }.getType();
    assertThat(factory.get(oResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResultClass = new TypeToken<Single<Result<String>>>() {
    }.getType();
    assertThat(factory.get(sResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mResultClass = new TypeToken<Maybe<Result<String>>>() {
    }.getType();
    assertThat(factory.get(sResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fResultClass = new TypeToken<Flowable<Result<String>>>() {
    }.getType();
    assertThat(factory.get(sResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type oResultWildcard = new TypeToken<Observable<Result<? extends String>>>() {
    }.getType();
    assertThat(factory.get(oResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type sResultWildcard = new TypeToken<Single<Result<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type mResultWildcard = new TypeToken<Maybe<Result<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
    Type fResultWildcard = new TypeToken<Flowable<Result<? extends String>>>() {
    }.getType();
    assertThat(factory.get(sResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
}
Also used : Maybe(io.reactivex.Maybe) Observable(io.reactivex.Observable) Type(java.lang.reflect.Type) Single(io.reactivex.Single) TypeToken(com.google.common.reflect.TypeToken) Flowable(io.reactivex.Flowable) Test(org.junit.Test)

Example 15 with Flowable

use of io.reactivex.Flowable in project Rocket.Chat.Android by RocketChat.

the class DDPClientImpl method connect.

public void connect(final TaskCompletionSource<DDPClientCallback.Connect> task, final String url, String session) {
    try {
        flowable = websocket.connect(url).autoConnect();
        CompositeDisposable subscriptions = new CompositeDisposable();
        subscriptions.add(flowable.filter(callback -> callback instanceof RxWebSocketCallback.Open).subscribe(callback -> {
            sendMessage("connect", json -> (TextUtils.isEmpty(session) ? json : json.put("session", session)).put("version", "pre2").put("support", new JSONArray().put("pre2").put("pre1")), task);
        }, err -> {
        }));
        subscriptions.add(flowable.filter(callback -> callback instanceof RxWebSocketCallback.Message).map(callback -> ((RxWebSocketCallback.Message) callback).responseBodyString).map(DDPClientImpl::toJson).timeout(7, TimeUnit.SECONDS).subscribe(response -> {
            String msg = extractMsg(response);
            if ("connected".equals(msg) && !response.isNull("session")) {
                task.trySetResult(new DDPClientCallback.Connect(client, response.optString("session")));
                subscriptions.dispose();
            } else if ("error".equals(msg) && "Already connected".equals(response.optString("reason"))) {
                task.trySetResult(new DDPClientCallback.Connect(client, null));
                subscriptions.dispose();
            } else if ("failed".equals(msg)) {
                task.trySetError(new DDPClientCallback.Connect.Failed(client, response.optString("version")));
                subscriptions.dispose();
            }
        }, err -> task.trySetError(new DDPClientCallback.Connect.Timeout(client))));
        addErrorCallback(subscriptions, task);
        subscribeBaseListeners();
    } catch (Exception e) {
        RCLog.e(e);
    }
}
Also used : RxWebSocketCallback(chat.rocket.android_ddp.rx.RxWebSocketCallback) TimeoutException(java.util.concurrent.TimeoutException) TextUtils(android.text.TextUtils) NonNull(android.support.annotation.NonNull) RCLog(chat.rocket.android.log.RCLog) TaskCompletionSource(bolts.TaskCompletionSource) TimeUnit(java.util.concurrent.TimeUnit) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) JSONException(org.json.JSONException) RxWebSocket(chat.rocket.android_ddp.rx.RxWebSocket) JSONObject(org.json.JSONObject) OkHttpClient(okhttp3.OkHttpClient) Flowable(io.reactivex.Flowable) Nullable(android.support.annotation.Nullable) Task(bolts.Task) JSONArray(org.json.JSONArray) JSONArray(org.json.JSONArray) RxWebSocketCallback(chat.rocket.android_ddp.rx.RxWebSocketCallback) TimeoutException(java.util.concurrent.TimeoutException) JSONException(org.json.JSONException) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Aggregations

Flowable (io.reactivex.Flowable)16 Test (org.junit.Test)7 Maybe (io.reactivex.Maybe)5 Single (io.reactivex.Single)5 Observable (io.reactivex.Observable)4 Type (java.lang.reflect.Type)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 Schedulers (io.reactivex.schedulers.Schedulers)3 Collections (java.util.Collections)3 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 Nullable (android.support.annotation.Nullable)2 Scheduler (io.reactivex.Scheduler)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Queue (java.util.Queue)2 Singleton (javax.inject.Singleton)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebTarget (javax.ws.rs.client.WebTarget)2