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 org.apache.hadoop.conf.Configuration;
19  import org.apache.hadoop.hbase.HBaseTestingUtility;
20  import org.apache.hadoop.hbase.testclassification.MediumTests;
21  import org.apache.hadoop.hbase.TableName;
22  import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
23  import org.apache.hadoop.hbase.util.Bytes;
24  import org.junit.AfterClass;
25  import org.junit.BeforeClass;
26  import org.junit.Test;
27  import org.junit.experimental.categories.Category;
28  
29  import static org.junit.Assert.assertEquals;
30  
31  @Category(MediumTests.class)
32  public class TestHRegionPartitioner {
33    private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
34  
35    @BeforeClass
36    public static void beforeClass() throws Exception {
37      UTIL.setJobWithoutMRCluster();
38      UTIL.startMiniCluster();
39    }
40  
41    @AfterClass
42    public static void afterClass() throws Exception {
43      UTIL.shutdownMiniCluster();
44    }
45  
46    /**
47     * Test HRegionPartitioner
48     */
49    @Test (timeout=300000)
50    public void testHRegionPartitioner() throws Exception {
51  
52      byte[][] families = { Bytes.toBytes("familyA"), Bytes.toBytes("familyB") };
53  
54      UTIL.createTable(TableName.valueOf("out_table"), families, 1,
55      Bytes.toBytes("aa"), Bytes.toBytes("cc"), 3);
56  
57      HRegionPartitioner<Long, Long> partitioner = new HRegionPartitioner<Long, Long>();
58      Configuration configuration = UTIL.getConfiguration();
59      configuration.set(TableOutputFormat.OUTPUT_TABLE, "out_table");
60      partitioner.setConf(configuration);
61      ImmutableBytesWritable writable = new ImmutableBytesWritable(Bytes.toBytes("bb"));
62  
63      assertEquals(1, partitioner.getPartition(writable, 10L, 3));
64      assertEquals(0, partitioner.getPartition(writable, 10L, 1));
65    }
66  }