use of io.reactivex.exceptions.CompositeException in project retrofit by square.
the class CompletableThrowingTest method bodyThrowingInOnErrorDeliveredToPlugin.
@Test
public void bodyThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse().setResponseCode(404));
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
});
RecordingCompletableObserver observer = observerRule.create();
final RuntimeException e = new RuntimeException();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
service.completable().subscribe(new ForwardingCompletableObserver(observer) {
@Override
public void onError(Throwable throwable) {
errorRef.set(throwable);
throw e;
}
});
// noinspection ThrowableResultOfMethodCallIgnored
CompositeException composite = (CompositeException) pluginRef.get();
assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
use of io.reactivex.exceptions.CompositeException in project retrofit by square.
the class MaybeThrowingTest method responseThrowingInOnErrorDeliveredToPlugin.
@Test
public void responseThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AFTER_REQUEST));
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (!throwableRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable);
}
}
});
RecordingMaybeObserver<Response<String>> observer = subscriberRule.create();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
final RuntimeException e = new RuntimeException();
service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
@Override
public void onError(Throwable throwable) {
if (!errorRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable);
}
throw e;
}
});
// noinspection ThrowableResultOfMethodCallIgnored
CompositeException composite = (CompositeException) throwableRef.get();
assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
use of io.reactivex.exceptions.CompositeException in project retrofit by square.
the class MaybeThrowingTest method resultThrowingInOnErrorDeliveredToPlugin.
@Ignore("Single's contract is onNext|onError so we have no way of triggering this case")
@Test
public void resultThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse());
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (!throwableRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable);
}
}
});
RecordingMaybeObserver<Result<String>> observer = subscriberRule.create();
final RuntimeException first = new RuntimeException();
final RuntimeException second = new RuntimeException();
service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
@Override
public void onSuccess(Result<String> value) {
// The only way to trigger onError for Result is if onSuccess throws.
throw first;
}
@Override
public void onError(Throwable throwable) {
throw second;
}
});
// noinspection ThrowableResultOfMethodCallIgnored
CompositeException composite = (CompositeException) throwableRef.get();
assertThat(composite.getExceptions()).containsExactly(first, second);
}
use of io.reactivex.exceptions.CompositeException in project retrofit by square.
the class FlowableThrowingTest method resultThrowingInOnErrorDeliveredToPlugin.
@Test
public void resultThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse());
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (!throwableRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable);
}
}
});
RecordingSubscriber<Result<String>> subscriber = subscriberRule.create();
final RuntimeException first = new RuntimeException();
final RuntimeException second = new RuntimeException();
service.result().safeSubscribe(new ForwardingSubscriber<Result<String>>(subscriber) {
@Override
public void onNext(Result<String> value) {
// The only way to trigger onError for a result is if onNext throws.
throw first;
}
@Override
public void onError(Throwable throwable) {
throw second;
}
});
// noinspection ThrowableResultOfMethodCallIgnored
CompositeException composite = (CompositeException) throwableRef.get();
assertThat(composite.getExceptions()).containsExactly(first, second);
}
use of io.reactivex.exceptions.CompositeException in project retrofit by square.
the class SingleThrowingTest method responseThrowingInOnErrorDeliveredToPlugin.
@Test
public void responseThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AFTER_REQUEST));
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (!throwableRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable);
}
}
});
RecordingSingleObserver<Response<String>> observer = subscriberRule.create();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
final RuntimeException e = new RuntimeException();
service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
@Override
public void onError(Throwable throwable) {
if (!errorRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable);
}
throw e;
}
});
// noinspection ThrowableResultOfMethodCallIgnored
CompositeException composite = (CompositeException) throwableRef.get();
assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
Aggregations