1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.chukwa.datacollection.agent;
19
20
21 import java.util.ArrayList;
22 import org.apache.hadoop.conf.Configuration;
23 import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
24 import org.apache.hadoop.chukwa.datacollection.agent.ChukwaAgent;
25 import org.apache.hadoop.chukwa.datacollection.controller.ChukwaAgentController;
26 import org.apache.hadoop.chukwa.datacollection.test.ConsoleOutConnector;
27 import junit.framework.TestCase;
28
29
30 public class TestAgent extends TestCase {
31
32 public void testStopAndStart() {
33
34 try {
35 Configuration conf = new Configuration();
36 conf.setInt("chukwaAgent.control.port", 0);
37 ChukwaAgent agent = new ChukwaAgent(conf);
38 ConsoleOutConnector conn = new ConsoleOutConnector(agent, true);
39 conn.start();
40
41 int portno = agent.getControllerPort();
42 ChukwaAgentController cli = new ChukwaAgentController("localhost", portno);
43
44 for (int i = 1; i < 20; ++i) {
45 String adaptorId = cli.add(
46 "org.apache.hadoop.chukwa.util.ConstRateAdaptor", "raw" + i, "2000"
47 + i, 0);
48 assertNotNull(adaptorId);
49 Thread.sleep(2000);
50 cli.removeAll();
51 }
52 agent.shutdown();
53 conn.shutdown();
54 Thread.sleep(2000);
55 } catch (Exception e) {
56 e.printStackTrace();
57 fail(e.toString());
58 }
59 }
60
61 public void testMultiStopAndStart() {
62
63 try {
64 Configuration conf = new Configuration();
65 conf.setInt("chukwaAgent.control.port", 0);
66 ChukwaAgent agent = new ChukwaAgent(conf);
67 ConsoleOutConnector conn = new ConsoleOutConnector(agent, true);
68 conn.start();
69 int count = agent.adaptorCount();
70 for (int trial = 0; trial < 20; ++trial) {
71 ArrayList<String> runningAdaptors = new ArrayList<String>();
72
73 for (int i = 1; i < 7; ++i) {
74 String l = agent
75 .processAddCommand("add org.apache.hadoop.chukwa.util.ConstRateAdaptor raw"
76 + i + " 2000" + i + " 0");
77 assertTrue(l != null);
78 runningAdaptors.add(l);
79 }
80 Thread.sleep(1000);
81 for (String l : runningAdaptors)
82 agent.stopAdaptor(l, false);
83 Thread.sleep(5000);
84 assertTrue(agent.adaptorCount() == count);
85 }
86 agent.shutdown();
87 Thread.sleep(2000);
88 } catch (Exception e) {
89 e.printStackTrace();
90 fail(e.toString());
91 }
92 }
93
94 public void testLogRotate() {
95
96 }
97
98 }