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