Search in sources :

Example 16 with CompositeException

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();
}
Also used : CompositeException(rx.exceptions.CompositeException) ArrayList(java.util.ArrayList) NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) NicIPConfiguration(com.microsoft.azure.management.network.NicIPConfiguration) CompositeException(rx.exceptions.CompositeException)

Example 17 with CompositeException

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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) CompositeException(rx.exceptions.CompositeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) OnErrorFailedException(rx.exceptions.OnErrorFailedException) Test(org.junit.Test)

Example 18 with CompositeException

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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) CompositeException(rx.exceptions.CompositeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) OnErrorFailedException(rx.exceptions.OnErrorFailedException) Test(org.junit.Test)

Example 19 with CompositeException

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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) CompositeException(rx.exceptions.CompositeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with CompositeException

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);
}
Also used : Response(retrofit2.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) RxJavaErrorHandler(rx.plugins.RxJavaErrorHandler) CompositeException(rx.exceptions.CompositeException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

CompositeException (rx.exceptions.CompositeException)23 Test (org.junit.Test)16 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 MockResponse (okhttp3.mockwebserver.MockResponse)13 RxJavaErrorHandler (rx.plugins.RxJavaErrorHandler)13 OnErrorFailedException (rx.exceptions.OnErrorFailedException)7 ArrayList (java.util.ArrayList)6 Observable (rx.Observable)4 Func1 (rx.functions.Func1)4 Response (retrofit2.Response)3 TestSubscriber (rx.observers.TestSubscriber)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 GenericDebuggerRunner (com.intellij.debugger.impl.GenericDebuggerRunner)1 GenericDebuggerRunnerSettings (com.intellij.debugger.impl.GenericDebuggerRunnerSettings)1 ExecutionException (com.intellij.execution.ExecutionException)1 Executor (com.intellij.execution.Executor)1 ConfigurationInfoProvider (com.intellij.execution.configurations.ConfigurationInfoProvider)1 RemoteConnection (com.intellij.execution.configurations.RemoteConnection)1 RunProfile (com.intellij.execution.configurations.RunProfile)1 RunProfileState (com.intellij.execution.configurations.RunProfileState)1