}
public void testMessageChunkingObject() throws Exception
{
final AtomicInteger messagePartsCount = new AtomicInteger(0);
final Latch chunkingReceiverLatch = new Latch();
final SimpleSerializableObject simpleSerializableObject = new SimpleSerializableObject("Test String", true, 99);
// find number of chunks
final int parts = (int) Math.ceil((SerializationUtils.serialize(simpleSerializableObject).length / (double) 2));
// Listen to events fired by the ChunkingReceiver service
muleContext.registerListener(new FunctionalTestNotificationListener()
{
public void onNotification(ServerNotification notification)
{
// Not strictly necessary to test for this as when we register the
// listener we supply the ComponentName as the subscription filter
assertEquals("ChunkingObjectReceiver", notification.getResourceIdentifier());
// Test that we have received all chunks in the correct order
Object reply = ((FunctionalTestNotification) notification).getEventContext().getMessage().getPayload();
// Check if Object is of Correct Type
assertTrue(reply instanceof SimpleSerializableObject);
SimpleSerializableObject replySimpleSerializableObject = (SimpleSerializableObject) reply;
// Check that Contents are Identical
assertEquals(simpleSerializableObject.b, replySimpleSerializableObject.b);
assertEquals(simpleSerializableObject.i, replySimpleSerializableObject.i);
assertEquals(simpleSerializableObject.s, replySimpleSerializableObject.s);
chunkingReceiverLatch.countDown();
}
}, "ChunkingObjectReceiver");
// Listen to Message Notifications on the Chunking receiver so we can
// determine how many message parts have been received
muleContext.registerListener(new EndpointMessageNotificationListener<EndpointMessageNotification>()
{
public void onNotification(EndpointMessageNotification notification)
{
if (notification.getAction() == EndpointMessageNotification.MESSAGE_RECEIVED)
{
messagePartsCount.getAndIncrement();
}
assertEquals("ChunkingObjectReceiver", notification.getResourceIdentifier());
}
}, "ChunkingObjectReceiver");
MuleClient client = new MuleClient(muleContext);
client.dispatch("vm://inbound.object.channel", simpleSerializableObject, null);
// Wait for the message to be received and tested (in the listener above)
assertTrue(chunkingReceiverLatch.await(20L, TimeUnit.SECONDS));
// Ensure we processed expected number of message parts
assertEquals(parts, messagePartsCount.get());
}