@Test
  public void testSizeAllocation() {
    // prevent cache from closing in reaction to ooom
    System.setProperty(OffHeapStorage.STAY_CONNECTED_ON_OUTOFOFFHEAPMEMORY_PROPERTY, "true");
    GemFireCacheImpl gfc = createCache();
    try {
      MemoryAllocator ma = gfc.getOffHeapStore();
      assertNotNull(ma);
      final long offHeapSize = ma.getFreeMemory();
      assertEquals(0, ma.getUsedMemory());
      StoredObject mc1 = ma.allocate(64);
      assertEquals(64 + perObjectOverhead(), ma.getUsedMemory());
      assertEquals(offHeapSize - (64 + perObjectOverhead()), ma.getFreeMemory());
      mc1.release();
      assertEquals(offHeapSize, ma.getFreeMemory());
      assertEquals(0, ma.getUsedMemory());
      // do an allocation larger than the slab size
      // TODO: currently the defragment will produce slabs bigger than the max slab size
      // (see the todo comment on defragment() in FreeListManager).
      // So we request 20m here since that it the total size.
      try {
        ma.allocate(1024 * 1024 * 20);
        fail("Expected an out of heap exception");
      } catch (OutOfOffHeapMemoryException ignored) {
      }
      assertEquals(0, ma.getUsedMemory());
      assertFalse(gfc.isClosed());
    } finally {
      System.clearProperty(OffHeapStorage.STAY_CONNECTED_ON_OUTOFOFFHEAPMEMORY_PROPERTY);
      closeCache(gfc, false);
    }
  }
Basic test of regions that use off heap storage. Subclasses exist for the different types of
offheap store.
geode-core/src/integrationTest/java/org/apache/geode/internal/offheap/OffHeapRegionBase.java