use of com.arjuna.ats.jdbc.TransactionalDriver 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)");
}
}
}
}
use of com.arjuna.ats.jdbc.TransactionalDriver in project narayana by jbosstm.
the class RecoveryTest method directRecoverableConnection.
@Test
@BMRule(name = "throw rmfail xaexception", targetClass = "org.h2.jdbcx.JdbcXAConnection", targetMethod = "commit", action = "throw new javax.transaction.xa.XAException(javax.transaction.xa.XAException.XAER_RMFAIL)", targetLocation = "AT ENTRY")
public void directRecoverableConnection() throws Exception {
// jdbc:arjuna: <path to properties file>, path starting at System.getProperty("user.dir")
String url = TransactionalDriver.arjunaDriver + "ds-direct.properties";
Properties dbProperties = new Properties();
dbProperties.put(TransactionalDriver.dynamicClass, PropertyFileDynamicClass.class.getName());
dbProperties.put(TransactionalDriver.userName, "");
dbProperties.put(TransactionalDriver.password, "");
Properties p = System.getProperties();
p.put("jdbc.drivers", Driver.class.getName());
System.setProperties(p);
transactionalDriver = new TransactionalDriver();
DriverManager.registerDriver(transactionalDriver);
step0_setupTables(url, dbProperties);
// rmfail means the db connection was left to be recovered
step1_leaveXidsInDbTable(url, dbProperties);
step2_checkDbIsNotCommitted(url, dbProperties);
// 3. Perform recovery - checking only top down XARecoveryModule functionality
{
XARecoveryModule xarm = new XARecoveryModule();
RecoveryManager manager = RecoveryManager.manager();
manager.removeAllModules(true);
manager.addModule(xarm);
AtomicActionRecoveryModule aarm = new AtomicActionRecoveryModule();
aarm.periodicWorkFirstPass();
Transformer.disableTriggers(true);
aarm.periodicWorkSecondPass();
Transformer.enableTriggers(true);
}
step4_finalDbCommitCheck(url, dbProperties);
}
use of com.arjuna.ats.jdbc.TransactionalDriver in project narayana by jbosstm.
the class JDBC2Test 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:./h2/foo");
dbProperties.put(TransactionalDriver.XADataSource, ds);
dbProperties.put(TransactionalDriver.poolConnections, "false");
conn = DriverManager.getConnection(url, dbProperties);
}
use of com.arjuna.ats.jdbc.TransactionalDriver in project narayana by jbosstm.
the class RecoveryTest method test.
@Test
@BMRule(name = "throw lang error exception", targetClass = "org.h2.jdbcx.JdbcXAConnection", targetMethod = "commit", action = "throw new java.lang.Error()", targetLocation = "AT ENTRY")
public void test() throws Exception {
String url = "jdbc:arjuna:";
Properties p = System.getProperties();
p.put("jdbc.drivers", Driver.class.getName());
System.setProperties(p);
transactionalDriver = new TransactionalDriver();
DriverManager.registerDriver(transactionalDriver);
Properties dbProperties = new Properties();
final JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
dbProperties.put(TransactionalDriver.XADataSource, ds);
step0_setupTables(url, dbProperties);
// We need to do this in a different thread as otherwise the transaction would still be associated with the connection due to the java.lang.Error
// RMFAIL on it's own will cause H2 to close connection and that seems to discard the indoubt transactions
step1_leaveXidsInDbTable(url, dbProperties);
step2_checkDbIsNotCommitted(url, dbProperties);
// 3. Perform recovery
{
XARecoveryModule xarm = new XARecoveryModule();
xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
return false;
}
@Override
public XAResource[] getXAResources() throws Exception {
return new XAResource[] { ds.getXAConnection().getXAResource() };
}
});
RecoveryManager manager = RecoveryManager.manager();
manager.removeAllModules(true);
manager.addModule(xarm);
AtomicActionRecoveryModule aarm = new AtomicActionRecoveryModule();
aarm.periodicWorkFirstPass();
Transformer.disableTriggers(true);
aarm.periodicWorkSecondPass();
Transformer.enableTriggers(true);
}
step4_finalDbCommitCheck(url, dbProperties);
}
use of com.arjuna.ats.jdbc.TransactionalDriver in project narayana by jbosstm.
the class TransactionServiceFactory method stop.
/**
* Stop the transaction service. If the recovery manager was started previously then it to will be stopped.
*/
public static synchronized void stop() {
if (!initialized)
return;
if (recoveryManager != null) {
recoveryManager.terminate();
recoveryManager = null;
}
unregisterJndiBindings();
try {
DriverManager.deregisterDriver(new TransactionalDriver());
} catch (SQLException e) {
if (tsLogger.logger.isInfoEnabled())
tsLogger.logger.debug("Unable to deregister TransactionalDriver: " + e.getMessage(), e);
}
if (replacedJndiProperties)
jdbcPropertyManager.getJDBCEnvironmentBean().setJndiProperties(null);
initialized = false;
}
Aggregations