001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.mapreduce;
019
020import static org.junit.Assert.assertEquals;
021import static org.junit.Assert.assertNull;
022
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.client.Scan;
026import org.apache.hadoop.hbase.testclassification.MapReduceTests;
027import org.apache.hadoop.hbase.testclassification.SmallTests;
028import org.apache.hadoop.hbase.util.Bytes;
029import org.apache.hadoop.io.LongWritable;
030import org.apache.hadoop.io.Text;
031import org.apache.hadoop.mapreduce.Job;
032import org.junit.ClassRule;
033import org.junit.Test;
034import org.junit.experimental.categories.Category;
035
036/**
037 * Test different variants of initTableMapperJob method
038 */
039@Category({MapReduceTests.class, SmallTests.class})
040public class TestTableMapReduceUtil {
041
042  @ClassRule
043  public static final HBaseClassTestRule CLASS_RULE =
044      HBaseClassTestRule.forClass(TestTableMapReduceUtil.class);
045
046  /*
047   * initTableSnapshotMapperJob is tested in {@link TestTableSnapshotInputFormat} because
048   * the method depends on an online cluster.
049   */
050
051  @Test
052  public void testInitTableMapperJob1() throws Exception {
053    Configuration configuration = new Configuration();
054    Job job = new Job(configuration, "tableName");
055    // test
056    TableMapReduceUtil.initTableMapperJob("Table", new Scan(), Import.Importer.class, Text.class,
057        Text.class, job, false, WALInputFormat.class);
058    assertEquals(WALInputFormat.class, job.getInputFormatClass());
059    assertEquals(Import.Importer.class, job.getMapperClass());
060    assertEquals(LongWritable.class, job.getOutputKeyClass());
061    assertEquals(Text.class, job.getOutputValueClass());
062    assertNull(job.getCombinerClass());
063    assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
064  }
065
066  @Test
067  public void testInitTableMapperJob2() throws Exception {
068    Configuration configuration = new Configuration();
069    Job job = new Job(configuration, "tableName");
070    TableMapReduceUtil.initTableMapperJob(Bytes.toBytes("Table"), new Scan(),
071        Import.Importer.class, Text.class, Text.class, job, false, WALInputFormat.class);
072    assertEquals(WALInputFormat.class, job.getInputFormatClass());
073    assertEquals(Import.Importer.class, job.getMapperClass());
074    assertEquals(LongWritable.class, job.getOutputKeyClass());
075    assertEquals(Text.class, job.getOutputValueClass());
076    assertNull(job.getCombinerClass());
077    assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
078  }
079
080  @Test
081  public void testInitTableMapperJob3() throws Exception {
082    Configuration configuration = new Configuration();
083    Job job = new Job(configuration, "tableName");
084    TableMapReduceUtil.initTableMapperJob(Bytes.toBytes("Table"), new Scan(),
085        Import.Importer.class, Text.class, Text.class, job);
086    assertEquals(TableInputFormat.class, job.getInputFormatClass());
087    assertEquals(Import.Importer.class, job.getMapperClass());
088    assertEquals(LongWritable.class, job.getOutputKeyClass());
089    assertEquals(Text.class, job.getOutputValueClass());
090    assertNull(job.getCombinerClass());
091    assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
092  }
093
094  @Test
095  public void testInitTableMapperJob4() throws Exception {
096    Configuration configuration = new Configuration();
097    Job job = new Job(configuration, "tableName");
098    TableMapReduceUtil.initTableMapperJob(Bytes.toBytes("Table"), new Scan(),
099        Import.Importer.class, Text.class, Text.class, job, false);
100    assertEquals(TableInputFormat.class, job.getInputFormatClass());
101    assertEquals(Import.Importer.class, job.getMapperClass());
102    assertEquals(LongWritable.class, job.getOutputKeyClass());
103    assertEquals(Text.class, job.getOutputValueClass());
104    assertNull(job.getCombinerClass());
105    assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE));
106  }
107}