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.extraction.engine.ChukwaRecordKey;
21  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
22  import org.apache.hadoop.chukwa.extraction.demux.processor.mapper.ChukwaTestOutputCollector;
23  import org.apache.hadoop.mapred.Reporter;
24  import org.apache.hadoop.mapred.JobConf;
25  import org.apache.hadoop.mapred.Reducer;
26  import junit.framework.TestCase;
27  
28  import java.io.IOException;
29  
30  /**
31   * Tests that settings related to the Demux mapper do what they should.
32   */
33  public class TestDemuxReducerConfigs extends TestCase {
34  
35    public static  String SAMPLE_RECORD_DATA = "sampleRecordData";
36  
37    public void testSetDefaultReducerProcessor() throws IOException {
38      Reducer<ChukwaRecordKey, ChukwaRecord, ChukwaRecordKey, ChukwaRecord> reducer =
39              new Demux.ReduceClass();
40  
41      JobConf conf = new JobConf();
42      conf.set("chukwa.demux.reducer.default.processor", "MockReduceProcessor");
43      reducer.configure(conf);
44  
45      ChukwaRecordKey key = new ChukwaRecordKey("someReduceType", "someKey");
46      ChukwaTestOutputCollector<ChukwaRecordKey, ChukwaRecord> output =
47              new ChukwaTestOutputCollector<ChukwaRecordKey, ChukwaRecord>();
48  
49      reducer.reduce(key, null, output, Reporter.NULL);
50  
51      assertEquals("MockReduceProcessor never invoked - no records found", 1, output.data.size());
52      assertNotNull("MockReduceProcessor never invoked", output.data.get(key));
53      assertEquals("MockReduceProcessor never invoked - key value incorrect",
54              "MockReduceProcessorValue",
55              output.data.get(key).getValue("MockReduceProcessorKey"));
56    }
57  }