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);
}
});
}
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));
}
Aggregations