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    /*
38     * initTableSnapshotMapperJob is tested in {@link TestTableSnapshotInputFormat} because
39     * the method depends on an online cluster.
40     */
41  
42    @Test
43    public void testInitTableMapperJob1() throws Exception {
44      Configuration configuration = new Configuration();
45      Job job = new Job(configuration, "tableName");
46      // test 
47      TableMapReduceUtil.initTableMapperJob("Table", new Scan(), Import.Importer.class, Text.class,
48          Text.class, job, false, HLogInputFormat.class);
49      assertEquals(HLogInputFormat.class, job.getInputFormatClass());
50      assertEquals(Import.Importer.class, job.getMapperClass());
51      assertEquals(LongWritable.class, job.getOutputKeyClass());
52      assertEquals(Text.class, job.getOutputValueClass());
53      assertNull(job.getCombinerClass());
54      assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
55    }
56  
57    @Test
58    public void testInitTableMapperJob2() throws Exception {
59      Configuration configuration = new Configuration();
60      Job job = new Job(configuration, "tableName");
61      TableMapReduceUtil.initTableMapperJob(Bytes.toBytes("Table"), new Scan(),
62          Import.Importer.class, Text.class, Text.class, job, false, HLogInputFormat.class);
63      assertEquals(HLogInputFormat.class, job.getInputFormatClass());
64      assertEquals(Import.Importer.class, job.getMapperClass());
65      assertEquals(LongWritable.class, job.getOutputKeyClass());
66      assertEquals(Text.class, job.getOutputValueClass());
67      assertNull(job.getCombinerClass());
68      assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
69    }
70  
71    @Test
72    public void testInitTableMapperJob3() throws Exception {
73      Configuration configuration = new Configuration();
74      Job job = new Job(configuration, "tableName");
75      TableMapReduceUtil.initTableMapperJob(Bytes.toBytes("Table"), new Scan(),
76          Import.Importer.class, Text.class, Text.class, job);
77      assertEquals(TableInputFormat.class, job.getInputFormatClass());
78      assertEquals(Import.Importer.class, job.getMapperClass());
79      assertEquals(LongWritable.class, job.getOutputKeyClass());
80      assertEquals(Text.class, job.getOutputValueClass());
81      assertNull(job.getCombinerClass());
82      assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
83    }
84  
85    @Test
86    public void testInitTableMapperJob4() throws Exception {
87      Configuration configuration = new Configuration();
88      Job job = new Job(configuration, "tableName");
89      TableMapReduceUtil.initTableMapperJob(Bytes.toBytes("Table"), new Scan(),
90          Import.Importer.class, Text.class, Text.class, job, false);
91      assertEquals(TableInputFormat.class, job.getInputFormatClass());
92      assertEquals(Import.Importer.class, job.getMapperClass());
93      assertEquals(LongWritable.class, job.getOutputKeyClass());
94      assertEquals(Text.class, job.getOutputValueClass());
95      assertNull(job.getCombinerClass());
96      assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
97    }
98  }