Package com.dianping.cat.message.spi

Examples of com.dianping.cat.message.spi.MessageCodec


public class MessageCodecPerformanceTest extends CatTestCase {
  public static final String ID = "plain-text";

  @Test
  public void testCodePerformance() throws Exception {
    MessageCodec codec = lookup(MessageCodec.class, ID);
    MessageTree tree = buildMessage();
    ChannelBuffer buf = new DynamicChannelBuffer(10240);
    codec.encode(tree, buf);

    int count = 5000000;
    for (int i = 0; i < count; i++) {

      buf.markReaderIndex();
      // read the size of the message
      buf.readInt();
      DefaultMessageTree result = (DefaultMessageTree) codec.decode(buf);
      buf.resetReaderIndex();
      result.setBuffer(buf);
    }
  }
View Full Code Here


    // please stop CAT server when you run this test case
    Assert.assertEquals("One message should be in the queue.", 1, m_queue.size());

    MessageTree tree = m_queue.poll();

    MessageCodec codec = Cat.lookup(MessageCodec.class, "plain-text");
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer(4 * 1024);

    codec.encode(tree, buf);

    buf.readInt();
    MessageTree tree2 = codec.decode(buf);

    Assert.assertEquals(tree.toString(), tree2.toString());
  }
View Full Code Here

public class MessageCodecUnexceptedCharTest extends CatTestCase {
  public static final String ID = "plain-text";

  @Test
  public void testCodePerformance() throws Exception {
    MessageCodec codec = lookup(MessageCodec.class, ID);
    MessageTree tree = buildMessage();
    ChannelBuffer buf = new DynamicChannelBuffer(10240);
    codec.encode(tree, buf);
    MessageTree result = new DefaultMessageTree();
    codec.decode(buf, result);
    Assert.assertEquals(tree.toString(), result.toString());
  }
View Full Code Here

public class MessageTest extends ComponentTestCase {
  private Queue<MessageTree> m_queue = new LinkedBlockingQueue<MessageTree>();

  private void checkMessage(String expected) {
    StringBuilder sb = new StringBuilder(1024);
    MessageCodec codec = new MockMessageCodec(sb);

    while (true) {
      MessageTree tree = m_queue.poll();

      if (tree != null) {
        codec.encode(tree, null);
      } else {
        break;
      }
    }
   
View Full Code Here

  protected String toString(ModelRequest request, MessageTree tree) {
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer(8192);

    if (tree.getMessage() instanceof Transaction && request.getProperty("waterfall", "false").equals("true")) {
      // to work around a plexus injection bug
      MessageCodec codec = lookup(MessageCodec.class, "waterfall");

      codec.encode(tree, buf);
    } else {
      m_codec.encode(tree, buf);
    }

    try {
View Full Code Here

    if (tree != null) {
      ChannelBuffer buf = ChannelBuffers.dynamicBuffer(8192);

      if (tree.getMessage() instanceof Transaction && request.getProperty("waterfall", "false").equals("true")) {
        // to work around a plexus injection bug
        MessageCodec codec = lookup(MessageCodec.class, "waterfall");

        codec.encode(tree, buf);
      } else {
        m_codec.encode(tree, buf);
      }

      try {
View Full Code Here

  @Test
  public void testReadWrite() throws Exception {
    setup();
    MessageIdFactory factory = new MockMessageIdFactory();
    LocalMessageBucket bucket = createBucket(factory, "");
    MessageCodec codec = lookup(MessageCodec.class, PlainTextMessageCodec.ID);

    int count = 2000;
    int i = 0;
    MessageBlock block = null;
    MessageTree tree = new DefaultMessageTree();
View Full Code Here

  public void testManyReadWrite() throws Exception {
    setup();

    MessageIdFactory factory = new MockMessageIdFactory();
    LocalMessageBucket[] buckets = new LocalMessageBucket[3];
    MessageCodec codec = lookup(MessageCodec.class, PlainTextMessageCodec.ID);

    for (int i = 0; i < buckets.length; i++) {
      LocalMessageBucket bucket = createBucket(factory, "-" + i);

      buckets[i] = bucket;
View Full Code Here

TOP

Related Classes of com.dianping.cat.message.spi.MessageCodec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.