@Test
  public void testGlobalMemStore() throws Exception {
    // Start the cluster
    LOG.info("Starting cluster");
    Configuration conf = HBaseConfiguration.create();
    TEST_UTIL = new HBaseTestingUtil(conf);
    TEST_UTIL.startMiniCluster(regionServerNum);
    cluster = TEST_UTIL.getHBaseCluster();
    LOG.info("Waiting for active/ready master");
    cluster.waitForActiveAndReadyMaster();

    // Create a table with regions
    final TableName table = TableName.valueOf(name.getMethodName());
    byte[] family = Bytes.toBytes("family");
    LOG.info("Creating table with " + regionNum + " regions");
    Table ht = TEST_UTIL.createMultiRegionTable(table, family, regionNum);
    int numRegions = -1;
    try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(table)) {
      numRegions = r.getStartKeys().length;
    }
    assertEquals(regionNum, numRegions);
    waitForAllRegionsAssigned();

    for (HRegionServer server : getOnlineRegionServers()) {
      long globalMemStoreSize = 0;
      for (RegionInfo regionInfo : ProtobufUtil.getOnlineRegions(null, server.getRSRpcServices())) {
        globalMemStoreSize += server.getRegion(regionInfo.getEncodedName()).getMemStoreDataSize();
      }
      assertEquals(server.getRegionServerAccounting().getGlobalMemStoreDataSize(),
        globalMemStoreSize);
    }

    // check the global memstore size after flush
    int i = 0;
    for (HRegionServer server : getOnlineRegionServers()) {
      LOG.info("Starting flushes on " + server.getServerName() + ", size="
        + server.getRegionServerAccounting().getGlobalMemStoreDataSize());

      for (RegionInfo regionInfo : ProtobufUtil.getOnlineRegions(null, server.getRSRpcServices())) {
        HRegion r = server.getRegion(regionInfo.getEncodedName());
        flush(r, server);
      }
      LOG.info("Post flush on " + server.getServerName());
      long now = EnvironmentEdgeManager.currentTime();
      long timeout = now + 1000;
      while (
        server.getRegionServerAccounting().getGlobalMemStoreDataSize() != 0
          && timeout < EnvironmentEdgeManager.currentTime()
      ) {
        Threads.sleep(10);
      }
      long size = server.getRegionServerAccounting().getGlobalMemStoreDataSize();
      if (size > 0) {
        // If size > 0, see if its because the meta region got edits while
        // our test was running....
        for (RegionInfo regionInfo : ProtobufUtil.getOnlineRegions(null,
          server.getRSRpcServices())) {
          HRegion r = server.getRegion(regionInfo.getEncodedName());
          long l = r.getMemStoreDataSize();
          if (l > 0) {
            // Only meta could have edits at this stage. Give it another flush
            // clear them.
            assertTrue(regionInfo.isMetaRegion());
            LOG.info(r.toString() + " " + l + ", reflushing");
            r.flush(true);
          }
        }
      }
      size = server.getRegionServerAccounting().getGlobalMemStoreDataSize();
      assertEquals("Server=" + server.getServerName() + ", i=" + i++, 0, size);
    }

    ht.close();
    TEST_UTIL.shutdownMiniCluster();
  }
Test the global mem store size in the region server is equal to sum of each region's mem store
size
hbase-server/src/test/java/org/apache/hadoop/hbase/TestGlobalMemStoreSize.java