/
PerfMonMetricGetterTest.java
97 lines (87 loc) · 3.84 KB
/
PerfMonMetricGetterTest.java
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
package kg.apc.perfmon;
import junit.framework.TestCase;
import kg.apc.emulators.DatagramChannelEmul;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarProxyCache;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.DatagramChannel;
/**
* @author undera
*/
public class PerfMonMetricGetterTest extends TestCase {
public PerfMonMetricGetterTest() {
}
public void testProcessCommand() throws IOException {
System.out.println("processCommand");
String toString = "test\ntest\nerr\n";
final DatagramChannel channel = DatagramChannelEmul.open();
channel.configureBlocking(false);
final InetSocketAddress inetSocketAddress = new InetSocketAddress(
"localhost", 4444);
channel.connect(inetSocketAddress);
PerfMonMetricGetter instance = new PerfMonMetricGetter(
SigarProxyCache.newInstance(new Sigar(), 500),
new PerfMonWorker(), channel, inetSocketAddress);
instance.addCommandString(toString);
instance.processNextCommand();
instance.processNextCommand();
try {
instance.processNextCommand();
fail();
} catch (UnsupportedOperationException e) {
}
}
public void testAddCommandString() throws IOException {
System.out.println("addCommandString");
String byteBufferToString = "";
PerfMonMetricGetter instance = new PerfMonMetricGetter(
SigarProxyCache.newInstance(new Sigar(), 500),
new PerfMonWorker(), DatagramChannel.open());
instance.addCommandString(byteBufferToString);
}
public void testProcessNextCommand() throws Exception {
System.out.println("processNextCommand");
PerfMonMetricGetter instance = new PerfMonMetricGetter(
SigarProxyCache.newInstance(new Sigar(), 500),
new PerfMonWorker(), DatagramChannel.open());
boolean expResult = false;
boolean result = instance.processNextCommand();
assertEquals(expResult, result);
}
public void testSendMetrics() throws IOException {
System.out.println("sendMetrics");
PerfMonMetricGetter instance = new PerfMonMetricGetter(
SigarProxyCache.newInstance(new Sigar(), 500),
new PerfMonWorker(), DatagramChannel.open());
instance.getMetricsLine();
}
public void testProcessCommand_single_metrics() throws IOException {
System.out.println("processCommand");
String toString = "metrics-single:cpu\tmemory\ttcp\n";
final DatagramChannel channel = DatagramChannelEmul.open();
channel.configureBlocking(false);
final InetSocketAddress inetSocketAddress = new InetSocketAddress(
"localhost", 4444);
channel.connect(inetSocketAddress);
PerfMonMetricGetter instance = new PerfMonMetricGetter(
SigarProxyCache.newInstance(new Sigar(), 500),
new PerfMonWorker(), channel, inetSocketAddress);
instance.addCommandString(toString);
instance.processNextCommand();
}
public void testProcessCommand_udp_transmitter() throws IOException {
System.out.println("UDP transmitter");
String cmd = "udp-transmitter:localhost:3333:cpu\tmemory\ttcp\n";
final DatagramChannel channel = DatagramChannelEmul.open();
channel.configureBlocking(false);
final InetSocketAddress inetSocketAddress = new InetSocketAddress(
"localhost", 4444);
channel.connect(inetSocketAddress);
PerfMonMetricGetter instance = new PerfMonMetricGetter(
SigarProxyCache.newInstance(new Sigar(), 500),
new PerfMonWorker(), channel, inetSocketAddress);
instance.addCommandString(cmd);
instance.processNextCommand();
}
}