[jboss-dev-forums] [Design of Messaging on JBoss (Messaging/JBoss)] - Re: Testing the wireformat

jmesnil do-not-reply at jboss.com
Fri Nov 16 03:14:44 EST 2007


"timfox" wrote : Now that testing is on my mind, here's a suggestion for testing the new JBM remoting code:
  | 
  | MINA is a third party component, so the unit tests shouldn't really test with the real MINA.
  | 
  | Instead, abstract out a simple interface that represents the interface between our new remoting code and MINA.
  | 
  | Our new remoting code then deals with that interface, not MINA directly.
  | 
  | Create a simple mock implementation of the interface which just forwards requests responses directly from client->server or vice versa (no actual sockets required).
  | 

The unit tests I put in the BRANCH_JBMessaging-544 (refactored but not committed yet) no longer require sockets.
They use MINA's own ProtocolCodecSession which encode & decode the packets using the same codec than when they're sent on the wire but there is no network trip.

All the wireformat tests looks like that:

1/ create the packet
2/ encode & decode it using MINA protocolCodecSession
3/ retrieve the decoded packet
4/ check it is equivalent to the created packet

the code for (2) is straightforward:


  |    private AbstractPacket encodeAndDecode(AbstractPacket packet)
  |          throws Exception
  |    {
  |       IoBuffer buffer = encode(packet);
  |       return decode(buffer);
  |    }
  | 
  |    private IoBuffer encode(AbstractPacket packet) throws Exception
  |    {
  |       ProtocolCodecSession session = new ProtocolCodecSession();
  |       ProtocolEncoder encoder = new PacketCodecFactory().getEncoder();
  |       encoder.encode(session, packet, session
  |             .getEncoderOutput());
  |       IoBuffer buffer = session.getEncoderOutputQueue().poll();
  |       return buffer;
  |    }
  | 
  |    private AbstractPacket decode(IoBuffer buffer) throws Exception
  |    {
  |       ProtocolCodecSession session = new ProtocolCodecSession();
  |       ProtocolDecoder decoder = new PacketCodecFactory().getDecoder();
  |       decoder.decode(session, buffer, session.getDecoderOutput());
  | 
  |       Object o = session.getDecoderOutputQueue().poll();
  | 
  |       assertTrue(o instanceof AbstractPacket);
  | 
  |       return (AbstractPacket) o;
  |    }
  | 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4105322#4105322

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4105322



More information about the jboss-dev-forums mailing list