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 import static org.apache.hadoop.chukwa.util.TempFileUtil.makeTestFile;
21 import static org.junit.Assert.*;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
27 import org.apache.hadoop.chukwa.datacollection.agent.ChukwaAgent;
28 import org.apache.hadoop.chukwa.datacollection.agent.ChukwaAgent.AlreadyRunningException;
29 import org.apache.hadoop.chukwa.datacollection.connector.ChunkCatcherConnector;
30 import org.junit.After;
31 import org.junit.Test;
32
33 public class TestFileTailer {
34 private ChukwaAgent agent;
35 private String adaptorId;
36 private File testFile;
37
38 @After
39 public void tearDown() throws Exception {
40 agent.stopAdaptor(adaptorId, false);
41 agent.shutdown();
42 if (testFile != null) {
43 testFile.delete();
44 }
45 }
46
47 @Test
48 public void testDontSleepIfHasMoreData() throws AlreadyRunningException, IOException, InterruptedException {
49 ChukwaConfiguration cc = new ChukwaConfiguration();
50 cc.setInt("chukwaAgent.fileTailingAdaptor.maxReadSize", 18);
51
52 agent = ChukwaAgent.getAgent(cc);
53 agent.start();
54
55 ChunkCatcherConnector chunks = new ChunkCatcherConnector();
56 chunks.start();
57
58 File baseDir = new File(System.getProperty("test.build.data", "/tmp"));
59 testFile = makeTestFile("testDontSleepIfHasMoreData", 1, baseDir);
60 long startTime = System.currentTimeMillis();
61 adaptorId = agent.processAddCommand("add adaptor_test ="
62 + "filetailer.FileTailingAdaptor testDontSleepIfHasMoreData "
63 + testFile.getCanonicalPath() + " 0");
64
65 chunks.waitForAChunk();
66 chunks.waitForAChunk();
67
68 long endTime = System.currentTimeMillis();
69 assertTrue( endTime - startTime < 300 );
70
71 }
72
73 }