@Test
  public void testByteArrayAllocation() {
    GemFireCacheImpl gfc = createCache();
    try {
      MemoryAllocator ma = gfc.getOffHeapStore();
      assertNotNull(ma);
      final long offHeapSize = ma.getFreeMemory();
      assertEquals(0, ma.getUsedMemory());
      byte[] data = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};
      StoredObject mc1 = ma.allocateAndInitialize(data, false, false);
      assertEquals(data.length + perObjectOverhead(), ma.getUsedMemory());
      assertEquals(offHeapSize - (data.length + perObjectOverhead()), ma.getFreeMemory());
      byte[] data2 = new byte[data.length];
      mc1.readDataBytes(0, data2);
      assertTrue(Arrays.equals(data, data2));
      mc1.release();
      assertEquals(offHeapSize, ma.getFreeMemory());
      assertEquals(0, ma.getUsedMemory());
      // try some small byte[] that don't need to be stored off heap.
      data = new byte[] {1, 2, 3, 4, 5, 6, 7};
      StoredObject so1 = ma.allocateAndInitialize(data, false, false);
      assertEquals(0, ma.getUsedMemory());
      assertEquals(offHeapSize, ma.getFreeMemory());
      data2 = new byte[data.length];
      data2 = (byte[]) so1.getDeserializedForReading();
      assertTrue(Arrays.equals(data, data2));
    } finally {
      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