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.MediumTests;
21  import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
22  import org.apache.hadoop.hbase.util.Bytes;
23  import org.junit.AfterClass;
24  import org.junit.BeforeClass;
25  import org.junit.Test;
26  import org.junit.experimental.categories.Category;
27  
28  import static org.junit.Assert.assertEquals;
29  
30  @Category(MediumTests.class)
31  public class TestHRegionPartitioner {
32    private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
33  
34    @BeforeClass
35    public static void beforeClass() throws Exception {
36      UTIL.startMiniCluster();
37      UTIL.startMiniMapReduceCluster();
38    }
39  
40    @AfterClass
41    public static void afterClass() throws Exception {
42      UTIL.shutdownMiniMapReduceCluster();
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(Bytes.toBytes("out_table"), families, 1, Bytes.toBytes("aa"),
55          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  }