Search in sources :

Example 66 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project narayana by jbosstm.

the class PerformanceTestCommitMarkableResource method testXAResource.

// @org.junit.Ignore
@Test
public void testXAResource() throws Exception {
    System.out.println("testXAResource: " + new Date());
    XADataSource dataSource = null;
    if (dbType.equals("oracle")) {
        Class clazz = Class.forName("oracle.jdbc.xa.client.OracleXADataSource");
        dataSource = (XADataSource) clazz.newInstance();
        clazz.getMethod("setDriverType", new Class[] { String.class }).invoke(dataSource, new Object[] { "thin" });
        clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "tywin.eng.hst.ams2.redhat.com" });
        clazz.getMethod("setNetworkProtocol", new Class[] { String.class }).invoke(dataSource, new Object[] { "tcp" });
        clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "orcl" });
        clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "dtf11" });
        clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "dtf11" });
        clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 1521 });
    } else if (dbType.equals("sybase")) {
        Class clazz = Class.forName("com.sybase.jdbc3.jdbc.SybXADataSource");
        dataSource = (XADataSource) clazz.newInstance();
        clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "192.168.1.5" });
        clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "LOCALHOST" });
        clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "sa" });
        clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "sybase" });
        clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 5000 });
    } else if (dbType.equals("h2")) {
        dataSource = new org.h2.jdbcx.JdbcDataSource();
        ((JdbcDataSource) dataSource).setURL("jdbc:h2:mem:JBTMDB2;MVCC=TRUE;DB_CLOSE_DELAY=-1");
    } else if (dbType.equals("postgres")) {
        dataSource = new PGXADataSource();
        ((PGXADataSource) dataSource).setPortNumber(5432);
        ((PGXADataSource) dataSource).setUser("dtf11");
        ((PGXADataSource) dataSource).setPassword("dtf11");
        ((PGXADataSource) dataSource).setServerName("tywin.eng.hst.ams2.redhat.com");
        ((PGXADataSource) dataSource).setDatabaseName("jbossts");
    } else if (dbType.equals("mysql")) {
        dataSource = new MysqlXADataSource();
        ((MysqlXADataSource) dataSource).setServerName("tywin.eng.hst.ams2.redhat.com");
        ((MysqlXADataSource) dataSource).setPortNumber(3306);
        ((MysqlXADataSource) dataSource).setDatabaseName("jbossts");
        ((MysqlXADataSource) dataSource).setUser("dtf11");
        ((MysqlXADataSource) dataSource).setPassword("dtf11");
    } else if (dbType.equals("db2")) {
        Class clazz = Class.forName("com.ibm.db2.jcc.DB2XADataSource");
        dataSource = (XADataSource) clazz.newInstance();
        clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "tywin.eng.hst.ams2.redhat.com" });
        clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "BTDB1" });
        clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "db2" });
        clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "db2" });
        clazz.getMethod("setDriverType", new Class[] { int.class }).invoke(dataSource, new Object[] { 4 });
        clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 50001 });
    } else if (dbType.equals("sqlserver")) {
        Class clazz = Class.forName("com.microsoft.sqlserver.jdbc.SQLServerXADataSource");
        dataSource = (XADataSource) clazz.newInstance();
        clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "dev30.mw.lab.eng.bos.redhat.com" });
        clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "crashrec" });
        clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "crashrec" });
        clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "crashrec" });
        clazz.getMethod("setSendStringParametersAsUnicode", new Class[] { Boolean.class }).invoke(dataSource, new Object[] { false });
        clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 3918 });
    }
    Utils.createTables(dataSource);
    doTest(new Handler(dataSource), "_testXAResource_" + dbType);
}
Also used : XADataSource(javax.sql.XADataSource) MysqlXADataSource(com.mysql.jdbc.jdbc2.optional.MysqlXADataSource) PGXADataSource(org.postgresql.xa.PGXADataSource) MysqlXADataSource(com.mysql.jdbc.jdbc2.optional.MysqlXADataSource) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Date(java.util.Date) PGXADataSource(org.postgresql.xa.PGXADataSource) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Test(org.junit.Test)

