public static void runTest3() throws Exception { boolean exceptionOccured = 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) { exceptionOccured = true; } if (!exceptionOccured) fail("Exception (Transaction-Time-Out)did not occur although was supposed" + "to occur"); } catch (Exception e) { fail("failed in runTest3 due to " + e); } }
public static void runTest1() throws Exception { boolean exceptionOccured = 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 = (DataSource) ctx.lookup("java:/XAPooledDataSource"); UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction"); utx.begin(); ds1.getConnection(); Thread.sleep(8000); try { utx.commit(); } catch (Exception e) { exceptionOccured = true; } if (!exceptionOccured) fail("Exception did not occur on commit although was supposed" + "occur"); } catch (Exception e) { getLogWriter().fine("Exception caught in runTest1 due to : " + e); fail("failed in runTest1 due to " + e); } }
public static void runTest2() throws Exception { boolean exceptionOccured1 = false; boolean exceptionOccured2 = 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) { exceptionOccured1 = true; } try { utx.commit(); } catch (Exception e) { exceptionOccured2 = true; } if (!exceptionOccured1) fail("Exception (Login-Time-Out)did not occur although was supposed" + "to occur"); if (exceptionOccured2) fail("Exception did occur on commit, although was not supposed" + "to occur"); } catch (Exception e) { fail("failed in runTest2 due to " + e); } }