@Test
  public void unitTestHexStringSplit() {
    HexStringSplit splitter = new HexStringSplit();
    // Check splitting while starting from scratch

    byte[][] twoRegionsSplits = splitter.split(2);
    assertEquals(1, twoRegionsSplits.length);
    assertArrayEquals(Bytes.toBytes("80000000"), twoRegionsSplits[0]);

    byte[][] threeRegionsSplits = splitter.split(3);
    assertEquals(2, threeRegionsSplits.length);
    byte[] expectedSplit0 = Bytes.toBytes("55555555");
    assertArrayEquals(expectedSplit0, threeRegionsSplits[0]);
    byte[] expectedSplit1 = Bytes.toBytes("aaaaaaaa");
    assertArrayEquals(expectedSplit1, threeRegionsSplits[1]);

    // Check splitting existing regions that have start and end points
    byte[] splitPoint = splitter.split(Bytes.toBytes("10000000"), Bytes.toBytes("30000000"));
    assertArrayEquals(Bytes.toBytes("20000000"), splitPoint);

    byte[] lastRow = Bytes.toBytes("ffffffff");
    assertArrayEquals(lastRow, splitter.lastRow());
    byte[] firstRow = Bytes.toBytes("00000000");
    assertArrayEquals(firstRow, splitter.firstRow());

    // Halfway between 00... and 20... should be 10...
    splitPoint = splitter.split(firstRow, Bytes.toBytes("20000000"));
    assertArrayEquals(Bytes.toBytes("10000000"), splitPoint);

    // Halfway between df... and ff... should be ef....
    splitPoint = splitter.split(Bytes.toBytes("dfffffff"), lastRow);
    assertArrayEquals(Bytes.toBytes("efffffff"), splitPoint);

    // Check splitting region with multiple mappers per region
    byte[][] splits =
      splitter.split(Bytes.toBytes("00000000"), Bytes.toBytes("30000000"), 3, false);
    assertEquals(2, splits.length);
    assertArrayEquals(Bytes.toBytes("10000000"), splits[0]);
    assertArrayEquals(Bytes.toBytes("20000000"), splits[1]);

    splits = splitter.split(Bytes.toBytes("00000000"), Bytes.toBytes("20000000"), 2, true);
    assertEquals(3, splits.length);
    assertArrayEquals(Bytes.toBytes("10000000"), splits[1]);
  }
Unit tests for the HexStringSplit algorithm. Makes sure it divides up the space of keys in the
way that we expect.
hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java