tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luke McCollum <luke.mccol...@sacramentopress.com>
Subject Unit Testing Transactions ... what the?
Date Fri, 23 Apr 2010 18:51:13 GMT
So I'm attempting to get some unit tests running using Open EJB and Hibernate. I had planned
on rolling back transactions after running unit tests, but for whatever reason, transactions
don't roll back at all. I set up a dead simple test class to extend and ended up making even
more dead simple to try to test transactions. Still can't get it going. Here's the class:

public class AbstractEJBIntegrationTester {

    protected static InitialContext context;
    protected static DeploymentInitializationService deploymentInitializationService;
    private static UserTransaction userTransaction;


    @BeforeClass
    public static void before() throws Exception {
        System.setProperty("hibernate.hbm2ddl.auto", "create");
        System.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
        System.setProperty("openejb.logger.external", "true");
        Properties properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
        URL config = AbstractEJBIntegrationTester.class.getClassLoader().getResource("META-INF/openejb-test.xml");
        properties.setProperty("openejb.configuration", config.toExternalForm());
        context = new InitialContext(properties);
        userTransaction = (UserTransaction)context.lookup("java:comp/UserTransaction");
        userTransaction.begin();
        deploymentInitializationService = (DeploymentInitializationService) context
                .lookup("DeploymentInitializationServiceBean");
        deploymentInitializationService.runAll();
        userTransaction.rollback();
    }
    
    @Test
    public void noop() {
        assertTrue(true);
    }
    
}

Open EJB loads great, everything is created and runs properly...but my transaction never rolls
back! I've gone so far as to turn on trace logging for all of the components, but Hibernate,
Open EJB, and Geronimo all tell me that a transaction is being opened, joined, then rolled
back successfully. For completeness, here is my openejb-test.xml file referred to above:

<?xml version="1.0" encoding="UTF-8"?>
<openejb>
	<SecurityService id="Default Security Service" />
	<TransactionManager id="Default Transaction Manager" />
	<Resource id="mysql_managed" type="DataSource">
		JdbcDriver com.mysql.jdbc.Driver
		JdbcUrl jdbc:mysql://localhost/testing
		UserName root
		JtaManaged true
	</Resource>
	<Resource id="Default JMS Resource Adapter" type="ActiveMQResourceAdapter" />
	<Resource id="jms/connectionFactory" type="javax.jms.ConnectionFactory" />
	<Resource id="Default Queue Connection Factory" type="QueueConnectionFactory" />
	<Resource id="Default Topic Connection Factory" type="TopicConnectionFactory" />
	<Resource id="jms/myQueue" type="javax.jms.Queue" />
</openejb>


I've been trying to get it working with HSQLDB instead of MySQL (they are unit tests after
all), but I decided just to experiment with another DBMS to rule that out. HSQLDB has the
exact same problem.
Mime
View raw message