Example 67 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project narayana by jbosstm.

the class TestCommitMarkableResourceFailActivate method testFailAfterPrepare.

@Test
@BMScript("commitMarkableResourceFailAfterCommit")
public void testFailAfterPrepare() throws Exception {
    final DataSource dataSource = new JdbcDataSource();
    ((JdbcDataSource) dataSource).setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
    // Test code
    Utils.createTables(dataSource.getConnection());
    // We can't just instantiate one as we need to be using the
    // same one as
    // the transaction
    // manager would have used to mark the transaction for GC
    CommitMarkableResourceRecordRecoveryModule recoveryModule = null;
    Vector recoveryModules = manager.getModules();
    if (recoveryModules != null) {
        Enumeration modules = recoveryModules.elements();
        while (modules.hasMoreElements()) {
            RecoveryModule m = (RecoveryModule) modules.nextElement();
            if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
                recoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
            } else if (m instanceof XARecoveryModule) {
                XARecoveryModule xarm = (XARecoveryModule) m;
                xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

                    public boolean initialise(String p) throws Exception {
                        return true;
                    }

                    public XAResource[] getXAResources() throws Exception {
                        return new XAResource[] { xaResource };
                    }
                });
            }
        }
    }
    // final Object o = new Object();
    // synchronized (o) {
    Thread foo = new Thread(new Runnable() {

        public void run() {
            try {
                javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
                tm.begin();
                Connection localJDBCConnection = dataSource.getConnection();
                localJDBCConnection.setAutoCommit(false);
                nonXAResource = new JDBCConnectableResource(localJDBCConnection);
                tm.getTransaction().enlistResource(nonXAResource);
                xaResource = new SimpleXAResource();
                tm.getTransaction().enlistResource(xaResource);
                localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
                tm.commit();
            } catch (ExecuteException t) {
            } catch (Exception t) {
                t.printStackTrace();
                failed = true;
            } catch (Error t) {
            }
        }
    });
    foo.start();
    foo.join();
    assertFalse(failed);
    // Now we need to correctly complete the transaction
    manager.scan();
    assertFalse(xaResource.wasCommitted());
    assertFalse(xaResource.wasRolledback());
    // This is test code, it allows us to verify that the
    // correct XID was
    // removed
    Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
    assertNotNull(committed);
    // The recovery module has to perform lookups
    new InitialContext().rebind("commitmarkableresource", dataSource);
    // Run the first pass it will load the committed Xids into so we can
    // indepently verify that the item was committed
    recoveryModule.periodicWorkFirstPass();
    recoveryModule.periodicWorkSecondPass();
    assertTrue(recoveryModule.wasCommitted("commitmarkableresource", committed));
    // Run the scan to clear the content
    manager.scan();
    assertTrue(xaResource.wasCommitted());
    assertFalse(xaResource.wasRolledback());
    // Make sure that the resource was GC'd by the CRRRM
    assertTrue(recoveryModule.wasCommitted("commitmarkableresource", committed));
    recoveryModule.periodicWorkFirstPass();
    assertTrue(recoveryModule.wasCommitted("commitmarkableresource", committed));
    // This is the pass that will delete it
    recoveryModule.periodicWorkSecondPass();
    assertFalse(recoveryModule.wasCommitted("commitmarkableresource", committed));
}
Also used : Enumeration(java.util.Enumeration) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) ExecuteException(org.jboss.byteman.rule.exception.ExecuteException) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) ExecuteException(org.jboss.byteman.rule.exception.ExecuteException) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) Vector(java.util.Vector) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 68 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project narayana by jbosstm.

the class TestCommitMarkableResourceFailAfterCommit method testFailAfterCommitH2.

