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.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
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 }