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;
19  
20  import org.apache.hadoop.chukwa.ChukwaArchiveKey;
21  import org.apache.hadoop.chukwa.ChunkImpl;
22  import org.apache.hadoop.chukwa.ChunkBuilder;
23  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
24  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
25  import org.apache.hadoop.chukwa.extraction.demux.processor.mapper.ChukwaTestOutputCollector;
26  import org.apache.hadoop.mapred.Mapper;
27  import org.apache.hadoop.mapred.Reporter;
28  import org.apache.hadoop.mapred.JobConf;
29  import junit.framework.TestCase;
30  
31  
32  import java.io.IOException;
33  
34  /**
35   * Tests that settings related to the Demux mapper do what they should.
36   */
37  public class TestDemuxMapperConfigs extends TestCase {
38  
39    public static  String SAMPLE_RECORD_DATA = "sampleRecordData";
40  
41    public void testSetDefaultMapProcessor() throws IOException {
42      Mapper<ChukwaArchiveKey, ChunkImpl, ChukwaRecordKey, ChukwaRecord> mapper =
43              new Demux.MapClass();
44  
45      JobConf conf = new JobConf();
46      conf.set("chukwa.demux.mapper.default.processor",
47               "org.apache.hadoop.chukwa.extraction.demux.processor.mapper.MockMapProcessor");
48      mapper.configure(conf);
49  
50      ChunkBuilder cb = new ChunkBuilder();
51      cb.addRecord(SAMPLE_RECORD_DATA.getBytes());
52      ChunkImpl chunk = (ChunkImpl)cb.getChunk();
53  
54      ChukwaTestOutputCollector<ChukwaRecordKey, ChukwaRecord> output =
55              new ChukwaTestOutputCollector<ChukwaRecordKey, ChukwaRecord>();
56  
57      mapper.map(new ChukwaArchiveKey(), chunk, output, Reporter.NULL);
58      ChukwaRecordKey recordKey = new ChukwaRecordKey("someReduceType", SAMPLE_RECORD_DATA);
59  
60      assertEquals("MockMapProcessor never invoked - no records found", 1, output.data.size());
61      assertNotNull("MockMapProcessor never invoked", output.data.get(recordKey));
62    }
63  }