|
20 | 20 | import com.alipay.oceanbase.hbase.util.OHBufferedMutatorImpl;
|
21 | 21 | import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
|
22 | 22 | import org.apache.hadoop.conf.Configuration;
|
23 |
| -import org.apache.hadoop.hbase.Cell; |
24 |
| -import org.apache.hadoop.hbase.CellUtil; |
25 |
| -import org.apache.hadoop.hbase.HConstants; |
26 |
| -import org.apache.hadoop.hbase.TableName; |
| 23 | +import org.apache.hadoop.hbase.*; |
27 | 24 | import org.apache.hadoop.hbase.client.*;
|
28 | 25 | import org.apache.hadoop.hbase.util.Bytes;
|
29 | 26 | import org.apache.hadoop.hbase.util.Threads;
|
@@ -992,6 +989,52 @@ public void testRangePartitionWithRegionLocator() throws Exception {
|
992 | 989 | });
|
993 | 990 | }
|
994 | 991 | }
|
| 992 | + |
| 993 | + @Test |
| 994 | + public void testHRegionLocation() throws IOException { |
| 995 | + final String tableNameStr = "test_region_locator"; |
| 996 | + |
| 997 | + final byte[][] splitPoints = new byte[][] { |
| 998 | + Bytes.toBytes("c"), // p1: < 'c' |
| 999 | + Bytes.toBytes("e"), // p2: < 'e' |
| 1000 | + Bytes.toBytes("g"), // p3: < 'g' |
| 1001 | + Bytes.toBytes("i"), // p4: < 'i' |
| 1002 | + Bytes.toBytes("l"), // p5: < 'l' |
| 1003 | + Bytes.toBytes("n"), // p6: < 'n' |
| 1004 | + Bytes.toBytes("p"), // p7: < 'p' |
| 1005 | + Bytes.toBytes("s"), // p8: < 's' |
| 1006 | + Bytes.toBytes("v") // p9: < 'v' |
| 1007 | + }; |
| 1008 | + |
| 1009 | + final TableName tableName = TableName.valueOf(tableNameStr); |
| 1010 | + final Configuration conf = ObHTableTestUtil.newConfiguration(); |
| 1011 | + connection = ConnectionFactory.createConnection(conf); |
| 1012 | + hTable = connection.getTable(tableName); |
| 1013 | + // (min, c), [c, e), [e, g), [g, i), [i, l), [l, n), [n, p), [p, s), [s, v), [v, max) |
| 1014 | + try (RegionLocator locator = connection.getRegionLocator(tableName)) { |
| 1015 | + Assert.assertEquals(locator.getStartKeys().length, locator.getEndKeys().length); |
| 1016 | + Assert.assertEquals(locator.getStartKeys().length, 10); |
| 1017 | + HRegionLocation loc = locator.getRegionLocation(HConstants.EMPTY_BYTE_ARRAY); |
| 1018 | + RegionInfo info = loc.getRegion(); |
| 1019 | + Assert.assertEquals(Arrays.toString(locator.getStartKeys()[0]), Arrays.toString(info.getStartKey())); |
| 1020 | + Assert.assertEquals(Arrays.toString(locator.getEndKeys()[0]), Arrays.toString(info.getEndKey())); |
| 1021 | + for (int i = 1; i < locator.getStartKeys().length; i++) { |
| 1022 | + loc = locator.getRegionLocation(splitPoints[i - 1]); |
| 1023 | + info = loc.getRegion(); |
| 1024 | + Assert.assertEquals(Arrays.toString(locator.getStartKeys()[i]), Arrays.toString(info.getStartKey())); |
| 1025 | + Assert.assertEquals(Arrays.toString(locator.getEndKeys()[i]), Arrays.toString(info.getEndKey())); |
| 1026 | + } |
| 1027 | + } finally { |
| 1028 | + Optional.ofNullable(hTable).ifPresent(table -> { |
| 1029 | + try { |
| 1030 | + table.close(); |
| 1031 | + } catch (IOException e) { |
| 1032 | + e.printStackTrace(); |
| 1033 | + } |
| 1034 | + }); |
| 1035 | + } |
| 1036 | + } |
| 1037 | + |
995 | 1038 | @Test
|
996 | 1039 | public void testKeyPartitionWithRegionLocator() throws IOException {
|
997 | 1040 | final String tableNameStr = "test_multi_cf";
|
|
0 commit comments