提交 3402d929 编写于 作者: Y yong.you

modify the HtmlMessageCodecTest

上级 17e2e294
......@@ -13,15 +13,16 @@ import org.junit.runners.JUnit4;
import org.unidal.lookup.ComponentTestCase;
import org.unidal.webres.helper.Files;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Event;
import com.dianping.cat.message.Heartbeat;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Metric;
import com.dianping.cat.message.Trace;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.internal.AbstractMessage;
import com.dianping.cat.message.internal.DefaultEvent;
import com.dianping.cat.message.internal.DefaultHeartbeat;
import com.dianping.cat.message.internal.DefaultMetric;
import com.dianping.cat.message.internal.DefaultTrace;
import com.dianping.cat.message.internal.DefaultTransaction;
import com.dianping.cat.message.spi.MessageCodec;
......@@ -33,24 +34,18 @@ public class HtmlMessageCodecTest extends ComponentTestCase {
private DefaultMessageTree buildMessageTree() {
long timestamp = 1325489621987L;
Transaction transaction = Cat.newTransaction("transaction", "transaction");
Cat.logTrace("logTrace", "<trace>");
Cat.logTrace("logTrace", "<trace>", Trace.SUCCESS, "data");
Cat.logMetric("logMetric", "test", "test");
Cat.logMetricForCount("logMetricForCount");
Cat.logMetricForCount("logMetricForCount", 4);
Cat.logMetricForDuration("logMetricForDuration", 100);
Cat.logMetricForSum("logMetricForSum", 100);
Cat.logMetricForSum("logMetricForSum", 100, 100);
Cat.logEvent("RemoteLink", "Call", Message.SUCCESS, "Cat-0a010680-384736-2061");
Cat.logEvent("EventType", "EventName");
Cat.logHeartbeat("logHeartbeat", "logHeartbeat", Message.SUCCESS, null);
DefaultMessageTree tree = (DefaultMessageTree) Cat.getManager().getThreadLocalMessageTree();
((DefaultTransaction) transaction).setDurationInMicros(8000);
((DefaultTransaction) transaction).setTimestamp(timestamp);
Transaction transaction = newTransaction("transaction", "transaction", timestamp, Message.SUCCESS, 8000, null);
transaction.addChild(newTrace("logTrace", "<trace>", timestamp, Trace.SUCCESS, null));
transaction.addChild(newTrace("logTrace", "<trace>", timestamp, Trace.SUCCESS, "data"));
transaction.addChild(newEvent("logEvent", "<event>", timestamp, Trace.SUCCESS, "data"));
transaction.addChild(newEvent("RemoteLink", "<event>", timestamp, Trace.SUCCESS, "data"));
transaction.addChild(newMetric("logEvent", "<event>", timestamp, Trace.SUCCESS, "data"));
transaction.addChild(newHeartbeat("logHeartbeat", "<event>", timestamp, Trace.SUCCESS, "data"));
DefaultMessageTree tree = new DefaultMessageTree();
tree.setMessage(transaction);
String messageId = "Cat-0a010680-384736-2061";
String parentMessageId = "Cat-0a010680-384736-2062";
......@@ -95,6 +90,15 @@ public class HtmlMessageCodecTest extends ComponentTestCase {
return event;
}
private Metric newMetric(String type, String name, long timestamp, String status, String data) {
DefaultMetric metric = new DefaultMetric(type, name);
metric.setStatus(status);
metric.addData(data);
metric.setTimestamp(timestamp);
return metric;
}
private Heartbeat newHeartbeat(String type, String name, long timestamp, String status, String data) {
DefaultHeartbeat heartbeat = new DefaultHeartbeat(type, name);
......@@ -142,7 +146,6 @@ public class HtmlMessageCodecTest extends ComponentTestCase {
}
@Test
@Ignore
public void testEncode() throws Exception {
MessageTree tree = buildMessageTree();
HtmlMessageCodec codec = (HtmlMessageCodec) lookup(MessageCodec.class, "html");
......@@ -152,7 +155,7 @@ public class HtmlMessageCodecTest extends ComponentTestCase {
String content = Files.forIO().readFrom(HtmlMessageCodecTest.class.getResourceAsStream("MessageTree.txt"),
"utf-8");
Assert.assertEquals(content.trim(), tree.toString().trim());
Assert.assertEquals(1929, buf.readableBytes());
Assert.assertEquals(1237, buf.readableBytes());
}
@Test
......@@ -166,6 +169,17 @@ public class HtmlMessageCodecTest extends ComponentTestCase {
"<tr><td>E15:33:41.987</td><td>type</td><td>name</td><td>&nbsp;</td><td>here is the data.</td></tr>\r\n");
}
@Test
public void testMetric() throws Exception {
long timestamp = 1325489621987L;
Metric Metric = newMetric("type", "name", timestamp, "0", "here is the data.");
MessageTree tree = new DefaultMessageTree();
tree.setMessage(Metric);
check(tree, Metric,
"<tr><td>M15:33:41.987</td><td>type</td><td>name</td><td>&nbsp;</td><td>here is the data.</td></tr>\r\n");
}
@Test
public void testEventForRawData() throws Exception {
long timestamp = 1325489621987L;
......
PT1 Cat localhost-cat 192.168.1.1 main 1 main Cat-c0a80746-384747-36441 Cat-0a010680-384736-2062 Cat-0a010680-384736-2061 null
PT1 null localhost-cat 192.168.1.1 null null null null Cat-0a010680-384736-2062 Cat-0a010680-384736-2061 null
t2012-01-02 15:33:41.987 transaction transaction
L2012-01-02 15:33:41.987 logTrace <trace> 0
L2012-01-02 15:33:41.987 logTrace <trace> 0 data
M2012-01-02 15:33:41.987 logMetric 0 test=test
M2012-01-02 15:33:41.987 logMetricForCount C 1
M2012-01-02 15:33:41.987 logMetricForCount C 4
M2012-01-02 15:33:41.987 logMetricForDuration T 100
M2012-01-02 15:33:41.987 logMetricForSum S 100.00
M2012-01-02 15:33:41.987 logMetricForSum S,C 100.00,100
E2012-01-02 15:33:41.987 RemoteLink Call 0 Cat-0a010680-384736-2061
E2012-01-02 15:33:41.987 EventType EventName 0
H2012-01-02 15:33:41.987 logHeartbeat logHeartbeat 0
T2012-01-02 15:33:41.995 transaction transaction unset 8000us
\ No newline at end of file
E2012-01-02 15:33:41.987 logEvent <event> 0 data
E2012-01-02 15:33:41.987 RemoteLink <event> 0 data
M2012-01-02 15:33:41.987 logEvent <event> 0 data
H2012-01-02 15:33:41.987 logHeartbeat <event> 0 data
T2012-01-02 15:33:49.987 transaction transaction 0 8000000us
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册