You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Dain Sundstrom <da...@iq80.com> on 2007/03/01 19:41:06 UTC

Working on MDB itests

I'm working on cloning the Stateless itests into a set of tests for  
MDB.  I'm going to try to keep the changes simple by replacing the  
Stateless RPC method calls with a simulated RPC using a request JMS  
message and response JMS message.

I'll post more when I get something working.

-dain

Re: Working on MDB itests

Posted by Dain Sundstrom <da...@iq80.com>.
I have completed converting the Stateless itests to MDB tests.  The  
tests cover basic message passing, lifecycle, allowed operations,  
injection and annotations.  We are still missing tests for message  
redelivery retry, transaction handling, exception handing and support  
for message destination linking.  Other than message destination  
linking, I think the others work but we need tests.

Anyway, MDBs for JMS should be considered to be working now, so if  
you find problems drop this list an email or file a JIRA.

-dain

On Mar 5, 2007, at 10:16 AM, Dain Sundstrom wrote:

> On Mar 1, 2007, at 12:08 PM, David Blevins wrote:
>
>> On Mar 1, 2007, at 10:41 AM, Dain Sundstrom wrote:
>>
>>> I'm working on cloning the Stateless itests into a set of tests  
>>> for MDB.  I'm going to try to keep the changes simple by  
>>> replacing the Stateless RPC method calls with a simulated RPC  
>>> using a request JMS message and response JMS message.
>>>
>>> I'll post more when I get something working.
>>
>> It'll be excellent to get some of those in, we sorely need it!
>
> I just committed our first MDB itest.  There are some ugly  
> commented out bits to help me debug this code and some duplicate  
> classes, but it does work.
>
> I spent extra time making the code simple so we can easily copy the  
> Stateless itests since Stateless and MDBs have almost the same  
> rules just Sync vs Async interfaces.  The tests basically look like  
> this:
>
> public abstract class SomeMdbTestClient extends MdbTestClient {
>     protected BasicMdbObject basicMdbObject;
>
>     protected void setUp() throws Exception {
>         super.setUp();
>         basicMdbObject = MdbProxy.newProxyInstance 
> (BasicMdbObject.class, connectionFactory, "request");
>     }
>
>     public void test03_proxy() throws Exception {
>         String returnValue = basicMdbObject.businessMethod("blah");
>         assertEquals("halb", returnValue);
>     }
> }
>
> So where's all the JMS code?  Well it is hidden under the magic  
> MDBProxy class.  I wrote some code that generates a  
> java.lang.reflect.Proxy to the MDB.  The proxy invocation handler  
> translates method invocations into the send of a JMS message and it  
> listens for a response message from the server which contains the  
> method invocation return value (or exception).  On the server side,  
> message processing is handled by anther helper class:
>
> public class BasicMdbBean implements BasicMdbObject,  
> MessageDrivenBean, MessageListener {
>     private MessageDrivenContext mdbContext = null;
>     protected MdbInvoker mdbInvoker;
>
>     public void setMessageDrivenContext(MessageDrivenContext ctx)  
> throws EJBException {
>         this.mdbContext = ctx;
>         try {
>             ConnectionFactory connectionFactory =  
> (ConnectionFactory) new InitialContext().lookup("java:comp/env/jms");
>             mdbInvoker = new MdbInvoker(connectionFactory, this);
>         } catch (Exception e) {
>             throw new EJBException(e);
>         }
>     }
>     public void onMessage(Message message) {
>         try {
>             mdbInvoker.onMessage(message);
>         } catch (Throwable e) {
>             e.printStackTrace();
>         }
>     }
> }
>
> Hopefully, I'll be able to fill out the MDB tests very quickly, but  
> it may take a wile to fix all the bugs they find in my code :)
>
> Oh ya, one final thing.  To get this working, I had to mock up the  
> system three different ways, so if you want to learn more about  
> JMS, these test classes maybe helpful
>
> Simple request response using JMS:
> http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/ 
> container/openejb-core/src/test/java/org/apache/openejb/core/mdb/ 
> JmsTest.java?revision=514750&view=markup
>
> Same test above, but server side uses JCA 1.5 inbound messaging:
> http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/ 
> container/openejb-core/src/test/java/org/apache/openejb/core/mdb/ 
> MdbTest.java?revision=514750&view=markup
>
> Same test, but uses proxy code:
> http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/ 
> container/openejb-core/src/test/java/org/apache/openejb/core/mdb/ 
> JmsProxyTest.java?revision=514750&view=markup
>
> -dain


