Skip to content

Commit 8a9968b

Browse files
committed
add hregionlocation test case
1 parent 61b48c2 commit 8a9968b

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

src/test/java/com/alipay/oceanbase/hbase/OHConnectionTest.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
import com.alipay.oceanbase.hbase.util.OHBufferedMutatorImpl;
2121
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
2222
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.*;
2724
import org.apache.hadoop.hbase.client.*;
2825
import org.apache.hadoop.hbase.util.Bytes;
2926
import org.apache.hadoop.hbase.util.Threads;
@@ -992,6 +989,52 @@ public void testRangePartitionWithRegionLocator() throws Exception {
992989
});
993990
}
994991
}
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+
9951038
@Test
9961039
public void testKeyPartitionWithRegionLocator() throws IOException {
9971040
final String tableNameStr = "test_multi_cf";

0 commit comments

Comments
 (0)