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.extraction.demux.processor.mapper;
19  
20  
21  import junit.framework.TestCase;
22  import org.apache.hadoop.chukwa.Chunk;
23  import org.apache.hadoop.chukwa.ChunkBuilder;
24  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
25  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
26  import org.apache.hadoop.chukwa.util.RecordConstants;
27  import org.apache.hadoop.mapred.OutputCollector;
28  import org.apache.hadoop.mapred.Reporter;
29  
30  public class TestAbtractProcessor extends TestCase {
31  
32    String[] data = { "dsjsjbsfjds\ndsafsfasd\n",
33        "asdgHSAJGDGYDGGHAgd7364rt3478tc4\nhr473rt346t\n", "e	gqd	yeegyxuyexfg\n" };
34  
35    public void testParse() {
36  
37      ChunkBuilder cb = new ChunkBuilder();
38      cb.addRecord(RecordConstants.escapeAllButLastRecordSeparator("\n", data[0])
39          .getBytes());
40      cb.addRecord(RecordConstants.escapeAllButLastRecordSeparator("\n", data[1])
41          .getBytes());
42      cb.addRecord(RecordConstants.escapeAllButLastRecordSeparator("\n", data[2])
43          .getBytes());
44      Chunk chunk = cb.getChunk();
45      OutputCollector<ChukwaRecordKey, ChukwaRecord> output = new ChukwaTestOutputCollector<ChukwaRecordKey, ChukwaRecord>();
46      TProcessor p = new TProcessor();
47      p.data = data;
48      p.process(null, chunk, output, null);
49    }
50  
51  }
52  
53  
54  class TProcessor extends AbstractProcessor {
55    String[] data = null;
56    int count = 0;
57  
58    @Override
59    protected void parse(String recordEntry,
60        OutputCollector<ChukwaRecordKey, ChukwaRecord> output, Reporter reporter) {
61      if (!recordEntry.equals(data[count])) {
62        System.out.println("[" + recordEntry + "]");
63        System.out.println("[" + data[count] + "]");
64        throw new RuntimeException("not the same record");
65      }
66      count++;
67    }
68  
69    public String getDataType() {
70      // TODO Auto-generated method stub
71      return null;
72    }
73  }