@@ -0,0 +1,1753 @@
+package com.dianping.cat.message.spi.core;%0A%0Aimport java.util.concurrent.BlockingQueue;%0Aimport java.util.concurrent.LinkedBlockingQueue;%0A%0Aimport junit.framework.Assert;%0A%0Aimport org.jboss.netty.buffer.ChannelBuffer;%0Aimport org.jboss.netty.buffer.ChannelBuffers;%0Aimport org.junit.Test;%0Aimport org.unidal.lookup.ComponentTestCase;%0A%0Aimport com.dianping.cat.message.spi.MessageCodec;%0Aimport com.dianping.cat.message.spi.MessageTree;%0Aimport com.dianping.cat.message.spi.core.TcpSocketReceiver.DecodeMessageTask;%0A%0Apublic class TcpSocketReceiverTest extends ComponentTestCase %7B%0A%09%0A%09private MockMessageTreeBuilder builder = new MockMessageTreeBuilder();%0A%0A%09@Test%0A%09public void test() throws Exception %7B%0A%09%09BlockingQueue%3CChannelBuffer%3E queue = new LinkedBlockingQueue%3CChannelBuffer%3E(1);%0A%09%09ChannelBuffer buf = ChannelBuffers.dynamicBuffer();%0A%09%09buf.writeInt(231);%0A%09%09buf.writeBytes(%22asdf%22.getBytes());%0A%0A%09%09queue.add(buf);%0A%0A%09%09MockHandler handler = new MockHandler();%0A%09%09DecodeMessageTask task = new TcpSocketReceiver().new DecodeMessageTask(0, queue, new MockCodec(),%0A%09%09      handler);%0A%0A%09%09task.handleMessage();%0A%09%09%0A%09%09handler.assertEqual(builder.build());%0A%09%7D%0A%0A%09public class MockHandler implements MessageHandler %7B%0A%09%09private MessageTree m_message;%0A%0A%09%09@Override%0A%09%09public void handle(MessageTree message) %7B%0A%09%09%09m_message = message;%0A%09%09%7D%0A%0A%09%09public void assertEqual(MessageTree expectedMessage) %7B%0A%09%09%09Assert.assertEquals(expectedMessage.toString(), m_message.toString());%0A%09%09%7D%0A%0A%09%7D%0A%0A%09public class MockCodec implements MessageCodec %7B%0A%0A%09%09@Override%0A%09%09public MessageTree decode(ChannelBuffer buf) %7B%0A%09%09%09return builder.build();%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public void decode(ChannelBuffer buf, MessageTree tree) %7B%0A%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public void encode(MessageTree tree, ChannelBuffer buf) %7B%0A%09%09%7D%0A%09%7D%0A%7D%0A

add TcpSocketReceiverTest