Skip to content

Commit

Permalink
Makes sure observable assembly hooks are called
Browse files Browse the repository at this point in the history
This allows things like error and trace tracking to work naturally.

Fixes #2716
  • Loading branch information
Adrian Cole committed Mar 28, 2018
1 parent 329a9fd commit 4faf9e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.reactivex.BackpressureStrategy;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.plugins.RxJavaPlugins;
import java.lang.reflect.Type;
import javax.annotation.Nullable;
import retrofit2.Call;
Expand Down Expand Up @@ -83,6 +84,6 @@ final class RxJava2CallAdapter<R> implements CallAdapter<R, Object> {
if (isCompletable) {
return observable.ignoreElements();
}
return observable;
return RxJavaPlugins.onAssembly(observable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package retrofit2.adapter.rxjava2;

import io.reactivex.Observable;
import io.reactivex.functions.Function;
import io.reactivex.plugins.RxJavaPlugins;
import java.io.IOException;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
Expand Down Expand Up @@ -133,4 +135,18 @@ interface Service {
assertThat(result.error()).isInstanceOf(IOException.class);
observer.assertComplete();
}

@Test public void observableAssembly() {
try {
final Observable<String> justMe = Observable.just("me");
RxJavaPlugins.setOnObservableAssembly(new Function<Observable, Observable>() {
@Override public Observable apply(Observable f) {
return justMe;
}
});
assertThat(service.body()).isEqualTo(justMe);
} finally {
RxJavaPlugins.reset();
}
}
}

0 comments on commit 4faf9e2

Please sign in to comment.