@Test
  public void testOffHeapMemoryAttributes() {
    MemberMXBean memberMXBean = getSystemManagementService().getMemberMXBean();
    sampleStatistics();

    int initialLargestFragment = (int) (((4096 * BYTES_PER_MEGABYTE) / 2) - 1);
    assertThat(memberMXBean.getOffHeapFragments()).isEqualTo(2);
    assertThat(memberMXBean.getOffHeapLargestFragment()).isEqualTo(initialLargestFragment);
    assertThat(memberMXBean.getOffHeapFreedChunks()).isEqualTo(0);

    RegionFactory regionFactory =
        getCache().createRegionFactory(PARTITION_REDUNDANT);
    regionFactory.setConcurrencyChecksEnabled(false);
    regionFactory.setOffHeap(true);

    regionFactory.create("testPRRegion1");
    Region region1 = getCache().getRegion(SEPARATOR + "testPRRegion1");

    // fill first fragment
    int hugeAllocations = 100;
    for (int i = 0; i < hugeAllocations; i++) {
      region1.put(i + 10, new byte[initialLargestFragment / hugeAllocations]);
    }
    for (int i = 0; i < hugeAllocations; i++) {
      region1.remove(i + 10);
    }

    region1.put(1, new byte[100]);
    region1.remove(1);
    // Release the memory of the object so that the next allocation reuses the freed chunk
    region1.put(2, new byte[100]);
    region1.remove(2);
    region1.put(3, new byte[200]);
    region1.remove(3);

    sampleStatistics();

    assertThat(memberMXBean.getOffHeapFragments()).isEqualTo(2);
    await().untilAsserted(() -> assertThat(memberMXBean.getOffHeapLargestFragment())
        .isLessThan(initialLargestFragment));
    await().untilAsserted(
        () -> assertThat(memberMXBean.getOffHeapFreedChunks()).isEqualTo(hugeAllocations + 2));
  }
Distributed tests for {@link MemberMXBean} attributes.
geode-core/src/distributedTest/java/org/apache/geode/management/MemberMXBeanAttributesDistributedTest.java