use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.
the class TransactionTimeOutJUnitTest method test9RollbackAfterTimeOut.
@Test
public void test9RollbackAfterTimeOut() throws Exception {
Context ctx = cache.getJNDIContext();
DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
Connection conn2 = ds2.getConnection();
GemFireTransactionDataSource ds = (GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
utx.begin();
Connection conn = ds.getConnection();
String sql = "create table newTable3 (id integer)";
Statement sm = conn.createStatement();
sm.execute(sql);
utx.setTransactionTimeout(30);
sql = "insert into newTable3 values (1)";
sm.execute(sql);
sql = "select * from newTable3 where id = 1";
ResultSet rs = sm.executeQuery(sql);
if (!rs.next()) {
fail("Transaction not committed");
}
sql = "drop table newTable3";
sm.execute(sql);
sm.close();
conn.close();
conn2.close();
utx.setTransactionTimeout(1);
Thread.sleep(3000);
try {
utx.rollback();
fail("exception did not occur on rollback although transaction timed out");
} catch (Exception expected) {
}
}
use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.
the class GlobalTransactionJUnitTest method testEnlistResource.
@Test
public void testEnlistResource() throws Exception {
try {
boolean exceptionoccurred = false;
utx.begin();
try {
Context ctx = cache.getJNDIContext();
GemFireTransactionDataSource ds = (GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
ds.getConnection();
} catch (SQLException e) {
exceptionoccurred = true;
}
if (exceptionoccurred)
fail("SQLException occurred while trying to enlist resource");
utx.rollback();
} catch (Exception e) {
try {
utx.rollback();
} catch (Exception e1) {
e1.printStackTrace();
}
fail("exception in testEnlistResource due to " + e);
e.printStackTrace();
}
}
use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.
the class GlobalTransactionJUnitTest method testEnlistResourceAfterRollBack.
@Test
public void testEnlistResourceAfterRollBack() throws Exception {
try {
boolean exceptionoccurred = false;
utx.begin();
utx.setRollbackOnly();
Context ctx = cache.getJNDIContext();
try {
GemFireTransactionDataSource ds = (GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
ds.getConnection();
} catch (SQLException e) {
exceptionoccurred = true;
}
if (!exceptionoccurred)
fail("SQLException not occurred although the transaction was marked for rollback");
utx.rollback();
} catch (Exception e) {
try {
utx.rollback();
} catch (Exception e1) {
e1.printStackTrace();
}
fail("exception in testSetRollbackonly due to " + e);
e.printStackTrace();
}
}
Aggregations