Re: Working on MDB itests

Posted by Dain Sundstrom <da...@iq80.com>.
On Mar 1, 2007, at 12:08 PM, David Blevins wrote:

> On Mar 1, 2007, at 10:41 AM, Dain Sundstrom wrote:
>
>> I'm working on cloning the Stateless itests into a set of tests  
>> for MDB.  I'm going to try to keep the changes simple by replacing  
>> the Stateless RPC method calls with a simulated RPC using a  
>> request JMS message and response JMS message.
>>
>> I'll post more when I get something working.
>
> It'll be excellent to get some of those in, we sorely need it!

I just committed our first MDB itest.  There are some ugly commented  
out bits to help me debug this code and some duplicate classes, but  
it does work.

I spent extra time making the code simple so we can easily copy the  
Stateless itests since Stateless and MDBs have almost the same rules  
just Sync vs Async interfaces.  The tests basically look like this:

public abstract class SomeMdbTestClient extends MdbTestClient {
     protected BasicMdbObject basicMdbObject;

     protected void setUp() throws Exception {
         super.setUp();
         basicMdbObject = MdbProxy.newProxyInstance 
(BasicMdbObject.class, connectionFactory, "request");
     }

     public void test03_proxy() throws Exception {
         String returnValue = basicMdbObject.businessMethod("blah");
         assertEquals("halb", returnValue);
     }
}

So where's all the JMS code?  Well it is hidden under the magic  
MDBProxy class.  I wrote some code that generates a  
java.lang.reflect.Proxy to the MDB.  The proxy invocation handler  
translates method invocations into the send of a JMS message and it  
listens for a response message from the server which contains the  
method invocation return value (or exception).  On the server side,  
message processing is handled by anther helper class:

public class BasicMdbBean implements BasicMdbObject,  
MessageDrivenBean, MessageListener {
     private MessageDrivenContext mdbContext = null;
     protected MdbInvoker mdbInvoker;

     public void setMessageDrivenContext(MessageDrivenContext ctx)  
throws EJBException {
         this.mdbContext = ctx;
         try {
             ConnectionFactory connectionFactory =  
(ConnectionFactory) new InitialContext().lookup("java:comp/env/jms");
             mdbInvoker = new MdbInvoker(connectionFactory, this);
         } catch (Exception e) {
             throw new EJBException(e);
         }
     }
     public void onMessage(Message message) {
         try {
             mdbInvoker.onMessage(message);
         } catch (Throwable e) {
             e.printStackTrace();
         }
     }
}

Hopefully, I'll be able to fill out the MDB tests very quickly, but  
it may take a wile to fix all the bugs they find in my code :)

Oh ya, one final thing.  To get this working, I had to mock up the  
system three different ways, so if you want to learn more about JMS,  
these test classes maybe helpful

Simple request response using JMS:
http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/ 
container/openejb-core/src/test/java/org/apache/openejb/core/mdb/ 
JmsTest.java?revision=514750&view=markup

Same test above, but server side uses JCA 1.5 inbound messaging:
http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/ 
container/openejb-core/src/test/java/org/apache/openejb/core/mdb/ 
MdbTest.java?revision=514750&view=markup

Same test, but uses proxy code:
http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/ 
container/openejb-core/src/test/java/org/apache/openejb/core/mdb/ 
JmsProxyTest.java?revision=514750&view=markup

-dain

Re: Working on MDB itests

Posted by David Blevins <da...@visi.com>.
On Mar 1, 2007, at 10:41 AM, Dain Sundstrom wrote:

> I'm working on cloning the Stateless itests into a set of tests for  
> MDB.  I'm going to try to keep the changes simple by replacing the  
> Stateless RPC method calls with a simulated RPC using a request JMS  
> message and response JMS message.
>
> I'll post more when I get something working.

It'll be excellent to get some of those in, we sorely need it!

-David