From: Francisco R. <rev...@im...> - 2005-05-20 22:03:04
|
User: reverbel Date: 05/05/20 18:02:45 Added: src/main/org/jboss/test/dtm/test T09DTMXAUnitTestCase.java T10OTSXAUnitTestCase.java Log: Add tests for DTM/OTS and XA. The tests are commented out in build.xml, as they use the Derby database engine, which is not included in the JBoss distribution. To run the XA tests, uncomment T09DTMXAUnitTestCase and T10OTSXAUnitTestCase, copy derby.jar to server/default, go to the testsuite directory, and say 'build.sh dtm-tests'. Revision Changes Path 1.1 date: 2005/05/20 22:02:45; author: reverbel; state: Exp;jbosstest/src/main/org/jboss/test/dtm/test/T09DTMXAUnitTestCase.java Index: T09DTMXAUnitTestCase.java =================================================================== package org.jboss.test.dtm.test; import org.jboss.test.JBossTestCase; import org.jboss.test.dtm.interfaces.FrontEnd; import org.jboss.test.dtm.interfaces.FrontEndHome; import javax.naming.Context; import javax.rmi.PortableRemoteObject; import javax.transaction.RollbackException; import javax.transaction.TransactionRolledbackException; import javax.transaction.UserTransaction; import junit.framework.Test; public class T09DTMXAUnitTestCase extends JBossTestCase { public T09DTMXAUnitTestCase(String name) throws java.io.IOException { super(name); } // Public -------------------------------------------------------- public void testCommittedTx() throws Exception { getLog().debug("+++ testCommittedTx"); Context ctx = getInitialContext(); getLog().debug("Obtain UserTransaction instance"); UserTransaction userTx = (UserTransaction) ctx.lookup("UserTransaction"); getLog().debug("Obtain home interface"); Object objref = ctx.lookup("dtmtest/FrontEndEJB"); FrontEndHome home = (FrontEndHome) PortableRemoteObject.narrow(objref, FrontEndHome.class); getLog().debug("Create FrontEnd bean"); FrontEnd frontEnd = home.create("testCommittedTx"); getLog().debug("Set balances"); userTx.begin(); frontEnd.setBalances(101, 102, 103); userTx.commit(); int balances[]; getLog().debug("Get balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances"); userTx.begin(); frontEnd.addToBalances(100); userTx.commit(); getLog().debug("Check updated balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 201", balances[0] == 201); assertTrue("second balance == 202", balances[1] == 202); assertTrue("third balance == 203", balances[2] == 203); getLog().debug("Remove FrontEnd bean"); frontEnd.remove(); } public void testRolledbackTx() throws Exception { getLog().debug("+++ testRolledbackTx"); Context ctx = getInitialContext(); getLog().debug("Obtain UserTransaction instance"); UserTransaction userTx = (UserTransaction) ctx.lookup("UserTransaction"); getLog().debug("Obtain home interface"); Object objref = ctx.lookup("dtmtest/FrontEndEJB"); FrontEndHome home = (FrontEndHome) PortableRemoteObject.narrow(objref, FrontEndHome.class); getLog().debug("Create FrontEnd bean"); FrontEnd frontEnd = home.create("testRolledbackTx"); getLog().debug("Set balances"); userTx.begin(); frontEnd.setBalances(101, 102, 103); userTx.commit(); int balances[]; getLog().debug("Get balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances and rollback"); userTx.begin(); frontEnd.addToBalances(100); userTx.rollback(); getLog().debug("Check that all balances remain the same"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); frontEnd.remove(); } public void testSetRollbackOnly() throws Exception { getLog().debug("+++ testSetRollbackOnly"); Context ctx = getInitialContext(); getLog().debug("Obtain UserTransaction instance"); UserTransaction userTx = (UserTransaction) ctx.lookup("UserTransaction"); getLog().debug("Obtain home interface"); Object objref = ctx.lookup("dtmtest/FrontEndEJB"); FrontEndHome home = (FrontEndHome) PortableRemoteObject.narrow(objref, FrontEndHome.class); getLog().debug("Create FrontEnd bean"); FrontEnd frontEnd = home.create("testSetRollbackOnly"); getLog().debug("Set balances"); userTx.begin(); frontEnd.setBalances(101, 102, 103); userTx.commit(); int balances[]; getLog().debug("Get balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances, set rollback only and try to commit"); try { userTx.begin(); frontEnd.addToBalances(100); userTx.setRollbackOnly(); userTx.commit(); fail("RollbackException should have been thrown"); } catch (RollbackException e) { getLog().debug("Expected exception: " + e); } getLog().debug("Check that all balances remain the same"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances, set rollback only and try to commit"); try { userTx.begin(); frontEnd.addToBalances(100); userTx.setRollbackOnly(); frontEnd.addToBalances(50); userTx.commit(); fail("Either TransactionRolledbackException or " + "RollbackException should have been thrown"); } catch (TransactionRolledbackException e) { getLog().debug("Expected exception: " + e); userTx.rollback(); // just to dissociate this thread from the // transaction that has already been rolled back } catch (RollbackException e) { getLog().debug("Expected exception: " + e); } getLog().debug("Check that all balances remain the same"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); frontEnd.remove(); } public void testSetRollbackOnlyAtTheFrontEnd() throws Exception { getLog().debug("+++ testSetRollbackOnlyAtTheFrontEnd"); Context ctx = getInitialContext(); getLog().debug("Obtain UserTransaction instance"); UserTransaction userTx = (UserTransaction) ctx.lookup("UserTransaction"); getLog().debug("Obtain home interface"); Object objref = ctx.lookup("dtmtest/FrontEndEJB"); FrontEndHome home = (FrontEndHome) PortableRemoteObject.narrow(objref, FrontEndHome.class); getLog().debug("Create FrontEnd bean"); FrontEnd frontEnd = home.create("testSetRollbackOnlyAtTheFrontEnd"); getLog().debug("Set balances"); userTx.begin(); frontEnd.setBalances(101, 102, 103); userTx.commit(); int balances[]; getLog().debug("Get balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances, set rollback only at the front end, " + "and try to commit"); try { userTx.begin(); frontEnd.addToBalances(100); frontEnd.setRollbackOnly(); frontEnd.addToBalances(50); userTx.commit(); fail("Either TransactionRolledbackException or " + "RollbackException should have been thrown"); } catch (TransactionRolledbackException e) { getLog().debug("Expected exception: " + e); userTx.rollback(); // just to dissociate this thread from the // transaction that has already been rolled back } catch (RollbackException e) { getLog().debug("Expected exception: " + e); } getLog().debug("Check that all balances remain the same"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); frontEnd.remove(); } public void testSetRollbackOnlyAtTheFirstAccount() throws Exception { getLog().debug("+++ testSetRollbackOnlyAtTheFirstAccount"); Context ctx = getInitialContext(); getLog().debug("Obtain UserTransaction instance"); UserTransaction userTx = (UserTransaction) ctx.lookup("UserTransaction"); getLog().debug("Obtain home interface"); Object objref = ctx.lookup("dtmtest/FrontEndEJB"); FrontEndHome home = (FrontEndHome) PortableRemoteObject.narrow(objref, FrontEndHome.class); getLog().debug("Create FrontEnd bean"); FrontEnd frontEnd = home.create("testSetRollbackOnlyAtTheFirstAccount"); getLog().debug("Set balances"); userTx.begin(); frontEnd.setBalances(101, 102, 103); userTx.commit(); int balances[]; getLog().debug("Get balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances, set rollback only at " + "the first account, and try to commit"); try { userTx.begin(); frontEnd.addToBalances(100); frontEnd.tellFirstAccountToSetRollbackOnly(); frontEnd.addToBalances(50); userTx.commit(); fail("Either TransactionRolledbackException or " + "RollbackException should have been thrown"); } catch (TransactionRolledbackException e) { getLog().debug("Expected exception: " + e); userTx.rollback(); // just to dissociate this thread from the // transaction that has already been rolled back } catch (RollbackException e) { getLog().debug("Expected exception: " + e); } getLog().debug("Check that all balances remain the same"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); frontEnd.remove(); } public static Test suite() throws Exception { java.net.URL url = ClassLoader.getSystemResource("host0.jndi.properties"); java.util.Properties host0JndiProps = new java.util.Properties(); host0JndiProps.load(url.openStream()); java.util.Properties systemProps = System.getProperties(); systemProps.putAll(host0JndiProps); System.setProperties(systemProps); return getDeploySetup(T09DTMXAUnitTestCase.class, "dtmfrontend2entities.jar"); } } 1.1 date: 2005/05/20 22:02:45; author: reverbel; state: Exp;jbosstest/src/main/org/jboss/test/dtm/test/T10OTSXAUnitTestCase.java Index: T10OTSXAUnitTestCase.java =================================================================== package org.jboss.test.dtm.test; import org.jboss.test.JBossTestCase; import org.jboss.test.dtm.interfaces.FrontEnd; import org.jboss.test.dtm.interfaces.FrontEndHome; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; import javax.transaction.RollbackException; import javax.transaction.TransactionRolledbackException; import javax.transaction.UserTransaction; import junit.framework.Test; public class T10OTSXAUnitTestCase extends JBossTestCase { // Attributes ---------------------------------------------------- private java.util.Properties jndiProps; // Constructors -------------------------------------------------- public T10OTSXAUnitTestCase(String name) throws java.io.IOException { super(name); java.net.URL url = ClassLoader.getSystemResource("host0.cosnaming.jndi.properties"); jndiProps = new java.util.Properties(); jndiProps.load(url.openStream()); } // Override getInitialContext() ---------------------------------- protected InitialContext getInitialContext() throws Exception { return new InitialContext(jndiProps); } // Public -------------------------------------------------------- public void testCommittedTx() throws Exception { getLog().debug("+++ testCommittedTx"); Context ctx = getInitialContext(); getLog().debug("Obtain UserTransaction instance"); UserTransaction userTx = (UserTransaction) ctx.lookup("UserTransaction"); getLog().debug("Obtain home interface"); Object objref = ctx.lookup("dtmiioptest/FrontEndEJB"); FrontEndHome home = (FrontEndHome) PortableRemoteObject.narrow(objref, FrontEndHome.class); getLog().debug("Create FrontEnd bean"); FrontEnd frontEnd = home.create("testCommittedTx"); getLog().debug("Set balances"); userTx.begin(); frontEnd.setBalances(101, 102, 103); userTx.commit(); int balances[]; getLog().debug("Get balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances"); userTx.begin(); frontEnd.addToBalances(100); userTx.commit(); getLog().debug("Check updated balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 201", balances[0] == 201); assertTrue("second balance == 202", balances[1] == 202); assertTrue("third balance == 203", balances[2] == 203); getLog().debug("Remove FrontEnd bean"); frontEnd.remove(); } public void testRolledbackTx() throws Exception { getLog().debug("+++ testRolledbackTx"); Context ctx = getInitialContext(); getLog().debug("Obtain UserTransaction instance"); UserTransaction userTx = (UserTransaction) ctx.lookup("UserTransaction"); getLog().debug("Obtain home interface"); Object objref = ctx.lookup("dtmiioptest/FrontEndEJB"); FrontEndHome home = (FrontEndHome) PortableRemoteObject.narrow(objref, FrontEndHome.class); getLog().debug("Create FrontEnd bean"); FrontEnd frontEnd = home.create("testRolledbackTx"); getLog().debug("Set balances"); userTx.begin(); frontEnd.setBalances(101, 102, 103); userTx.commit(); int balances[]; getLog().debug("Get balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances and rollback"); userTx.begin(); frontEnd.addToBalances(100); userTx.rollback(); getLog().debug("Check that all balances remain the same"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); frontEnd.remove(); } public void testSetRollbackOnly() throws Exception { getLog().debug("+++ testSetRollbackOnly"); Context ctx = getInitialContext(); getLog().debug("Obtain UserTransaction instance"); UserTransaction userTx = (UserTransaction) ctx.lookup("UserTransaction"); getLog().debug("Obtain home interface"); Object objref = ctx.lookup("dtmiioptest/FrontEndEJB"); FrontEndHome home = (FrontEndHome) PortableRemoteObject.narrow(objref, FrontEndHome.class); getLog().debug("Create FrontEnd bean"); FrontEnd frontEnd = home.create("testSetRollbackOnly"); getLog().debug("Set balances"); userTx.begin(); frontEnd.setBalances(101, 102, 103); userTx.commit(); int balances[]; getLog().debug("Get balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances, set rollback only and try to commit"); try { userTx.begin(); frontEnd.addToBalances(100); userTx.setRollbackOnly(); userTx.commit(); fail("RollbackException should have been thrown"); } catch (RollbackException e) { getLog().debug("Expected exception: " + e); } getLog().debug("Check that all balances remain the same"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances, set rollback only and try to commit"); try { userTx.begin(); frontEnd.addToBalances(100); userTx.setRollbackOnly(); frontEnd.addToBalances(50); userTx.commit(); fail("Either TransactionRolledbackException or " + "RollbackException should have been thrown"); } catch (TransactionRolledbackException e) { getLog().debug("Expected exception: " + e); userTx.rollback(); // just to dissociate this thread from the // transaction that has already been rolled back } catch (RollbackException e) { getLog().debug("Expected exception: " + e); } getLog().debug("Check that all balances remain the same"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); frontEnd.remove(); } public void testSetRollbackOnlyAtTheFrontEnd() throws Exception { getLog().debug("+++ testSetRollbackOnlyAtTheFrontEnd"); Context ctx = getInitialContext(); getLog().debug("Obtain UserTransaction instance"); UserTransaction userTx = (UserTransaction) ctx.lookup("UserTransaction"); getLog().debug("Obtain home interface"); Object objref = ctx.lookup("dtmiioptest/FrontEndEJB"); FrontEndHome home = (FrontEndHome) PortableRemoteObject.narrow(objref, FrontEndHome.class); getLog().debug("Create FrontEnd bean"); FrontEnd frontEnd = home.create("testSetRollbackOnlyAtTheFrontEnd"); getLog().debug("Set balances"); userTx.begin(); frontEnd.setBalances(101, 102, 103); userTx.commit(); int balances[]; getLog().debug("Get balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances, set rollback only at the front end, " + "and try to commit"); try { userTx.begin(); frontEnd.addToBalances(100); frontEnd.setRollbackOnly(); frontEnd.addToBalances(50); userTx.commit(); fail("Either TransactionRolledbackException or " + "RollbackException should have been thrown"); } catch (TransactionRolledbackException e) { getLog().debug("Expected exception: " + e); userTx.rollback(); // just to dissociate this thread from the // transaction that has already been rolled back } catch (RollbackException e) { getLog().debug("Expected exception: " + e); } getLog().debug("Check that all balances remain the same"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); frontEnd.remove(); } public void testSetRollbackOnlyAtTheFirstAccount() throws Exception { getLog().debug("+++ testSetRollbackOnlyAtTheFirstAccount"); Context ctx = getInitialContext(); getLog().debug("Obtain UserTransaction instance"); UserTransaction userTx = (UserTransaction) ctx.lookup("UserTransaction"); getLog().debug("Obtain home interface"); Object objref = ctx.lookup("dtmiioptest/FrontEndEJB"); FrontEndHome home = (FrontEndHome) PortableRemoteObject.narrow(objref, FrontEndHome.class); getLog().debug("Create FrontEnd bean"); FrontEnd frontEnd = home.create("testSetRollbackOnlyAtTheFirstAccount"); getLog().debug("Set balances"); userTx.begin(); frontEnd.setBalances(101, 102, 103); userTx.commit(); int balances[]; getLog().debug("Get balances"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); getLog().debug("Update balances, set rollback only at " + "the first account, and try to commit"); try { userTx.begin(); frontEnd.addToBalances(100); frontEnd.tellFirstAccountToSetRollbackOnly(); frontEnd.addToBalances(50); userTx.commit(); fail("Either TransactionRolledbackException or " + "RollbackException should have been thrown"); } catch (TransactionRolledbackException e) { getLog().debug("Expected exception: " + e); userTx.rollback(); // just to dissociate this thread from the // transaction that has already been rolled back } catch (RollbackException e) { getLog().debug("Expected exception: " + e); } getLog().debug("Check that all balances remain the same"); userTx.begin(); balances = frontEnd.getBalances(); userTx.commit(); assertTrue("first balance == 101", balances[0] == 101); assertTrue("second balance == 102", balances[1] == 102); assertTrue("third balance == 103", balances[2] == 103); frontEnd.remove(); } public static Test suite() throws Exception { java.net.URL url = ClassLoader.getSystemResource("host0.jndi.properties"); java.util.Properties host0JndiProps = new java.util.Properties(); host0JndiProps.load(url.openStream()); java.util.Properties systemProps = System.getProperties(); systemProps.putAll(host0JndiProps); System.setProperties(systemProps); return getDeploySetup(T10OTSXAUnitTestCase.class, "dtmfrontend2entitiesiiop.jar"); } } |