VMware Cloud Community
admin
Immortal
Immortal

hq r1472 - trunk/src/org/hyperic/hq/test

0 Kudos
3 Replies
jtravis_hyperic
Hot Shot
Hot Shot

Ok, I think these changes have probably resolved our issues with
MockEJB and transactions.

So, how we probably start to do a fair evaluation of Hibernate 3.2.

Please don't add any flushes to your code unless your dealing with
direct SQL. Flushes that you've added for ghetto old-skool MockEJB
should be removed.

-- Jon


On Nov 22, 2006, at 3:45 PM, jtravis@hyperic.com wrote:

> Author: jtravis
> Date: 2006-11-22 15:45:02 -0800 (Wed, 22 Nov 2006)
> New Revision: 1472
> URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=1472
>
> Added:
> trunk/src/org/hyperic/hq/test/SessionBeanPointcut.java
> Modified:
> trunk/src/org/hyperic/hq/test/HQEJBTestBase.java
> trunk/src/org/hyperic/hq/test/MockBeanTestBase.java
> Log:
> Use aspects to tell MockEJB that we need a transaction for all
> session bean calls
>
> Modified: trunk/src/org/hyperic/hq/test/HQEJBTestBase.java
> ===================================================================
> --- trunk/src/org/hyperic/hq/test/HQEJBTestBase.java 2006-11-22
> 23:42:11 UTC (rev 1471)
> +++ trunk/src/org/hyperic/hq/test/HQEJBTestBase.java 2006-11-22
> 23:45:02 UTC (rev 1472)
> @@ -157,17 +157,28 @@
> throws Exception
> {
> Transaction t = _session.beginTransaction();
> + boolean success = false;
> +
> try {
> block.run();
> + success = true;
> } finally {
> - t.commit();
> + if (success == false) {
> + t.rollback();
> + } else {
> + t.commit();
> + }
> }
> }
>
> public void tearDown() throws Exception {
> - _session.disconnect();
> - ManagedSessionContext.unbind(Util.getSessionFactory());
> - _session = null;
> + try {
> + _session.flush();
> + } finally {
> + _session.disconnect();
> + ManagedSessionContext.unbind(Util.getSessionFactory());
> + _session = null;
> + }
> }
>
> protected AuthzSubjectValue getOverlord()
>
> Modified: trunk/src/org/hyperic/hq/test/MockBeanTestBase.java
> ===================================================================
> --- trunk/src/org/hyperic/hq/test/MockBeanTestBase.java 2006-11-22
> 23:42:11 UTC (rev 1471)
> +++ trunk/src/org/hyperic/hq/test/MockBeanTestBase.java 2006-11-22
> 23:45:02 UTC (rev 1472)
> @@ -14,29 +14,38 @@
> */
> package org.hyperic.hq.test;
>
> -import com.mockrunner.mock.ejb.MockUserTransaction;
> +import java.lang.reflect.Method;
>
> import javax.jms.MessageListener;
> import javax.jms.Queue;
> import javax.jms.QueueConnectionFactory;
> import javax.naming.Context;
> import javax.naming.InitialContext;
> -import javax.naming.NamingException;
> import javax.sql.DataSource;
> +import javax.transaction.Status;
>
> -import org.hyperic.dao.DAOFactory;
> +import oracle.jdbc.pool.OracleDataSource;
>
> +import org.hyperic.util.jdbc.LoggingTransaction;
> import org.mockejb.MDBDescriptor;
> import org.mockejb.MockContainer;
> import org.mockejb.OptionalCactusTestCase;
> import org.mockejb.SessionBeanDescriptor;
> +import org.mockejb.TransactionManager;
> +import org.mockejb.TransactionPolicy;
> +import org.mockejb.interceptor.Aspect;
> +import org.mockejb.interceptor.AspectSystem;
> +import org.mockejb.interceptor.AspectSystemFactory;
> +import org.mockejb.interceptor.ClassPatternPointcut;
> +import org.mockejb.interceptor.InvocationContext;
> +import org.mockejb.interceptor.Pointcut;
> import org.mockejb.jms.MockQueue;
> import org.mockejb.jms.QueueConnectionFactoryImpl;
> import org.mockejb.jndi.MockContextFactory;
> -
> import org.postgresql.jdbc2.optional.SimpleDataSource;
> -import oracle.jdbc.pool.OracleDataSource;
>
> +import com.mockrunner.mock.ejb.MockUserTransaction;
> +
> /**
> * Abstract base class for all JUnit tests that use Mock EJB
> * to test EJBs. Factors out common features to allow them to
> @@ -168,10 +177,9 @@
> _dsMapping);
> }
> }
> -
> +
> /**
> * Initialising the context and mock container
> - * @throws NamingException if the initialisation cannot be
> completed
> */
> public void initialiseContainer() throws Exception {
> /* We want to use MockEJB JNDI provider only if we run
> outside of
> @@ -190,17 +198,23 @@
> // Create an instance of the MockContainer
> _container = new MockContainer(_context);
>
> + AspectSystem sys = AspectSystemFactory.getAspectSystem();
> + sys.addFirst(new SessionBeanPointcut(),
> + new TransactionManager
> (TransactionPolicy.REQUIRED));
> +
> +
> if (!isRunningOnServer()) {
> // bind jta transaction
> // we use MockTransaction outside of the app server
> MockUserTransaction mockTransaction = new
> MockUserTransaction();
> - _context.rebind("javax.transaction.UserTransaction",
> mockTransaction);
> + _context.rebind("javax.transaction.UserTransaction",
> + mockTransaction);
> // bind datasource
> DataSource ds = getDataSource();
> _context.rebind("java:/HypericDS", ds);
> }
> }
> -
> +
> /**
> * Deploy the session bean that has the specified remote interface
> * class. The bean must have a remote interface and must
> follow the
>
> Added: trunk/src/org/hyperic/hq/test/SessionBeanPointcut.java
> ===================================================================
> --- trunk/src/org/hyperic/hq/test/
> SessionBeanPointcut.java (rev 0)
> +++ trunk/src/org/hyperic/hq/test/SessionBeanPointcut.java
> 2006-11-22 23:45:02 UTC (rev 1472)
> @@ -0,0 +1,34 @@
> +package org.hyperic.hq.test;
> +
> +import java.lang.reflect.Method;
> +
> +import org.mockejb.interceptor.Pointcut;
> +
> +/**
> + * We use this pointcut to tell MockEJB that we need to intercept
> method
> + * calls made to our session beans. Fortunately we have a nice
> naming
> + * convention for everything.
> + */
> +public class SessionBeanPointcut
> + implements Pointcut
> +{
> + public SessionBeanPointcut() {
> + }
> +
> + public boolean matchesJointpoint(Method method) {
> + Class owner = method.getDeclaringClass();
> +
> + return owner.getName().indexOf("EJBImpl") != -1;
> + }
> +
> + public boolean equals(Object o){
> + if (o == null || o instanceof SessionBeanPointcut == false)
> + return false;
> +
> + return true;
> + }
> +
> + public int hashCode() {
> + return super.hashCode();
> + }
> +}
>


0 Kudos
jtravis_hyperic
Hot Shot
Hot Shot

Ok, so it's not all fixed. There are still problems with Hibernate
session flushing and the Mock transactions.

This is at least the 3rd day that I've devoted to working on this
test framework. Even if I get this part working, I see other parts
that are going to fail (other threads needing to do stuff in the same
transaction, etc.)

So, that leaves us with in-container Cactus-barfo-stylee tests.
Anyone currently doing this? I know dev-time will be increased by
quite a bit to run these tests, but I need to move onto other things.

-- Jon




On Nov 22, 2006, at 5:02 PM, Jon Travis wrote:

> Ok, I think these changes have probably resolved our issues with
> MockEJB and transactions.
>
> So, how we probably start to do a fair evaluation of Hibernate 3.2.
>
> Please don't add any flushes to your code unless your dealing with
> direct SQL. Flushes that you've added for ghetto old-skool MockEJB
> should be removed.
>
> -- Jon
>
>
> On Nov 22, 2006, at 3:45 PM, jtravis@hyperic.com wrote:
>
>> Author: jtravis
>> Date: 2006-11-22 15:45:02 -0800 (Wed, 22 Nov 2006)
>> New Revision: 1472
>> URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=1472
>>
>> Added:
>> trunk/src/org/hyperic/hq/test/SessionBeanPointcut.java
>> Modified:
>> trunk/src/org/hyperic/hq/test/HQEJBTestBase.java
>> trunk/src/org/hyperic/hq/test/MockBeanTestBase.java
>> Log:
>> Use aspects to tell MockEJB that we need a transaction for all
>> session bean calls
>>
>> Modified: trunk/src/org/hyperic/hq/test/HQEJBTestBase.java
>> ===================================================================
>> --- trunk/src/org/hyperic/hq/test/HQEJBTestBase.java 2006-11-22
>> 23:42:11 UTC (rev 1471)
>> +++ trunk/src/org/hyperic/hq/test/HQEJBTestBase.java 2006-11-22
>> 23:45:02 UTC (rev 1472)
>> @@ -157,17 +157,28 @@
>> throws Exception
>> {
>> Transaction t = _session.beginTransaction();
>> + boolean success = false;
>> +
>> try {
>> block.run();
>> + success = true;
>> } finally {
>> - t.commit();
>> + if (success == false) {
>> + t.rollback();
>> + } else {
>> + t.commit();
>> + }
>> }
>> }
>>
>> public void tearDown() throws Exception {
>> - _session.disconnect();
>> - ManagedSessionContext.unbind(Util.getSessionFactory());
>> - _session = null;
>> + try {
>> + _session.flush();
>> + } finally {
>> + _session.disconnect();
>> + ManagedSessionContext.unbind(Util.getSessionFactory());
>> + _session = null;
>> + }
>> }
>>
>> protected AuthzSubjectValue getOverlord()
>>
>> Modified: trunk/src/org/hyperic/hq/test/MockBeanTestBase.java
>> ===================================================================
>> --- trunk/src/org/hyperic/hq/test/MockBeanTestBase.java 2006-11-22
>> 23:42:11 UTC (rev 1471)
>> +++ trunk/src/org/hyperic/hq/test/MockBeanTestBase.java 2006-11-22
>> 23:45:02 UTC (rev 1472)
>> @@ -14,29 +14,38 @@
>> */
>> package org.hyperic.hq.test;
>>
>> -import com.mockrunner.mock.ejb.MockUserTransaction;
>> +import java.lang.reflect.Method;
>>
>> import javax.jms.MessageListener;
>> import javax.jms.Queue;
>> import javax.jms.QueueConnectionFactory;
>> import javax.naming.Context;
>> import javax.naming.InitialContext;
>> -import javax.naming.NamingException;
>> import javax.sql.DataSource;
>> +import javax.transaction.Status;
>>
>> -import org.hyperic.dao.DAOFactory;
>> +import oracle.jdbc.pool.OracleDataSource;
>>
>> +import org.hyperic.util.jdbc.LoggingTransaction;
>> import org.mockejb.MDBDescriptor;
>> import org.mockejb.MockContainer;
>> import org.mockejb.OptionalCactusTestCase;
>> import org.mockejb.SessionBeanDescriptor;
>> +import org.mockejb.TransactionManager;
>> +import org.mockejb.TransactionPolicy;
>> +import org.mockejb.interceptor.Aspect;
>> +import org.mockejb.interceptor.AspectSystem;
>> +import org.mockejb.interceptor.AspectSystemFactory;
>> +import org.mockejb.interceptor.ClassPatternPointcut;
>> +import org.mockejb.interceptor.InvocationContext;
>> +import org.mockejb.interceptor.Pointcut;
>> import org.mockejb.jms.MockQueue;
>> import org.mockejb.jms.QueueConnectionFactoryImpl;
>> import org.mockejb.jndi.MockContextFactory;
>> -
>> import org.postgresql.jdbc2.optional.SimpleDataSource;
>> -import oracle.jdbc.pool.OracleDataSource;
>>
>> +import com.mockrunner.mock.ejb.MockUserTransaction;
>> +
>> /**
>> * Abstract base class for all JUnit tests that use Mock EJB
>> * to test EJBs. Factors out common features to allow them to
>> @@ -168,10 +177,9 @@
>> _dsMapping);
>> }
>> }
>> -
>> +
>> /**
>> * Initialising the context and mock container
>> - * @throws NamingException if the initialisation cannot be
>> completed
>> */
>> public void initialiseContainer() throws Exception {
>> /* We want to use MockEJB JNDI provider only if we run
>> outside of
>> @@ -190,17 +198,23 @@
>> // Create an instance of the MockContainer
>> _container = new MockContainer(_context);
>>
>> + AspectSystem sys = AspectSystemFactory.getAspectSystem();
>> + sys.addFirst(new SessionBeanPointcut(),
>> + new TransactionManager
>> (TransactionPolicy.REQUIRED));
>> +
>> +
>> if (!isRunningOnServer()) {
>> // bind jta transaction
>> // we use MockTransaction outside of the app server
>> MockUserTransaction mockTransaction = new
>> MockUserTransaction();
>> - _context.rebind("javax.transaction.UserTransaction",
>> mockTransaction);
>> + _context.rebind("javax.transaction.UserTransaction",
>> + mockTransaction);
>> // bind datasource
>> DataSource ds = getDataSource();
>> _context.rebind("java:/HypericDS", ds);
>> }
>> }
>> -
>> +
>> /**
>> * Deploy the session bean that has the specified remote
>> interface
>> * class. The bean must have a remote interface and must
>> follow the
>>
>> Added: trunk/src/org/hyperic/hq/test/SessionBeanPointcut.java
>> ===================================================================
>> --- trunk/src/org/hyperic/hq/test/
>> SessionBeanPointcut.java (rev 0)
>> +++ trunk/src/org/hyperic/hq/test/SessionBeanPointcut.java
>> 2006-11-22 23:45:02 UTC (rev 1472)
>> @@ -0,0 +1,34 @@
>> +package org.hyperic.hq.test;
>> +
>> +import java.lang.reflect.Method;
>> +
>> +import org.mockejb.interceptor.Pointcut;
>> +
>> +/**
>> + * We use this pointcut to tell MockEJB that we need to intercept
>> method
>> + * calls made to our session beans. Fortunately we have a nice
>> naming
>> + * convention for everything.
>> + */
>> +public class SessionBeanPointcut
>> + implements Pointcut
>> +{
>> + public SessionBeanPointcut() {
>> + }
>> +
>> + public boolean matchesJointpoint(Method method) {
>> + Class owner = method.getDeclaringClass();
>> +
>> + return owner.getName().indexOf("EJBImpl") != -1;
>> + }
>> +
>> + public boolean equals(Object o){
>> + if (o == null || o instanceof SessionBeanPointcut == false)
>> + return false;
>> +
>> + return true;
>> + }
>> +
>> + public int hashCode() {
>> + return super.hashCode();
>> + }
>> +}
>>
>


0 Kudos
admin
Immortal
Immortal




The MockEJB framework supports in-container testing.  HQ is currently setup to support it.  The current issues

are that

 

1) HQEJBTestBase need to be modified to be Cactus aware

2) unit tests probably need to tweeked as well.

 

