@Test
  public void testTotalHeapSize() throws Exception {
    initManagement(false);
    long totalHeapSizeOnAll = 0;
    for (VM vm : managedNodeList) {
      totalHeapSizeOnAll = totalHeapSizeOnAll
          + ((Number) vm.invoke(TestHeapDUnitTest::getHeapSizeOfClient)).longValue();
    }
    long totalHeapSizeFromMXBean =
        ((Number) managingNode.invoke(TestHeapDUnitTest::getHeapSizeOfDS)).intValue();

    LogWriterUtils.getLogWriter().info("testTotalHeapSize totalHeapSizeFromMXBean = "
        + totalHeapSizeFromMXBean + " totalHeapSizeOnAll = " + totalHeapSizeOnAll);

    assertNotSame(0, totalHeapSizeFromMXBean);
    assertNotSame(0, totalHeapSizeOnAll);
    assertNotSame(0,
        totalHeapSizeFromMXBean - totalHeapSizeOnAll > 0
            ? (totalHeapSizeFromMXBean - totalHeapSizeOnAll)
            : (-1 * (totalHeapSizeFromMXBean - totalHeapSizeOnAll)));
  }
This is for testing heap size from Mbean
geode-core/src/distributedTest/java/org/apache/geode/management/internal/pulse/TestHeapDUnitTest.java