Search in sources :

Example 61 with XAConnection

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();
}
Also used : XADataSource(javax.sql.XADataSource) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) XAConnection(javax.sql.XAConnection) Test(org.junit.Test)

Example 62 with XAConnection

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();
}
Also used : Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) Properties(java.util.Properties) XAConnection(javax.sql.XAConnection) Test(org.junit.Test)

Example 63 with XAConnection

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);
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) XAConnection(javax.sql.XAConnection) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 64 with XAConnection

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);
            }
        }
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) Transaction(javax.transaction.Transaction) SQLException(java.sql.SQLException) XAConnection(javax.sql.XAConnection)

Example 65 with XAConnection

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);
}
Also used : Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) XAConnection(javax.sql.XAConnection) Test(org.junit.Test)

Aggregations

XAConnection (javax.sql.XAConnection)115 Connection (java.sql.Connection)78 XAResource (javax.transaction.xa.XAResource)56 XADataSource (javax.sql.XADataSource)52 Xid (javax.transaction.xa.Xid)44 Statement (java.sql.Statement)34 SQLException (java.sql.SQLException)30 PreparedStatement (java.sql.PreparedStatement)23 PooledConnection (javax.sql.PooledConnection)23 ResultSet (java.sql.ResultSet)22 CallableStatement (java.sql.CallableStatement)18 Test (org.junit.Test)18 XAException (javax.transaction.xa.XAException)16 Transaction (javax.transaction.Transaction)8 DataSource (javax.sql.DataSource)7 XidImpl (org.firebirdsql.jca.TestXABase.XidImpl)7 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)7 NotSupportedException (javax.transaction.NotSupportedException)5 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)4 J2EEDataSource (org.apache.derbyTesting.junit.J2EEDataSource)4