use of rx.exceptions.CompositeException in project azure-sdk-for-java by Azure.
the class LoadBalancerImpl method afterCreating.
@Override
protected void afterCreating() {
List<Exception> nicExceptions = new ArrayList<>();
// Update the NICs to point to the backend pool
for (Entry<String, String> nicInBackend : this.nicsInBackends.entrySet()) {
String nicId = nicInBackend.getKey();
String backendName = nicInBackend.getValue();
try {
NetworkInterface nic = this.manager().networkInterfaces().getById(nicId);
NicIPConfiguration nicIP = nic.primaryIPConfiguration();
nic.update().updateIPConfiguration(nicIP.name()).withExistingLoadBalancerBackend(this, backendName).parent().apply();
} catch (Exception e) {
nicExceptions.add(e);
}
}
if (!nicExceptions.isEmpty()) {
throw new CompositeException(nicExceptions);
}
this.nicsInBackends.clear();
this.refresh();
}
use of rx.exceptions.CompositeException in project retrofit by square.
the class ObservableThrowingSafeSubscriberTest method resultThrowingInOnErrorDeliveredToPlugin.
@Test
public void resultThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse());
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (throwable instanceof OnErrorFailedException) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
}
});
RecordingSubscriber<Result<String>> observer = subscriberRule.create();
final RuntimeException first = new RuntimeException();
final RuntimeException second = new RuntimeException();
service.result().subscribe(new ForwardingSubscriber<Result<String>>(observer) {
@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;
}
});
CompositeException composite = (CompositeException) pluginRef.get().getCause();
assertThat(composite.getExceptions()).containsExactly(first, second);
}
use of rx.exceptions.CompositeException in project retrofit by square.
the class ObservableThrowingSafeSubscriberTest method bodyThrowingInOnErrorDeliveredToPlugin.
@Test
public void bodyThrowingInOnErrorDeliveredToPlugin() {
server.enqueue(new MockResponse().setResponseCode(404));
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (throwable instanceof OnErrorFailedException) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
}
});
RecordingSubscriber<String> observer = subscriberRule.create();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
final RuntimeException e = new RuntimeException();
service.body().subscribe(new ForwardingSubscriber<String>(observer) {
@Override
public void onError(Throwable throwable) {
if (!errorRef.compareAndSet(null, throwable)) {
throw Exceptions.propagate(throwable);
}
throw e;
}
});
CompositeException composite = (CompositeException) pluginRef.get().getCause();
assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
use of rx.exceptions.CompositeException in project retrofit by square.
the class SingleThrowingTest 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> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
});
RecordingSubscriber<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;
}
});
CompositeException composite = (CompositeException) pluginRef.get();
assertThat(composite.getExceptions()).containsExactly(first, second);
}
use of rx.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> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
}
});
RecordingSubscriber<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;
}
});
CompositeException composite = (CompositeException) pluginRef.get();
assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
Aggregations