1
2
3
4
5
6
7
8
9
10
11
12
13
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
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 }