Search in sources :

Example 6 with ConnectionException

use of org.mule.runtime.api.connection.ConnectionException in project mule by mulesoft.

the class ExtensionMessageSourceTestCase method failOnExceptionWithConnectionExceptionAndGetsReconnected.

@Test
public void failOnExceptionWithConnectionExceptionAndGetsReconnected() throws Exception {
    messageSource.initialise();
    messageSource.start();
    messageSource.onException(new ConnectionException(ERROR_MESSAGE));
    verify(source, times(2)).onStart(sourceCallback);
    verify(source, times(1)).onStop();
}
Also used : ConnectionException(org.mule.runtime.api.connection.ConnectionException) Test(org.junit.Test)

Example 7 with ConnectionException

use of org.mule.runtime.api.connection.ConnectionException in project mule by mulesoft.

the class LifecycleAwareConfigurationInstanceAsyncRetryTestCase method testConnectivityFailsUponStart.

@Override
@Test
public void testConnectivityFailsUponStart() throws Exception {
    if (connectionProvider.isPresent()) {
        Exception connectionException = new ConnectionException("Oops!");
        when(connectionManager.testConnectivity(interceptable)).thenReturn(failure(connectionException.getMessage(), connectionException));
        interceptable.initialise();
        interceptable.start();
        new PollingProber().check(new JUnitLambdaProbe(() -> {
            verify(connectionManager, times(RECONNECTION_MAX_ATTEMPTS + 1)).testConnectivity(interceptable);
            return true;
        }));
    }
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) Test(org.junit.Test)

Example 8 with ConnectionException

use of org.mule.runtime.api.connection.ConnectionException in project mule by mulesoft.

the class ConnectionInterceptorTestCase method onConnectionException.

@Test
public void onConnectionException() throws Exception {
    interceptor.before(operationContext);
    interceptor.onError(operationContext, new ConnectionException("Bleh"));
    interceptor.after(operationContext, null);
    verify(connectionHandler).invalidate();
}
Also used : ConnectionException(org.mule.runtime.api.connection.ConnectionException) Test(org.junit.Test)

Example 9 with ConnectionException

use of org.mule.runtime.api.connection.ConnectionException in project mule by mulesoft.

the class ReconnectableHeisenbergSource method reconnect.

@Override
public void reconnect(ConnectionException exception, ReconnectionCallback reconnectionCallback) {
    if (reconnectable) {
        succesfulReconnections++;
        reconnectionCallback.success();
    } else {
        failedReconnections++;
        reconnectionCallback.failed(new ConnectionException("Boss said no", exception));
    }
}
Also used : ConnectionException(org.mule.runtime.api.connection.ConnectionException)

Example 10 with ConnectionException

use of org.mule.runtime.api.connection.ConnectionException in project mule by mulesoft.

the class ReconectionSource method onStart.

@Override
public void onStart(SourceCallback<ReconnectableConnection, Void> sourceCallback) throws MuleException {
    ReconnectableConnection connection;
    try {
        connection = connectionProvider.connect();
        scheduler = schedulerService.ioScheduler();
        scheduler.execute(() -> {
            boolean shouldFinish = false;
            while (!shouldFinish) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    shouldFinish = true;
                }
                if (ReconnectableConnectionProvider.fail) {
                    sourceCallback.onConnectionException(new ConnectionException(new RuntimeException(), connection));
                    shouldFinish = true;
                } else {
                    sourceCallback.handle(Result.<ReconnectableConnection, Void>builder().output(connection).build());
                }
            }
        });
    } catch (Exception e) {
        sourceCallback.onConnectionException(new ConnectionException(e));
    }
}
Also used : ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) MuleException(org.mule.runtime.api.exception.MuleException)

Aggregations

ConnectionException (org.mule.runtime.api.connection.ConnectionException)24 Test (org.junit.Test)18 SmallTest (org.mule.tck.size.SmallTest)10 IOException (java.io.IOException)6 MuleException (org.mule.runtime.api.exception.MuleException)6 ExceptionUtils.extractConnectionException (org.mule.runtime.core.api.util.ExceptionUtils.extractConnectionException)4 List (java.util.List)2 ExpectedException (org.junit.rules.ExpectedException)2 MuleFatalException (org.mule.runtime.api.exception.MuleFatalException)2 Error (org.mule.runtime.api.message.Error)2 HeisenbergException (org.mule.test.heisenberg.extension.exception.HeisenbergException)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Lock (java.util.concurrent.locks.Lock)1 ThrowableAssert.catchThrowable (org.assertj.core.api.ThrowableAssert.catchThrowable)1 CoreMatchers.instanceOf (org.hamcrest.CoreMatchers.instanceOf)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 Matchers.hasSize (org.hamcrest.Matchers.hasSize)1 Assert.assertThat (org.junit.Assert.assertThat)1 Matchers.any (org.mockito.Matchers.any)1