use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.
the class TransactionTimeOutJUnitTest method test8CommitAfterTimeOut.
@Test
public void test8CommitAfterTimeOut() throws Exception {
Context ctx = cache.getJNDIContext();
DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
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 newTable2 (id integer)";
Statement sm = conn.createStatement();
sm.execute(sql);
utx.setTransactionTimeout(30);
sql = "insert into newTable2 values (1)";
sm.execute(sql);
sql = "select * from newTable2 where id = 1";
ResultSet rs = sm.executeQuery(sql);
if (!rs.next()) {
fail("Transaction not committed");
}
sql = "drop table newTable2";
sm.execute(sql);
sm.close();
conn.close();
utx.setTransactionTimeout(1);
Thread.sleep(3000);
try {
utx.commit();
fail("exception did not occur on commit although transaction timed out");
} catch (Exception expected) {
}
}
use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.
the class TransactionTimeOutDUnitTest method runTest10.
public static void runTest10() {
try {
boolean exceptionOccurred = false;
Context ctx = cache.getJNDIContext();
DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
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();
utx.setTransactionTimeout(1);
Thread.sleep(3000);
try {
utx.rollback();
} catch (Exception e) {
exceptionOccurred = true;
}
if (!exceptionOccurred) {
fail("exception did not occur on rollback although transaction timed out");
}
} catch (Exception e) {
fail("Exception occurred in test Commit due to ", e);
}
}
use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.
the class TransactionTimeOutDUnitTest method runTest8.
public static void runTest8() {
try {
Context ctx = cache.getJNDIContext();
DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
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 newTable1 (id integer)";
Statement sm = conn.createStatement();
sm.execute(sql);
utx.setTransactionTimeout(30);
Thread.sleep(5000);
utx.setTransactionTimeout(20);
utx.setTransactionTimeout(10);
sql = "insert into newTable1 values (1)";
sm.execute(sql);
utx.commit();
sql = "select * from newTable1 where id = 1";
ResultSet rs = sm.executeQuery(sql);
if (!rs.next())
fail("Transaction not committed");
sql = "drop table newTable1";
sm.execute(sql);
sm.close();
conn.close();
} catch (Exception e) {
fail("Exception occurred in test Commit due to ", e);
}
}
use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.
the class TransactionTimeOutDUnitTest method runTest9.
public static void runTest9() {
try {
boolean exceptionOccurred = false;
Context ctx = cache.getJNDIContext();
DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
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 newTable2 (id integer)";
Statement sm = conn.createStatement();
sm.execute(sql);
utx.setTransactionTimeout(30);
sql = "insert into newTable2 values (1)";
sm.execute(sql);
sql = "select * from newTable2 where id = 1";
ResultSet rs = sm.executeQuery(sql);
if (!rs.next())
fail("Transaction not committed");
sql = "drop table newTable2";
sm.execute(sql);
sm.close();
conn.close();
utx.setTransactionTimeout(1);
Thread.sleep(3000);
try {
utx.commit();
} catch (Exception e) {
exceptionOccurred = true;
}
if (!exceptionOccurred) {
fail("exception did not occur on commit although transaction timed out");
}
} catch (Exception e) {
fail("Exception occurred in test Commit due to ", e);
}
}
use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.
the class TransactionTimeOutJUnitTest method test7Commit.
@Test
public void test7Commit() throws Exception {
Context ctx = cache.getJNDIContext();
DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
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 newTable1 (id integer)";
Statement sm = conn.createStatement();
sm.execute(sql);
utx.setTransactionTimeout(30);
Thread.sleep(5000);
utx.setTransactionTimeout(20);
utx.setTransactionTimeout(10);
sql = "insert into newTable1 values (1)";
sm.execute(sql);
utx.commit();
sql = "select * from newTable1 where id = 1";
ResultSet rs = sm.executeQuery(sql);
if (!rs.next()) {
fail("Transaction not committed");
}
sql = "drop table newTable1";
sm.execute(sql);
sm.close();
conn.close();
}
Aggregations