View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0
5    * (the "License"); you may not use this file except in compliance with the License. You may
6    * obtain a copy of the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software distributed under the
11   * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12   * either express or implied. See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.apache.hadoop.hbase.mapreduce;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNull;
20  
21  import org.apache.hadoop.conf.Configuration;
22  import org.apache.hadoop.hbase.SmallTests;
23  import org.apache.hadoop.hbase.client.Scan;
24  import org.apache.hadoop.hbase.util.Bytes;
25  import org.apache.hadoop.io.LongWritable;
26  import org.apache.hadoop.io.Text;
27  import org.apache.hadoop.mapreduce.Job;
28  import org.junit.Test;
29  import org.junit.experimental.categories.Category;
30  
31  /**
32   * Test different variants of initTableMapperJob method
33   */
34  @Category(SmallTests.class)
35  public class TestTableMapReduceUtil {
36  
37    @Test
38    public void testInitTableMapperJob1() throws Exception {
39      Configuration configuration = new Configuration();
40      Job job = new Job(configuration, "tableName");
41      // test 
42      TableMapReduceUtil.initTableMapperJob("Table", new Scan(), Import.Importer.class, Text.class,
43          Text.class, job, false, HLogInputFormat.class);
44      assertEquals(HLogInputFormat.class, job.getInputFormatClass());
45      assertEquals(Import.Importer.class, job.getMapperClass());
46      assertEquals(LongWritable.class, job.getOutputKeyClass());
47      assertEquals(Text.class, job.getOutputValueClass());
48      assertNull(job.getCombinerClass());
49      assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
50    }
51  
52    @Test
53    public void testInitTableMapperJob2() throws Exception {
54      Configuration configuration = new Configuration();
55      Job job = new Job(configuration, "tableName");
56      TableMapReduceUtil.initTableMapperJob(Bytes.toBytes("Table"), new Scan(),
57          Import.Importer.class, Text.class, Text.class, job, false, HLogInputFormat.class);
58      assertEquals(HLogInputFormat.class, job.getInputFormatClass());
59      assertEquals(Import.Importer.class, job.getMapperClass());
60      assertEquals(LongWritable.class, job.getOutputKeyClass());
61      assertEquals(Text.class, job.getOutputValueClass());
62      assertNull(job.getCombinerClass());
63      assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
64    }
65  
66    @Test
67    public void testInitTableMapperJob3() throws Exception {
68      Configuration configuration = new Configuration();
69      Job job = new Job(configuration, "tableName");
70      TableMapReduceUtil.initTableMapperJob(Bytes.toBytes("Table"), new Scan(),
71          Import.Importer.class, Text.class, Text.class, job);
72      assertEquals(TableInputFormat.class, job.getInputFormatClass());
73      assertEquals(Import.Importer.class, job.getMapperClass());
74      assertEquals(LongWritable.class, job.getOutputKeyClass());
75      assertEquals(Text.class, job.getOutputValueClass());
76      assertNull(job.getCombinerClass());
77      assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
78    }
79  
80    @Test
81    public void testInitTableMapperJob4() throws Exception {
82      Configuration configuration = new Configuration();
83      Job job = new Job(configuration, "tableName");
84      TableMapReduceUtil.initTableMapperJob(Bytes.toBytes("Table"), new Scan(),
85          Import.Importer.class, Text.class, Text.class, job, false);
86      assertEquals(TableInputFormat.class, job.getInputFormatClass());
87      assertEquals(Import.Importer.class, job.getMapperClass());
88      assertEquals(LongWritable.class, job.getOutputKeyClass());
89      assertEquals(Text.class, job.getOutputValueClass());
90      assertNull(job.getCombinerClass());
91      assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
92    }
93  }