Search in sources :

Example 1 with ConnectionValidationResult

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

the class DefaultConnectionManagerTestCase method cachedConnectionProviderConnectivity.

@Test
public void cachedConnectionProviderConnectivity() throws Exception {
    ConnectionValidationResult result = connectionManager.testConnectivity(connectionProvider);
    assertThat(result.isValid(), is(true));
    verify(connectionProvider).connect();
    verify(connectionProvider, atLeastOnce()).validate(connection);
    verify(connectionProvider, never()).disconnect(connection);
}
Also used : ConnectionValidationResult(org.mule.runtime.api.connection.ConnectionValidationResult) Test(org.junit.Test)

Example 2 with ConnectionValidationResult

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

the class DefaultConnectionManagerTestCase method failingConnectionProviderConnectivity.

@Test
public void failingConnectionProviderConnectivity() throws Exception {
    ConnectionValidationResult validationResult = failure("oops", new Exception());
    when(testeableConnectionProvider.validate(connection)).thenReturn(validationResult);
    ConnectionValidationResult result = connectionManager.testConnectivity(testeableConnectionProvider);
    assertThat(result, is(sameInstance(validationResult)));
    verify(testeableConnectionProvider).connect();
    verify(testeableConnectionProvider).validate(connection);
    verify(testeableConnectionProvider).disconnect(connection);
}
Also used : ConnectionValidationResult(org.mule.runtime.api.connection.ConnectionValidationResult) ConnectionException(org.mule.runtime.api.connection.ConnectionException) Test(org.junit.Test)

Example 3 with ConnectionValidationResult

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

the class ForwardingSoapClientConnectionProvider method validate.

@Override
public ConnectionValidationResult validate(ForwardingSoapClient connection) {
    try {
        serviceProvider.validateConfiguration();
        MessageDispatcher messageDispatcher;
        if (transportProvider instanceof ContextAwareMessageDispatcherProvider) {
            messageDispatcher = ((ContextAwareMessageDispatcherProvider) transportProvider).connect(new DefaultDispatchingContext(client));
        } else {
            messageDispatcher = transportProvider.connect();
        }
        ConnectionValidationResult result = transportProvider.validate(messageDispatcher, serviceProvider);
        transportProvider.disconnect(messageDispatcher);
        return result;
    } catch (Exception e) {
        return failure(e.getMessage(), e);
    }
}
Also used : MessageDispatcher(org.mule.runtime.extension.api.soap.message.MessageDispatcher) ConnectionValidationResult(org.mule.runtime.api.connection.ConnectionValidationResult) ContextAwareMessageDispatcherProvider(org.mule.runtime.extension.api.soap.ContextAwareMessageDispatcherProvider) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) MuleException(org.mule.runtime.api.exception.MuleException) SoapServiceProviderConfigurationException(org.mule.runtime.extension.api.soap.SoapServiceProviderConfigurationException)

Example 4 with ConnectionValidationResult

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

the class LifecycleAwareConfigurationInstance method testConnectivity.

private void testConnectivity() throws MuleException {
    ConnectionProvider provider = connectionProvider.get();
    if (provider instanceof NoConnectivityTest) {
        return;
    }
    Scheduler retryScheduler = schedulerService.ioScheduler();
    RetryPolicyTemplate retryTemplate = connectionManager.getRetryTemplateFor(provider);
    ReconnectionConfig reconnectionConfig = connectionManager.getReconnectionConfigFor(provider);
    RetryCallback retryCallback = new RetryCallback() {

        @Override
        public void doWork(RetryContext context) throws Exception {
            Lock lock = testConnectivityLock;
            if (lock != null) {
                final boolean lockAcquired = lock.tryLock();
                if (lockAcquired) {
                    LOGGER.info("Doing testConnectivity() for config " + getName());
                    try {
                        ConnectionValidationResult result = connectionManager.testConnectivity(LifecycleAwareConfigurationInstance.this);
                        if (result.isValid()) {
                            context.setOk();
                        } else {
                            if ((reconnectionConfig.isFailsDeployment())) {
                                context.setFailed(result.getException());
                                throw new ConnectionException(format("Connectivity test failed for config '%s'", getName()), result.getException());
                            } else {
                                if (LOGGER.isInfoEnabled()) {
                                    LOGGER.info(format("Connectivity test failed for config '%s'. Application deployment will continue. Error was: ", getName(), result.getMessage()), result.getException());
                                }
                            }
                        }
                    } finally {
                        lock.unlock();
                    }
                } else {
                    LOGGER.warn("There is a testConnectivity() already running for config " + getName());
                }
            }
        }

        @Override
        public String getWorkDescription() {
            return format("Testing connectivity for config '%s'", getName());
        }

        @Override
        public Object getWorkOwner() {
            return value;
        }
    };
    try {
        retryTemplate.execute(retryCallback, retryScheduler);
    } catch (Exception e) {
        throw new DefaultMuleException(createStaticMessage(format("Could not perform connectivity testing for config '%s'", getName())), e);
    } finally {
        if (retryScheduler != null) {
            retryScheduler.stop();
        }
    }
}
Also used : RetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate) Scheduler(org.mule.runtime.api.scheduler.Scheduler) RetryContext(org.mule.runtime.core.api.retry.RetryContext) ReconnectionConfig(org.mule.runtime.core.internal.retry.ReconnectionConfig) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) Lock(java.util.concurrent.locks.Lock) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ConnectionValidationResult(org.mule.runtime.api.connection.ConnectionValidationResult) NoConnectivityTest(org.mule.runtime.extension.api.connectivity.NoConnectivityTest) ConnectionException(org.mule.runtime.api.connection.ConnectionException) RetryCallback(org.mule.runtime.core.api.retry.RetryCallback)

Example 5 with ConnectionValidationResult

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

the class ExtensionConnectivityTestingStrategyTestCase method connectionProviderInConfigWithValidConnection.

@Test
public void connectionProviderInConfigWithValidConnection() throws MuleException {
    ConnectionValidationResult connectionResult = testConnectivityWithConnectionProvider(true);
    assertThat(connectionResult.isValid(), is(true));
}
Also used : ConnectionValidationResult(org.mule.runtime.api.connection.ConnectionValidationResult) Test(org.junit.Test)

Aggregations

ConnectionValidationResult (org.mule.runtime.api.connection.ConnectionValidationResult)14 Test (org.junit.Test)10 ConnectionException (org.mule.runtime.api.connection.ConnectionException)3 MuleException (org.mule.runtime.api.exception.MuleException)3 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)2 SoapServiceProviderConfigurationException (org.mule.runtime.extension.api.soap.SoapServiceProviderConfigurationException)2 Lock (java.util.concurrent.locks.Lock)1 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)1 PoolingConnectionProvider (org.mule.runtime.api.connection.PoolingConnectionProvider)1 ConnectivityTestingService (org.mule.runtime.api.connectivity.ConnectivityTestingService)1 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)1 Scheduler (org.mule.runtime.api.scheduler.Scheduler)1 RetryCallback (org.mule.runtime.core.api.retry.RetryCallback)1 RetryContext (org.mule.runtime.core.api.retry.RetryContext)1 RetryPolicyTemplate (org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate)1 ReconnectionConfig (org.mule.runtime.core.internal.retry.ReconnectionConfig)1 NoConnectivityTest (org.mule.runtime.extension.api.connectivity.NoConnectivityTest)1 ContextAwareMessageDispatcherProvider (org.mule.runtime.extension.api.soap.ContextAwareMessageDispatcherProvider)1 MessageDispatcher (org.mule.runtime.extension.api.soap.message.MessageDispatcher)1