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

modify the HtmlMessageCodecTest

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