Search in sources :

Example 1 with XATransactionalConnection

use of org.mule.runtime.extension.api.connectivity.XATransactionalConnection in project mule by mulesoft.

the class TransactionalSource method onStart.

@Override
public void onStart(SourceCallback<TestTransactionalConnection, Object> sourceCallback) throws MuleException {
    connectExecutor = newFixedThreadPool(1);
    connectExecutor.execute(() -> {
        SourceCallbackContext ctx = sourceCallback.createContext();
        try {
            TestTransactionalConnection connection = connectionProvider.connect();
            boolean isXa = false;
            if (connection instanceof XATransactionalConnection) {
                isXa = true;
                xaResource = (DummyXaResource) ((XATransactionalConnection) connection).getXAResource();
            }
            ctx.addVariable(IS_XA, isXa);
            ctx.bindConnection(connection);
            sourceCallback.handle(Result.<TestTransactionalConnection, Object>builder().output(connection).build(), ctx);
        } catch (ConnectionException e) {
            sourceCallback.onConnectionException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : SourceCallbackContext(org.mule.runtime.extension.api.runtime.source.SourceCallbackContext) TestTransactionalConnection(org.mule.test.transactional.connection.TestTransactionalConnection) XATransactionalConnection(org.mule.runtime.extension.api.connectivity.XATransactionalConnection) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) TransactionException(org.mule.runtime.api.tx.TransactionException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 2 with XATransactionalConnection

use of org.mule.runtime.extension.api.connectivity.XATransactionalConnection in project mule by mulesoft.

the class ExtensionConnectionSupplierTestCase method xaTransaction.

@Test
public void xaTransaction() throws Exception {
    muleContext.setTransactionManager(mock(TransactionManager.class, RETURNS_DEEP_STUBS));
    XaTransaction transaction = spy(new XaTransaction(muleContext));
    XATransactionalConnection connection = mock(XATransactionalConnection.class, RETURNS_DEEP_STUBS);
    Object config = new Object();
    ExecutionContextAdapter operationContext = mock(ExecutionContextAdapter.class, RETURNS_DEEP_STUBS);
    ConnectionProvider connectionProvider = mock(ConnectionProvider.class);
    ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
    when(configurationInstance.getConnectionProvider()).thenReturn(of(connectionProvider));
    when(operationContext.getConfiguration()).thenReturn(of(configurationInstance));
    when(configurationInstance.getValue()).thenReturn(config);
    when(connectionProvider.connect()).thenReturn(connection);
    TransactionConfig transactionConfig = mock(TransactionConfig.class);
    when(transactionConfig.getAction()).thenReturn(ACTION_ALWAYS_JOIN);
    when(transactionConfig.isTransacted()).thenReturn(true);
    when(operationContext.getTransactionConfig()).thenReturn(of(transactionConfig));
    connectionManager.bind(config, connectionProvider);
    TransactionCoordination.getInstance().bindTransaction(transaction);
    adapter.getConnection(operationContext);
    verify(transaction).bindResource(any(), any(XAExtensionTransactionalResource.class));
}
Also used : XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) XAExtensionTransactionalResource(org.mule.runtime.module.extension.internal.runtime.transaction.XAExtensionTransactionalResource) TransactionManager(javax.transaction.TransactionManager) TransactionConfig(org.mule.runtime.core.api.transaction.TransactionConfig) XATransactionalConnection(org.mule.runtime.extension.api.connectivity.XATransactionalConnection) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Test(org.junit.Test)

Aggregations

XATransactionalConnection (org.mule.runtime.extension.api.connectivity.XATransactionalConnection)2 TransactionManager (javax.transaction.TransactionManager)1 Test (org.junit.Test)1 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)1 MuleException (org.mule.runtime.api.exception.MuleException)1 TransactionException (org.mule.runtime.api.tx.TransactionException)1 TransactionConfig (org.mule.runtime.core.api.transaction.TransactionConfig)1 XaTransaction (org.mule.runtime.core.privileged.transaction.XaTransaction)1 ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)1 SourceCallbackContext (org.mule.runtime.extension.api.runtime.source.SourceCallbackContext)1 ExecutionContextAdapter (org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter)1 XAExtensionTransactionalResource (org.mule.runtime.module.extension.internal.runtime.transaction.XAExtensionTransactionalResource)1 TestTransactionalConnection (org.mule.test.transactional.connection.TestTransactionalConnection)1