Search in sources :

Example 21 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project microservice_framework by CJSCommonPlatform.

the class StreamStatusJdbcRepositoryIT method initDatabase.

@Before
public void initDatabase() throws Exception {
    final TestDataSourceFactory testDataSourceFactory = new TestDataSourceFactory(LIQUIBASE_STREAM_STATUS_CHANGELOG_XML);
    final JdbcDataSource dataSource = testDataSourceFactory.createDataSource();
    jdbcRepository = new StreamStatusJdbcRepository(dataSource, new JdbcRepositoryHelper());
    try {
        final Poller poller = new Poller();
        poller.pollUntilFound(() -> {
            try {
                dataSource.getConnection().prepareStatement("SELECT COUNT (*) FROM stream_buffer;").execute();
                return Optional.of("Success");
            } catch (SQLException e) {
                e.printStackTrace();
                fail("EventJdbcRepository construction failed");
                return Optional.empty();
            }
        });
    } catch (final Exception e) {
        e.printStackTrace();
        fail("EventJdbcRepository construction failed");
    }
}
Also used : JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper) SQLException(java.sql.SQLException) TestDataSourceFactory(uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Poller(uk.gov.justice.services.test.utils.core.messaging.Poller) SQLException(java.sql.SQLException) Before(org.junit.Before)

Example 22 with JdbcDataSource

use of org.h2.jdbcx.JdbcDataSource in project microservice_framework by CJSCommonPlatform.

the class StreamBufferJdbcRepositoryIT method initDatabase.

@Before
public void initDatabase() throws Exception {
    final TestDataSourceFactory testDataSourceFactory = new TestDataSourceFactory(LIQUIBASE_STREAM_STATUS_CHANGELOG_XML);
    final JdbcDataSource dataSource = testDataSourceFactory.createDataSource();
    jdbcRepository = new StreamBufferJdbcRepository(dataSource, new JdbcRepositoryHelper());
    try {
        final Poller poller = new Poller();
        poller.pollUntilFound(() -> {
            try {
                dataSource.getConnection().prepareStatement("SELECT COUNT (*) FROM stream_buffer;").execute();
                return Optional.of("Success");
            } catch (SQLException e) {
                e.printStackTrace();
                fail("EventJdbcRepository construction failed");
                return Optional.empty();
            }
        });
    } catch (final Exception e) {
        e.printStackTrace();
        fail("EventJdbcRepository construction failed");
    }
}
Also used : JdbcRepositoryHelper(uk.gov.justice.services.jdbc.persistence.JdbcRepositoryHelper) SQLException(java.sql.SQLException) TestDataSourceFactory(uk.gov.justice.services.test.utils.persistence.TestDataSourceFactory) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Poller(uk.gov.justice.services.test.utils.core.messaging.Poller) SQLException(java.sql.SQLException) Before(org.junit.Before)

Example 23 with JdbcDataSource

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

the class TestCommitMarkableResourceFailAfterPrepare method testFailAfterPrepare.

@Test
@BMScript("commitMarkableResourceFailAfterPrepare")
public void testFailAfterPrepare() throws Exception {
    final DataSource dataSource = new JdbcDataSource();
    generateCMRRecord(dataSource);
    checkCMRRecovery(dataSource);
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) DataSource(javax.sql.DataSource) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 24 with JdbcDataSource

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

the class TestCommitMarkableResourceFailAfterCommitTwoXAResources method testFailAfterCommitH2.

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

Example 25 with JdbcDataSource

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

the class TestCommitMarkableResourceMultiEnlist method testFailDoubleEnlist.

@Test
public void testFailDoubleEnlist() throws NotSupportedException, SystemException, IllegalStateException, RollbackException, SQLException {
    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE");
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    tm.begin();
    tm.getTransaction().enlistResource(new JDBCConnectableResource(dataSource.getConnection()));
    if (tm.getTransaction().enlistResource(new JDBCConnectableResource(dataSource.getConnection()))) {
        fail();
    }
    tm.rollback();
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Test(org.junit.Test)

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