TestCrossMessage.java
3.96 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.dianping.cat.demo;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.Test;
import org.unidal.helper.Threads;
import org.unidal.helper.Threads.Task;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.message.spi.internal.DefaultMessageTree;
public class TestCrossMessage {
@Test
public void testCross() throws Exception {
String serverIp = "10.10.10.1";
String clientIp = "10.10.10.2";
for (int i = 0; i < 1000; i++) {
sendClientMsg("Cat-Call", "catClient1", clientIp, "1000", "catServer1", serverIp + ":8080");
sendClientMsg("Cat-Call", "catClient1", clientIp, "1000", "catServer2", serverIp + ":8081");
sendClientMsg("Cat-Call", "catClient2", clientIp, "1001", "catServer1", serverIp + ":8080");
sendClientMsg("Cat-Call", "catClient2", clientIp, "1001", "catServer2", serverIp + ":8081");
sendServiceMsg("Cat-Call", "catServer1", serverIp, "catClient1", clientIp + ":1000");
sendServiceMsg("Cat-Call", "catServer1", serverIp, "catClient2", clientIp + ":1001");
sendServiceMsg("Cat-Call", "catServer2", serverIp, "catClient1", clientIp + ":1000");
sendServiceMsg("Cat-Call", "catServer2", serverIp, "catClient2", clientIp + ":1001");
}
Thread.sleep(10000);
}
@Test
public void testCross1() throws Exception {
String serverIp = "10.10.10.1";
String clientIp = "10.10.10.2";
for (int i = 0; i < 1000; i++) {
sendClientMsg("Cat-Call", "catClient1", clientIp, "1000", "catServer1", serverIp + ":1000");
sendClientMsg("Cat-Call", "catServer1", serverIp, "1000", "catClient1", clientIp + ":1000");
sendServiceMsg("Cat-Call", "catServer1", serverIp, "catClient1", clientIp + ":1000");
sendServiceMsg("Cat-Call", "catClient1", clientIp, "catServer1", serverIp + ":1000");
}
Thread.sleep(10000);
}
private void sendServiceMsg(String method, String server, String serverIp, String client, String clientIp) {
Transaction t = Cat.newTransaction("PigeonService", method);
Cat.logEvent("PigeonService.client", clientIp);
Cat.logEvent("PigeonService.app", client);
MessageTree tree = Cat.getManager().getThreadLocalMessageTree();
((DefaultMessageTree) tree).setDomain(server);
((DefaultMessageTree) tree).setIpAddress(serverIp);
t.setStatus(Transaction.SUCCESS);
t.complete();
}
private void sendClientMsg(String method, String client, String clientIp, String port, String server, String serverIp) {
Transaction t = Cat.newTransaction("PigeonCall", method);
Cat.logEvent("PigeonCall.server", serverIp);
Cat.logEvent("PigeonCall.app", server);
Cat.logEvent("PigeonCall.port", port);
MessageTree tree = Cat.getManager().getThreadLocalMessageTree();
((DefaultMessageTree) tree).setDomain(client);
((DefaultMessageTree) tree).setIpAddress(clientIp);
t.setStatus(Transaction.SUCCESS);
t.complete();
}
@Test
public void test() throws InterruptedException {
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < 100; i++) {
String key = String.valueOf(i);
map.put(key, key);
}
Threads.forGroup("f").start(new TestThread(map));
Thread.sleep(1000);
Map<String, String> map2 = new HashMap<String, String>();
for (int i = 100; i < 200; i++) {
String key = String.valueOf(i);
map2.put(key, key);
}
map = map2;
Thread.sleep(10000);
}
public static class TestThread implements Task {
public Map<String, String> m_map;
public TestThread(Map<String, String> map) {
m_map = map;
}
@Override
public void run() {
for (Entry<String, String> entry : m_map.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public String getName() {
return null;
}
@Override
public void shutdown() {
// TODO Auto-generated method stub
}
}
}