TestInternalCdn.java
1.44 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
package com.dianping.cat.demo;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import org.junit.Test;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Metric;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.internal.DefaultMetric;
import com.dianping.cat.message.internal.DefaultTransaction;
import com.dianping.cat.message.spi.MessageTree;
public class TestInternalCdn {
@Test
public void test() {
List<String> keys = Arrays.asList("DiLian", "TengXun", "WangSu");
List<String> ips = Arrays.asList("*.*.*.*", "*.*.*.*");
Random r = new Random();
while (true) {
try {
int random = r.nextInt(100);
String key = keys.get(random % keys.size()) + ": " + ips.get(random % ips.size());
Metric metric = Cat.getProducer().newMetric("cdn", key);
DefaultMetric defaultMetric = (DefaultMetric) metric;
defaultMetric.setTimestamp(System.currentTimeMillis());
defaultMetric.setStatus("C");
defaultMetric.addData(String.valueOf(100));
MessageTree tree = Cat.getManager().getThreadLocalMessageTree();
Message message = tree.getMessage();
if (message instanceof Transaction) {
((DefaultTransaction) message).setTimestamp(System.currentTimeMillis());
}
tree.setDomain("piccenter-display");
metric.complete();
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}