public static LlapAllocatorBuffer[] allocate(
      BuddyAllocator a, int count, int size, int baseValue, boolean doIncRef) {
    LlapAllocatorBuffer[] allocs = new LlapAllocatorBuffer[count];
    try {
      a.allocateMultiple(allocs, size);
    } catch (AllocatorOutOfMemoryException ex) {
      LOG.error("Failed to allocate " + allocs.length + " of " + size + "; " + a.testDump());
      throw ex;
    }
    for (int i = 0; i < count; ++i) {
      // Make sure buffers are eligible for discard.
      if (doIncRef) {
        int rc = allocs[i].incRef();
        assertTrue(rc > 0);
      }
      TestBuddyAllocator.putTestValue(allocs[i], baseValue + i);
      if (doIncRef) {
        allocs[i].decRef();
      }
    }
    return allocs;
  }
This relies on allocations basically being sequential, no internal reordering. Rather,
the specific paths it takes do; all the scenarios should work regardless of allocation.
llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocatorForceEvict.java