1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.chukwa.datacollection.adaptor.filetailer;
19
20
21 import java.io.*;
22
23 import junit.framework.TestCase;
24 import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
25 import java.util.Map;
26 import java.util.Iterator;
27 import org.apache.hadoop.chukwa.Chunk;
28 import org.apache.hadoop.chukwa.datacollection.adaptor.*;
29 import org.apache.hadoop.chukwa.datacollection.agent.ChukwaAgent;
30 import org.apache.hadoop.chukwa.datacollection.controller.ChukwaAgentController;
31 import org.apache.hadoop.chukwa.datacollection.connector.ChunkCatcherConnector;
32 import org.apache.hadoop.conf.Configuration;
33 import static org.apache.hadoop.chukwa.util.TempFileUtil.*;
34
35 public class TestRawAdaptor extends TestCase {
36 ChunkCatcherConnector chunks;
37
38 public TestRawAdaptor() {
39 chunks = new ChunkCatcherConnector();
40 chunks.start();
41 }
42
43 public void testRawAdaptor() throws Exception {
44 System.out.println("testing raw fta");
45 runTest("FileTailingAdaptor");
46 }
47
48
49 public void testLWRawAdaptor() throws Exception {
50 System.out.println("testing lightweight fta");
51 runTest("LWFTAdaptor");
52 }
53
54
55 public void testRotAdaptor() throws Exception {
56 System.out.println("testing lightweight fta");
57 runTest("LWFTAdaptor");
58 }
59
60 public void runTest(String name) throws IOException, InterruptedException,
61 ChukwaAgent.AlreadyRunningException {
62
63
64 Configuration conf = new Configuration();
65 conf.set("chukwaAgent.control.port", "0");
66 conf.setInt("chukwaAgent.adaptor.context.switch.time", 100);
67 ChukwaAgent agent = new ChukwaAgent(conf);
68
69 File testFile = makeTestFile("chukwaRawTest", 80,
70 new File(System.getProperty("test.build.data", "/tmp")));
71
72 String adaptorId = agent
73 .processAddCommand("add org.apache.hadoop.chukwa.datacollection.adaptor."
74 +"filetailer." + name
75 + " raw " + testFile + " 0");
76 assertNotNull(adaptorId);
77 Chunk c = chunks.waitForAChunk(1000);
78 assertNotNull(c);
79 assertEquals(testFile.length(), c.getData().length);
80 assertTrue(c.getDataType().equals("raw"));
81 assertTrue(c.getRecordOffsets().length == 1);
82 assertTrue(c.getSeqID() == testFile.length());
83
84 c = chunks.waitForAChunk(1000);
85 assertNull(c);
86
87 agent.stopAdaptor(adaptorId, false);
88 agent.shutdown();
89 }
90
91
92 }