use of io.cdap.cdap.hbase.wd.AbstractRowKeyDistributor in project cdap by caskdata.
the class HBaseTableUtilTest method testGetSplitKeys.
@Test
public void testGetSplitKeys() {
int buckets = 16;
AbstractRowKeyDistributor distributor = new RowKeyDistributorByHashPrefix(new RowKeyDistributorByHashPrefix.OneByteSimpleHash(buckets));
// Number of splits will be no less than user asked. If splits > buckets, the number of splits will bumped to
// next multiple of bucket that is no less than user splits requested.
// it should return one key less than required splits count, because HBase will take care of the first automatically
Assert.assertEquals(getSplitSize(buckets, 12) - 1, HBaseTableUtil.getSplitKeys(12, buckets, distributor).length);
Assert.assertEquals(getSplitSize(buckets, 16) - 1, HBaseTableUtil.getSplitKeys(16, buckets, distributor).length);
// at least #buckets - 1, but no less than user asked
Assert.assertEquals(buckets - 1, HBaseTableUtil.getSplitKeys(6, buckets, distributor).length);
Assert.assertEquals(buckets - 1, HBaseTableUtil.getSplitKeys(2, buckets, distributor).length);
// "1" can be used for queue tables that we know are not "hot", so we do not pre-split in this case
Assert.assertEquals(0, HBaseTableUtil.getSplitKeys(1, buckets, distributor).length);
// allows up to 255 * 8 - 1 splits
Assert.assertEquals(255 * buckets - 1, HBaseTableUtil.getSplitKeys(255 * buckets, buckets, distributor).length);
try {
HBaseTableUtil.getSplitKeys(256 * buckets, buckets, distributor);
Assert.fail("getSplitKeys(256) should have thrown IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
HBaseTableUtil.getSplitKeys(0, buckets, distributor);
Assert.fail("getSplitKeys(0) should have thrown IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
}
Aggregations