- Young





From: hq-dev-bounces@hyperic.org on behalf of Jon Travis
Sent: Mon 11/27/2006 2:34 PM
To: Jon Travis
Cc: hq-dev@hyperic.org
Subject: Re: hq r1472 - trunk/src/org/hyperic/hq/test



Ok, so it's not all fixed.  There are still problems with Hibernate 
session flushing and the Mock transactions.

This is at least the 3rd day that I've devoted to working on this 
test framework.  Even if I get this part working, I see other parts 
that are going to fail (other threads needing to do stuff in the same 
transaction, etc.)

So, that leaves us with in-container Cactus-barfo-stylee tests.  
Anyone currently doing this?  I know dev-time will be increased by 
quite a bit to run these tests, but I need to move onto other things.

-- Jon




On Nov 22, 2006, at 5:02 PM, Jon Travis wrote:

> Ok, I think these changes have probably resolved our issues with 
> MockEJB and transactions.
>
> So, how we probably start to do a fair evaluation of Hibernate 3.2.
>
> Please don't add any flushes to your code unless your dealing with 
> direct SQL.  Flushes that you've added for ghetto old-skool MockEJB 
> should be removed.
>
> -- Jon
>
>
> On Nov 22, 2006, at 3:45 PM, jtravis@hyperic.com wrote:
>
>> Author: jtravis
>> Date: 2006-11-22 15:45:02 -0800 (Wed, 22 Nov 2006)
>> New Revision: 1472
>> URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=1472
>>
>> Added:
>>    trunk/src/org/hyperic/hq/test/SessionBeanPointcut.java
>> Modified:
>>    trunk/src/org/hyperic/hq/test/HQEJBTestBase.java
>>    trunk/src/org/hyperic/hq/test/MockBeanTestBase.java
>> Log:
>> Use aspects to tell MockEJB that we need a transaction for all 
>> session bean calls
>>
>> Modified: trunk/src/org/hyperic/hq/test/HQEJBTestBase.java
>> ===================================================================
>> --- trunk/src/org/hyperic/hq/test/HQEJBTestBase.java 2006-11-22 
>> 23:42:11 UTC (rev 1471)
>> +++ trunk/src/org/hyperic/hq/test/HQEJBTestBase.java 2006-11-22 
>> 23:45:02 UTC (rev 1472)
>> @@ -157,17 +157,28 @@
>>          throws Exception
>>      {
>>          Transaction t = _session.beginTransaction();
>> +        boolean success = false;
>> +
>>          try {
>>              block.run();
>> +            success = true;
>>          } finally {
>> -            t.commit();
>> +            if (success == false) {
>> +                t.rollback();
>> +            } else {
>> +                t.commit();
>> +            }
>>          }
>>      }
>>
>>      public void tearDown() throws Exception {
>> -        _session.disconnect();
>> -        ManagedSessionContext.unbind(Util.getSessionFactory());
>> -        _session = null;
>> +        try {
>> +            _session.flush();
>> +        } finally {
>> +            _session.disconnect();
>> +            ManagedSessionContext.unbind(Util.getSessionFactory());
>> +            _session = null;
>> +        }
>>      }
>>
>>      protected AuthzSubjectValue getOverlord()
>>
>> Modified: trunk/src/org/hyperic/hq/test/MockBeanTestBase.java
>> ===================================================================
>> --- trunk/src/org/hyperic/hq/test/MockBeanTestBase.java      2006-11-22 
>> 23:42:11 UTC (rev 1471)
>> +++ trunk/src/org/hyperic/hq/test/MockBeanTestBase.java      2006-11-22 
>> 23:45:02 UTC (rev 1472)
>> @@ -14,29 +14,38 @@
>>   */
>>  package org.hyperic.hq.test;
>>
>> -import com.mockrunner.mock.ejb.MockUserTransaction;
>> +import java.lang.reflect.Method;
>>
>>  import javax.jms.MessageListener;
>>  import javax.jms.Queue;
>>  import javax.jms.QueueConnectionFactory;
>>  import javax.naming.Context;
>>  import javax.naming.InitialContext;
>> -import javax.naming.NamingException;
>>  import javax.sql.DataSource;
>> +import javax.transaction.Status;
>>
>> -import org.hyperic.dao.DAOFactory;
>> +import oracle.jdbc.pool.OracleDataSource;
>>
>> +import org.hyperic.util.jdbc.LoggingTransaction;
>>  import org.mockejb.MDBDescriptor;
>>  import org.mockejb.MockContainer;
>>  import org.mockejb.OptionalCactusTestCase;
>>  import org.mockejb.SessionBeanDescriptor;
>> +import org.mockejb.TransactionManager;
>> +import org.mockejb.TransactionPolicy;
>> +import org.mockejb.interceptor.Aspect;
>> +import org.mockejb.interceptor.AspectSystem;
>> +import org.mockejb.interceptor.AspectSystemFactory;
>> +import org.mockejb.interceptor.ClassPatternPointcut;
>> +import org.mockejb.interceptor.InvocationContext;
>> +import org.mockejb.interceptor.Pointcut;
>>  import org.mockejb.jms.MockQueue;
>>  import org.mockejb.jms.QueueConnectionFactoryImpl;
>>  import org.mockejb.jndi.MockContextFactory;
>> -
>>  import org.postgresql.jdbc2.optional.SimpleDataSource;
>> -import oracle.jdbc.pool.OracleDataSource;
>>
>> +import com.mockrunner.mock.ejb.MockUserTransaction;
>> +
>>  /**
>>   * Abstract base class for all JUnit tests that use Mock EJB
>>   * to test EJBs.  Factors out common features to allow them to
>> @@ -168,10 +177,9 @@
>>                                                 _dsMapping);
>>          }
>>      }
>> -
>> +
>>      /**
>>       * Initialising the context and mock container
>> -     * @throws NamingException if the initialisation cannot be 
>> completed
>>       */
>>      public void initialiseContainer() throws Exception {
>>          /* We want to use MockEJB JNDI provider only if we run 
>> outside of
>> @@ -190,17 +198,23 @@
>>          // Create an instance of the MockContainer
>>          _container = new MockContainer(_context);
>>
>> +        AspectSystem sys = AspectSystemFactory.getAspectSystem();
>> +        sys.addFirst(new SessionBeanPointcut(),
>> +                     new TransactionManager
>> (TransactionPolicy.REQUIRED));
>> +
>> +
>>          if (!isRunningOnServer()) {
>>              // bind jta transaction
>>              // we use MockTransaction outside of the app server
>>              MockUserTransaction mockTransaction = new 
>> MockUserTransaction();
>> -            _context.rebind("javax.transaction.UserTransaction", 
>> mockTransaction);
>> +            _context.rebind("javax.transaction.UserTransaction",
>> +                            mockTransaction);
>>              // bind datasource
>>              DataSource ds = getDataSource();
>>              _context.rebind("java:/HypericDS", ds);
>>          }
>>      }
>> -
>> +
>>     /**
>>      * Deploy the session bean that has the specified remote 
>> interface
>>      * class.  The bean must have a remote interface and must 
>> follow the
>>
>> Added: trunk/src/org/hyperic/hq/test/SessionBeanPointcut.java
>> ===================================================================
>> --- trunk/src/org/hyperic/hq/test/
>> SessionBeanPointcut.java                             (rev 0)
>> +++ trunk/src/org/hyperic/hq/test/SessionBeanPointcut.java   
>> 2006-11-22 23:45:02 UTC (rev 1472)
>> @@ -0,0 +1,34 @@
>> +package org.hyperic.hq.test;
>> +
>> +import java.lang.reflect.Method;
>> +
>> +import org.mockejb.interceptor.Pointcut;
>> +
>> +/**
>> + * We use this pointcut to tell MockEJB that we need to intercept 
>> method
>> + * calls made to our session beans.  Fortunately we have a nice 
>> naming
>> + * convention for everything.
>> + */
>> +public class SessionBeanPointcut
>> +    implements Pointcut
>> +{
>> +    public SessionBeanPointcut() {
>> +    }
>> +
>> +    public boolean matchesJointpoint(Method method) {
>> +        Class owner = method.getDeclaringClass();
>> +
>> +        return owner.getName().indexOf("EJBImpl") != -1;
>> +    }
>> +
>> +    public boolean equals(Object o){
>> +        if (o == null || o instanceof SessionBeanPointcut == false)
>> +            return false;
>> +
>> +        return true;
>> +    }
>> +
>> +    public int hashCode() {
>> +        return super.hashCode();
>> +    }
>> +}
>>
>


0 Kudos