@Test
  public void testConversion() {
    TableName tn = TableName.valueOf("table1");

    RegionInfo hri1 = RegionInfoBuilder.newBuilder(tn).setStartKey(Bytes.toBytes("a"))
      .setEndKey(Bytes.toBytes("b")).build();
    RegionInfo hri2 = RegionInfoBuilder.newBuilder(tn).setStartKey(Bytes.toBytes("b"))
      .setEndKey(Bytes.toBytes("c")).build();
    RegionInfo hri3 = RegionInfoBuilder.newBuilder(tn).setStartKey(Bytes.toBytes("c"))
      .setEndKey(Bytes.toBytes("d")).build();
    RegionSizeStore store = RegionSizeStoreFactory.getInstance().createStore();
    store.put(hri1, 1024L * 1024L);
    store.put(hri2, 1024L * 1024L * 8L);
    store.put(hri3, 1024L * 1024L * 32L);

    // Call the real method to convert the map into a protobuf
    HRegionServer rs = mock(HRegionServer.class);
    doCallRealMethod().when(rs).buildRegionSpaceUseReportRequest(any(RegionSizeStore.class));
    doCallRealMethod().when(rs).convertRegionSize(any(), anyLong());

    RegionSpaceUseReportRequest requests = rs.buildRegionSpaceUseReportRequest(store);
    assertEquals(store.size(), requests.getSpaceUseCount());
    for (RegionSpaceUse spaceUse : requests.getSpaceUseList()) {
      RegionInfo hri = ProtobufUtil.toRegionInfo(spaceUse.getRegionInfo());
      RegionSize expectedSize = store.remove(hri);
      assertNotNull("Could not find size for HRI: " + hri, expectedSize);
      assertEquals(expectedSize.getSize(), spaceUse.getRegionSize());
    }
    assertTrue("Should not have any space use entries left: " + store, store.isEmpty());
  }
Test class for isolated (non-cluster) tests surrounding the report of Region space use to the
Master by RegionServers.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRegionSpaceUseReport.java