use of javax.transaction.UserTransaction in project geode by apache.
the class ExceptionsDUnitTest method runTest3.
public static void runTest3() throws Exception {
boolean exceptionOccurred = false;
try {
Context ctx = cache.getJNDIContext();
DataSource ds1 = null;
DataSource ds2 = null;
ds1 = (DataSource) ctx.lookup("java:/XAPooledDataSource");
ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
ds2.getConnection();
UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
utx.begin();
utx.setTransactionTimeout(2);
ds1.getConnection();
Thread.sleep(4000);
try {
utx.commit();
} catch (Exception e) {
exceptionOccurred = true;
}
if (!exceptionOccurred)
fail("Exception (Transaction-Time-Out)did not occur although was supposed" + "to occur");
} catch (Exception e) {
fail("failed in runTest3 due to " + e);
}
}
use of javax.transaction.UserTransaction in project geode by apache.
the class ExceptionsDUnitTest method runTest2.
public static void runTest2() throws Exception {
boolean exceptionOccurred1 = false;
boolean exceptionOccurred2 = false;
try {
Context ctx = cache.getJNDIContext();
DataSource ds1 = null;
DataSource ds2 = null;
ds1 = (DataSource) ctx.lookup("java:/XAPooledDataSource");
ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
ds2.getConnection();
ds1.getConnection();
ds1.getConnection();
ds1.getConnection();
ds1.getConnection();
ds1.getConnection();
UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
utx.begin();
try {
ds1.getConnection();
Thread.sleep(8000);
} catch (SQLException e) {
exceptionOccurred1 = true;
}
try {
utx.commit();
} catch (Exception e) {
exceptionOccurred2 = true;
}
if (!exceptionOccurred1)
fail("Exception (Login-Time-Out)did not occur although was supposed" + "to occur");
if (exceptionOccurred2)
fail("Exception did occur on commit, although was not supposed" + "to occur");
} catch (Exception e) {
fail("failed in runTest2 due to " + e);
}
}
use of javax.transaction.UserTransaction in project geode by apache.
the class TransactionTimeOutJUnitTest method test1One.
@Test
public void test1One() throws Exception {
UserTransaction utx = new UserTransactionImpl();
utx.begin();
Thread.sleep(2000);
utx.setTransactionTimeout(2);
utx.setTransactionTimeout(200);
utx.setTransactionTimeout(3);
Thread.sleep(5000);
// utx.commit();
}
use of javax.transaction.UserTransaction in project geode by apache.
the class TransactionTimeOutJUnitTest method test2SetTransactionTimeOut.
@Test
public void test2SetTransactionTimeOut() throws Exception {
UserTransaction utx = new UserTransactionImpl();
utx.begin();
utx.setTransactionTimeout(2);
System.out.println("Going to sleep");
Thread.sleep(6000);
utx.begin();
utx.commit();
}
use of javax.transaction.UserTransaction 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) {
}
}
Aggregations