View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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      // Remove any adaptor left over from previous run
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  }