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  
19  package org.apache.hadoop.chukwa.extraction.demux.processor.mapper;
20  
21  
22  import java.io.IOException;
23  import junit.framework.TestCase;
24  import org.apache.hadoop.chukwa.Chunk;
25  import org.apache.hadoop.chukwa.ChunkImpl;
26  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
27  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
28  import org.apache.hadoop.mapred.OutputCollector;
29  import org.apache.hadoop.mapred.Reporter;
30  
31  /*
32   * Test code for verifying that the log processors work properly.
33   * 
34   * Currently more or less just a stub
35   */
36  public class TestHadoopLogProcessor extends TestCase {
37  
38    long serializedSize = 0;
39    OutputCollector<ChukwaRecordKey, ChukwaRecord> nullcollector = new OutputCollector<ChukwaRecordKey, ChukwaRecord>() {
40      public void collect(ChukwaRecordKey arg0, ChukwaRecord arg1)
41          throws IOException {
42        serializedSize += arg1.toString().length();
43      }
44    };
45  
46    public void testHLPParseTimes() {
47      HadoopLogProcessor hlp = new HadoopLogProcessor();
48  
49      int LINES = 50000;
50      long bytes = 0;
51      long ts_start = System.currentTimeMillis();
52      for (int i = 0; i < LINES; ++i) {
53        Chunk c = getNewChunk();
54        bytes += c.getData().length;
55        hlp.process(null, c, nullcollector, Reporter.NULL);
56        // hlp.parse(line, nullcollector, Reporter.NULL);
57      }
58      long time = (System.currentTimeMillis() - ts_start);
59      System.out.println("parse took " + time + " milliseconds");
60      System.out.println("aka " + time * 1.0 / LINES + " ms per line or " + time
61          * 1000.0 / bytes + " ms per kilobyte of log data");
62      System.out.println("output records had total length of " + serializedSize);
63    }
64  
65    java.util.Random r = new java.util.Random();
66  
67    public Chunk getNewChunk() {
68      int ms = r.nextInt(1000);
69      String line = "2008-05-29 10:42:22," + ms
70          + " INFO org.apache.hadoop.dfs.DataNode: Some text goes here"
71          + r.nextInt() + "\n";
72      ChunkImpl c = new ChunkImpl("HadoopLogProcessor", "test",
73          line.length() , line.getBytes(), null);
74  
75      return c;
76    }
77  
78  }