use of javax.sql.XAConnection in project spring-boot by spring-projects.
the class PoolingDataSourceBeanTests method setDataSource.
@Test
public void setDataSource() throws Exception {
XADataSource dataSource = mock(XADataSource.class);
XAConnection xaConnection = mock(XAConnection.class);
Connection connection = mock(Connection.class);
given(dataSource.getXAConnection()).willReturn(xaConnection);
given(xaConnection.getConnection()).willReturn(connection);
this.bean.setDataSource(dataSource);
this.bean.setBeanName("beanName");
this.bean.afterPropertiesSet();
this.bean.init();
this.bean.createPooledConnection(dataSource, this.bean);
verify(dataSource).getXAConnection();
TransactionManagerServices.getTaskScheduler().shutdown();
}
use of javax.sql.XAConnection in project spring-boot by spring-projects.
the class NarayanaDataSourceBeanTests method shouldGetConnectionAndCommit.
@Test
public void shouldGetConnectionAndCommit() throws SQLException {
Connection mockConnection = mock(Connection.class);
XAConnection mockXaConnection = mock(XAConnection.class);
given(mockXaConnection.getConnection()).willReturn(mockConnection);
given(this.dataSource.getXAConnection("", "")).willReturn(mockXaConnection);
Properties properties = new Properties();
properties.put(TransactionalDriver.XADataSource, this.dataSource);
Connection connection = this.dataSourceBean.getConnection();
assertThat(connection).isInstanceOf(ConnectionImple.class);
connection.commit();
verify(this.dataSource, times(1)).getXAConnection("", "");
verify(mockXaConnection, times(1)).getConnection();
verify(mockConnection, times(1)).commit();
}
use of javax.sql.XAConnection in project geode by apache.
the class AbstractPoolCacheJUnitTest method testEffectOfBlockingTimeoutOnXAConnection.
/**
* Tests if an XAresource obtained from an XAConnection which is already closed , can return null
* or not.
*/
@Ignore("TODO: test used to eat its own exception and it fails")
@Test
public void testEffectOfBlockingTimeoutOnXAConnection() throws Exception {
Map map = new HashMap();
map.put("init-pool-size", "2");
map.put("jndi-name", "TestXAPooledDataSource");
map.put("max-pool-size", "7");
map.put("idle-timeout-seconds", "20");
map.put("blocking-timeout-seconds", "2");
map.put("login-timeout-seconds", "5");
// map.put("xa-datasource-class","org.apache.derby.jdbc.EmbeddedXADataSource");
map.put("jdbc-driver-class", "org.apache.derby.jdbc.EmbeddedDriver");
map.put("user-name", "mitul");
map.put("password", "83f0069202c571faf1ae6c42b4ad46030e4e31c17409e19a");
map.put("connection-url", "jdbc:derby:newDB;create=true");
List props = new ArrayList();
props.add(new ConfigProperty("databaseName", "newDB", "java.lang.String"));
GemFireBasicDataSource gbds = (GemFireBasicDataSource) DataSourceFactory.getSimpleDataSource(map, props);
map.put("xa-datasource-class", "org.apache.derby.jdbc.EmbeddedXADataSource");
map.put("connection-url", "jdbc:derby:newDB;create=true");
GemFireTransactionDataSource gtds = (GemFireTransactionDataSource) DataSourceFactory.getTranxDataSource(map, props);
XAConnection xaconn = (XAConnection) gtds.provider.borrowConnection();
try {
Thread.sleep(4);
} catch (InterruptedException e) {
fail("interrupted");
}
for (int i = 0; i < 1000; ++i) {
XAResource xar = xaconn.getXAResource();
System.out.println("XAResource=" + xar);
assertNotNull(xar);
}
}
use of javax.sql.XAConnection in project geode by apache.
the class GemFireTransactionDataSource method connectionClosed.
/**
* Implementation of call back function from ConnectionEventListener interface. This callback will
* be invoked on connection close event.
*
* @param event Connection event object
*/
public void connectionClosed(ConnectionEvent event) {
if (isActive) {
try {
XAConnection conn = (XAConnection) event.getSource();
XAResource xar = (XAResource) xaResourcesMap.get(conn);
xaResourcesMap.remove(conn);
Transaction txn = transManager.getTransaction();
if (txn != null && xar != null)
txn.delistResource(xar, XAResource.TMSUCCESS);
provider.returnConnection(conn);
} catch (Exception e) {
String exception = "GemFireTransactionDataSource::connectionClosed: Exception occurred due to " + e;
if (logger.isDebugEnabled()) {
logger.debug(exception, e);
}
}
}
}
use of javax.sql.XAConnection in project aries by apache.
the class XATxContextBindingEntityManagerTest method testActiveTransactionStraightXAConnection.
@Test
public void testActiveTransactionStraightXAConnection() throws SQLException {
Connection con = Mockito.mock(Connection.class, withSettings().extraInterfaces(XAConnection.class));
Mockito.when(((XAConnection) con).getXAResource()).thenReturn(xaResource);
Mockito.when(rawEm.unwrap(Connection.class)).thenReturn(con);
setupActiveTransaction();
em.isOpen();
em.isOpen();
Mockito.verify(rawEm, times(2)).isOpen();
Mockito.verify(rawEm).joinTransaction();
checkPostCompletion(null);
}
Aggregations