@Test
@BMScript("commitMarkableResourceFailAfterCommit")
public void testFailAfterCommitH2() throws Exception {
    final JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
    doTest(dataSource);
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 69 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project narayana by jbosstm.

the class TestCommitMarkableResourceFailAfterCommitOrphan method test.

@Test
@BMScript("commitMarkableResourceFailAfterCommit")
public void test() throws Exception {
    final JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
    // Test code
    Utils.createTables(dataSource.getConnection());
    // We can't just instantiate one as we need to be using the
    // same one as
    // the transaction
    // manager would have used to mark the transaction for GC
    CommitMarkableResourceRecordRecoveryModule commitMarkableResourceRecoveryModule = null;
    Vector recoveryModules = manager.getModules();
    if (recoveryModules != null) {
        Enumeration modules = recoveryModules.elements();
        while (modules.hasMoreElements()) {
            RecoveryModule m = (RecoveryModule) modules.nextElement();
            if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
                commitMarkableResourceRecoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
            } else if (m instanceof XARecoveryModule) {
                xarm = (XARecoveryModule) m;
                xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

                    public boolean initialise(String p) throws Exception {
                        return true;
                    }

                    public XAResource[] getXAResources() throws Exception {
                        return new XAResource[] { xaResource };
                    }
                });
            }
        }
    }
    // final Object o = new Object();
    // synchronized (o) {
    Thread preCrash = new Thread(new Runnable() {

        public void run() {
            try (Connection localJDBCConnection = dataSource.getConnection()) {
                javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
                tm.begin();
                localJDBCConnection.setAutoCommit(false);
                cmrResource = new JDBCConnectableResource(localJDBCConnection);
                tm.getTransaction().enlistResource(cmrResource);
                tm.getTransaction().enlistResource(xaResource);
                localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
                tm.commit();
            } catch (ExecuteException t) {
            } catch (Exception e) {
                e.printStackTrace();
                failed = true;
            } catch (Error e) {
            }
        }
    });
    preCrash.start();
    preCrash.join();
    assertFalse(failed);
    assertFalse(wasCommitted);
    assertFalse(wasRolledback);
    // The recovery module has to perform lookups
    new InitialContext().rebind("commitmarkableresource", dataSource);
    // Testing that we can find a AAC but that it won't be ignored in orphan detection so need CMRRM run
    commitMarkableResourceRecoveryModule.periodicWorkFirstPass();
    XAResourceOrphanFilter.Vote vote = new JTATransactionLogXAResourceOrphanFilter().checkXid(preparedXid);
    assertTrue(vote == XAResourceOrphanFilter.Vote.LEAVE_ALONE);
    manager.scan();
    manager.scan();
    assertTrue(wasCommitted);
}
Also used : Enumeration(java.util.Enumeration) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) JTATransactionLogXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) ExecuteException(org.jboss.byteman.rule.exception.ExecuteException) XAException(javax.transaction.xa.XAException) InitialContext(javax.naming.InitialContext) XAResource(javax.transaction.xa.XAResource) ExecuteException(org.jboss.byteman.rule.exception.ExecuteException) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) Vector(java.util.Vector) XAResourceOrphanFilter(com.arjuna.ats.jta.recovery.XAResourceOrphanFilter) JTATransactionLogXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 70 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project jdbi by jdbi.

the class TestNewApiOnDbiAndHandle method setUp.

@Before
public void setUp() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:" + UUID.randomUUID());
    db = Jdbi.create(ds);
    db.installPlugin(new SqlObjectPlugin());
    db.registerRowMapper(new SomethingMapper());
    handle = db.open();
    handle.execute("create table something (id int primary key, name varchar(100))");
}
Also used : SomethingMapper(org.jdbi.v3.core.mapper.SomethingMapper) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Before(org.junit.Before)

Aggregations

JdbcDataSource (org.h2.jdbcx.JdbcDataSource)81 Connection (java.sql.Connection)24 Test (org.junit.Test)24 Before (org.junit.Before)15 XAResource (javax.transaction.xa.XAResource)13 DataSource (javax.sql.DataSource)9 Xid (javax.transaction.xa.Xid)9 SQLException (java.sql.SQLException)8 InitialContext (javax.naming.InitialContext)8 XAConnection (javax.sql.XAConnection)8 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)7 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)7 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)7 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)7 Statement (java.sql.Statement)7 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)7 File (java.io.File)6 Enumeration (java.util.Enumeration)6 Properties (java.util.Properties)6 Vector (java.util.Vector)6