CrossInfoTest.java
4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.dianping.cat.consumer.cross;
import junit.framework.Assert;
import org.junit.Test;
import org.unidal.lookup.ComponentTestCase;
import com.dianping.cat.config.server.ServerConfigManager;
import com.dianping.cat.consumer.cross.CrossAnalyzer.CrossInfo;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.internal.DefaultEvent;
import com.dianping.cat.message.internal.DefaultTransaction;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.message.spi.internal.DefaultMessageTree;
public class CrossInfoTest extends ComponentTestCase {
public MessageTree buildMockMessageTree() {
MessageTree tree = new DefaultMessageTree();
tree.setMessageId("Cat-c0a80746-373452-6");// 192.168.7.70 machine logview
tree.setIpAddress("192.168.0.1");
return tree;
}
@Test
public void testParseOtherTransaction() throws Exception {
CrossAnalyzer analyzer = new CrossAnalyzer();
analyzer.setServerConfigManager(lookup(ServerConfigManager.class));
analyzer.setIpConvertManager(new IpConvertManager());
DefaultTransaction t = new DefaultTransaction("Other", "method1", null);
MessageTree tree = buildMockMessageTree();
CrossInfo info = analyzer.parseCorssTransaction(t, tree);
Assert.assertEquals(true, info == null);
}
@Test
public void testParsePigeonClientTransaction() throws Exception {
CrossAnalyzer analyzer = new CrossAnalyzer();
analyzer.setServerConfigManager(lookup(ServerConfigManager.class));
analyzer.setIpConvertManager(new IpConvertManager());
DefaultTransaction t = new DefaultTransaction("PigeonCall", "method1", null);
MessageTree tree = buildMockMessageTree();
CrossInfo info = analyzer.parseCorssTransaction(t, tree);
Assert.assertEquals(info.getLocalAddress(), "192.168.0.1");
Assert.assertEquals(info.getRemoteAddress(), null);
Message message = new DefaultEvent("PigeonCall.server", "10.1.1.1", null);
Message messageApp = new DefaultEvent("PigeonCall.app", "myDomain", null);
t.addChild(message);
t.addChild(messageApp);
info = analyzer.parseCorssTransaction(t, tree);
Assert.assertEquals(info.getLocalAddress(), "192.168.0.1");
Assert.assertEquals(info.getRemoteAddress(), "10.1.1.1");
Assert.assertEquals(info.getDetailType(), "PigeonCall");
Assert.assertEquals(info.getRemoteRole(), "Pigeon.Server");
Assert.assertEquals(info.getApp(), "myDomain");
}
@Test
public void testParsePigeonServerTransaction() throws Exception {
CrossAnalyzer analyzer = new CrossAnalyzer();
analyzer.setServerConfigManager(lookup(ServerConfigManager.class));
analyzer.setIpConvertManager(new IpConvertManager());
DefaultTransaction t = new DefaultTransaction("PigeonService", "method1", null);
MessageTree tree = buildMockMessageTree();
CrossInfo info = analyzer.parseCorssTransaction(t, tree);
Assert.assertEquals(info.validate(), false);
Message message = new DefaultEvent("PigeonService.client", "192.168.7.71", null);
Message messageApp = new DefaultEvent("PigeonService.app", "myDomain", null);
t.addChild(message);
t.addChild(messageApp);
info = analyzer.parseCorssTransaction(t, tree);
Assert.assertEquals(info.getLocalAddress(), "192.168.0.1");
Assert.assertEquals(info.getRemoteAddress(), "192.168.7.71");
Assert.assertEquals(info.getDetailType(), "PigeonService");
Assert.assertEquals(info.getRemoteRole(), "Pigeon.Client");
Assert.assertEquals(info.getApp(), "myDomain");
}
@Test
public void testParsePigeonServerTransactionWithPort() throws Exception {
CrossAnalyzer analyzer = new CrossAnalyzer();
analyzer.setServerConfigManager(lookup(ServerConfigManager.class));
analyzer.setIpConvertManager(new IpConvertManager());
DefaultTransaction t = new DefaultTransaction("PigeonService", "method1", null);
MessageTree tree = buildMockMessageTree();
CrossInfo info = analyzer.parseCorssTransaction(t, tree);
Message message = new DefaultEvent("PigeonService.client", "192.168.7.71:29987", null);
Message messageApp = new DefaultEvent("PigeonService.app", "myDomain", null);
t.addChild(message);
t.addChild(messageApp);
info = analyzer.parseCorssTransaction(t, tree);
Assert.assertEquals(info.getLocalAddress(), "192.168.0.1");
Assert.assertEquals(info.getRemoteAddress(), "192.168.7.71:29987");
Assert.assertEquals(info.getDetailType(), "PigeonService");
Assert.assertEquals(info.getRemoteRole(), "Pigeon.Client");
Assert.assertEquals(info.getApp(), "myDomain");
}
}