use of org.h2.jdbcx.JdbcDataSource in project narayana by jbosstm.
the class TestCommitMarkableResourceReturnUnknownOutcomeFrom1PCCommit method testRMFAILAfterCommit.
@Test
public void testRMFAILAfterCommit() throws Exception {
jtaPropertyManager.getJTAEnvironmentBean().setNotifyCommitMarkableResourceRecoveryModuleOfCompleteBranches(false);
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) {
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 };
}
});
}
}
}
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
Uid get_uid = ((TransactionImple) tm.getTransaction()).get_uid();
Connection localJDBCConnection = dataSource.getConnection();
localJDBCConnection.setAutoCommit(false);
nonXAResource = new JDBCConnectableResource(localJDBCConnection) {
@Override
public void commit(Xid arg0, boolean arg1) throws XAException {
super.commit(arg0, arg1);
throw new XAException(XAException.XAER_RMFAIL);
}
};
tm.getTransaction().enlistResource(nonXAResource);
xaResource = new SimpleXAResource();
tm.getTransaction().enlistResource(xaResource);
localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
tm.commit();
assertTrue(xaResource.wasCommitted());
Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
assertNotNull(committed);
InputObjectState uids = new InputObjectState();
StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
Uid uid = UidHelper.unpackFrom(uids);
assertTrue(uid.equals(get_uid));
// Belt and braces but we don't expect the CMR to be removed anyway as
// the RM is "offline"
manager.scan();
manager.scan();
// The recovery module has to perform lookups
new InitialContext().rebind("commitmarkableresource", dataSource);
assertTrue(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
// This will complete the atomicaction
manager.scan();
StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
uid = UidHelper.unpackFrom(uids);
assertTrue(uid.equals(Uid.nullUid()));
// This is when the CMR deletes are done due to ordering
manager.scan();
// of the recovery modules
assertFalse(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
}
use of org.h2.jdbcx.JdbcDataSource in project narayana by jbosstm.
the class PerformanceTestCommitMarkableResource method testCommitMarkableResource.
// @org.junit.Ignore
@Test
public void testCommitMarkableResource() throws Exception {
System.out.println("testCommitMarkableResource: " + new Date());
ConnectionPoolDataSource dataSource = null;
DataSource recoveryDataSource = null;
if (dbType.equals("oracle")) {
// ORA-01795: maximum number of expressions in a list is 1000
BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class).setCommitMarkableResourceRecordDeleteBatchSize(1000);
Class clazz = Class.forName("oracle.jdbc.pool.OracleConnectionPoolDataSource");
dataSource = (ConnectionPoolDataSource) 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 });
recoveryDataSource = (DataSource) dataSource;
} else if (dbType.equals("sybase")) {
// wide table support?
BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class).setCommitMarkableResourceRecordDeleteBatchSize(2000);
Class clazz = Class.forName("com.sybase.jdbc3.jdbc.SybConnectionPoolDataSource");
dataSource = (ConnectionPoolDataSource) 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 });
Class clazz2 = Class.forName("com.sybase.jdbc3.jdbc.SybDataSource");
recoveryDataSource = (DataSource) clazz2.newInstance();
clazz2.getMethod("setServerName", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "192.168.1.5" });
clazz2.getMethod("setDatabaseName", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "LOCALHOST" });
clazz2.getMethod("setUser", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "sa" });
clazz2.getMethod("setPassword", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "sybase" });
clazz2.getMethod("setPortNumber", new Class[] { int.class }).invoke(recoveryDataSource, new Object[] { 5000 });
} else if (dbType.equals("h2")) {
// Smaller batch size as H2 uses a hashtable in the delete which is
// inefficent for bytearray clause
BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class).setCommitMarkableResourceRecordDeleteBatchSize(100);
dataSource = new JdbcDataSource();
((JdbcDataSource) dataSource).setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
recoveryDataSource = ((JdbcDataSource) dataSource);
} else if (dbType.equals("postgres")) {
dataSource = new PGConnectionPoolDataSource();
((PGConnectionPoolDataSource) dataSource).setPortNumber(5432);
((PGConnectionPoolDataSource) dataSource).setUser("dtf11");
((PGConnectionPoolDataSource) dataSource).setPassword("dtf11");
((PGConnectionPoolDataSource) dataSource).setServerName("tywin.eng.hst.ams2.redhat.com");
((PGConnectionPoolDataSource) dataSource).setDatabaseName("jbossts");
recoveryDataSource = new PGSimpleDataSource();
((PGSimpleDataSource) recoveryDataSource).setPortNumber(5432);
((PGSimpleDataSource) recoveryDataSource).setUser("dtf11");
((PGSimpleDataSource) recoveryDataSource).setPassword("dtf11");
((PGSimpleDataSource) recoveryDataSource).setServerName("tywin.eng.hst.ams2.redhat.com");
((PGSimpleDataSource) recoveryDataSource).setDatabaseName("jbossts");
} else if (dbType.equals("mysql")) {
// com.mysql.jdbc.PacketTooBigException: Packet for query is too
// large (1318148 > 1048576). You can change this value on the
// server by setting the max_allowed_packet' variable
BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class).setCommitMarkableResourceRecordDeleteBatchSize(3500);
dataSource = new MysqlConnectionPoolDataSource();
// need paranoid as otherwise it sends a connection change user
((MysqlConnectionPoolDataSource) dataSource).setUrl("jdbc:mysql://tywin.eng.hst.ams2.redhat.com:3306/jbossts?user=dtf11&password=dtf11¶noid=true");
recoveryDataSource = (DataSource) dataSource;
} else if (dbType.equals("db2")) {
Class clazz = Class.forName("com.ibm.db2.jcc.DB2ConnectionPoolDataSource");
dataSource = (ConnectionPoolDataSource) 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 });
Class clazz2 = Class.forName("com.ibm.db2.jcc.DB2DataSource");
recoveryDataSource = (DataSource) clazz2.newInstance();
clazz2.getMethod("setServerName", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "tywin.eng.hst.ams2.redhat.com" });
clazz2.getMethod("setDatabaseName", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "BTDB1" });
clazz2.getMethod("setUser", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "db2" });
clazz2.getMethod("setPassword", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "db2" });
clazz2.getMethod("setDriverType", new Class[] { int.class }).invoke(recoveryDataSource, new Object[] { 4 });
clazz2.getMethod("setPortNumber", new Class[] { int.class }).invoke(recoveryDataSource, new Object[] { 50001 });
} else if (dbType.equals("sqlserver")) {
Class clazz = Class.forName("com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource");
dataSource = (ConnectionPoolDataSource) 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[] { "dballo01" });
clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "dballo01" });
clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "dballo01" });
clazz.getMethod("setSendStringParametersAsUnicode", new Class[] { Boolean.class }).invoke(dataSource, new Object[] { false });
clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 3918 });
recoveryDataSource = (DataSource) dataSource;
}
PooledConnection pooledConnection = dataSource.getPooledConnection();
Utils.createTables(pooledConnection.getConnection());
doTest(new Handler(dataSource, recoveryDataSource), "_testCommitMarkableResource_" + dbType);
}
use of org.h2.jdbcx.JdbcDataSource in project narayana by jbosstm.
the class TestCommitMarkableResource method testH2.
// @Ignore
@Test
public void testH2() throws Exception {
JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
doTest(dataSource);
}
use of org.h2.jdbcx.JdbcDataSource in project narayana by jbosstm.
the class BasicXARecoveryTest method test.
@Test
public void test() throws SQLException, NamingException {
Context ctx = new InitialContext();
ctx.bind("h2DataSource", new JdbcDataSource());
JdbcDataSource h2DataSource = (JdbcDataSource) ctx.lookup("h2DataSource");
h2DataSource.setUser("sa");
h2DataSource.setPassword("sa");
h2DataSource.setUrl("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1");
BasicXARecovery bxar = new BasicXARecovery();
bxar.initialise("h2recoveryproperties.xml");
assertTrue(bxar.hasMoreResources());
XAResource xar1 = bxar.getXAResource();
assertFalse(bxar.hasMoreResources());
assertTrue(bxar.hasMoreResources());
XAResource xar2 = bxar.getXAResource();
assertEquals(xar1, xar2);
}
use of org.h2.jdbcx.JdbcDataSource in project narayana by jbosstm.
the class PoolingTest method setup.
@Before
public void setup() throws Exception {
url = "jdbc:arjuna:";
Properties p = System.getProperties();
p.put("jdbc.drivers", Driver.class.getName());
System.setProperties(p);
DriverManager.registerDriver(new TransactionalDriver());
dbProperties = new Properties();
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
dbProperties.put(TransactionalDriver.XADataSource, ds);
dbProperties.setProperty(TransactionalDriver.maxConnections, "" + POOLSIZE);
try (Connection conn = DriverManager.getConnection(url, dbProperties)) {
try (Statement stmt = conn.createStatement()) {
try {
stmt.executeUpdate("DROP TABLE test_table");
} catch (Exception e) {
// Ignore
} finally {
stmt.executeUpdate("CREATE TABLE test_table (a varchar2)");
}
}
}
}
Aggregations