提交 45825588 编写于 作者: A ainilife

refine the code

上级 f16d63d6
......@@ -75,27 +75,21 @@ public class LocalMessageBucketManagerTest extends ComponentTestCase {
return transaction;
}
@Test
public void test() {
}
@Test
public void testReadWrite() throws Exception {
MessageCodec codec = lookup(MessageCodec.class, PlainTextMessageCodec.ID);
LocalMessageBucketManager manager = (LocalMessageBucketManager) lookup(MessageBucketManager.class,
LocalMessageBucketManager.ID);
MessageCodec codec = lookup(MessageCodec.class, PlainTextMessageCodec.ID);
MessageIdFactory factory = new MockMessageIdFactory();
manager.setLocalIp(m_ip);
long now = 1343532130488L;
int num = 5000;
Thread.sleep(100);
manager.setLocalIp(m_ip);
factory.setIpAddress("7f000001");
factory.initialize("source");
Thread.sleep(100);
for (int i = 0; i < num; i++) {
DefaultMessageTree tree = newMessageTree(factory.getNextId(), i, now + i * 10L);
MessageId id = MessageId.parse(tree.getMessageId());
......
package com.dianping.cat.storage.dump;
import java.io.File;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Ignore;
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;
import com.dianping.cat.message.spi.MessageCodec;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.message.spi.codec.PlainTextMessageCodec;
import com.dianping.cat.message.spi.internal.DefaultMessageTree;
@Ignore
public class LocalMessageRecovery extends ComponentTestCase {
private MessageCodec m_codec;
@Test
public void test()throws Exception{
recovery("10.1.6.108");
}
public void recovery(String ip) throws Exception {
m_codec = lookup(MessageCodec.class, PlainTextMessageCodec.ID);
File dataFile = new File("/Users/youyong/midasMerchantServerWorker-10.1.8.77-"+ip);
MessageBlockReader reader = new MessageBlockReader(dataFile);
String message = readMessage(reader, 27);
String id="midasMerchantServerWorker-0a01084d-382328-27";
if(message.indexOf(id)>-1){
System.out.println(message);
}
}
private String readMessage(MessageBlockReader reader, int index) throws Exception {
byte[] data = reader.readMessage(index);
if(data==null){
return "";
}
ChannelBuffer buf = ChannelBuffers.dynamicBuffer(data.length);
MessageTree tree = new DefaultMessageTree();
buf.writeBytes(data);
m_codec.decode(buf, tree);
return tree.toString();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册