public static LlapAllocatorBuffer[] prepareAllocatorWithSmallFragments(BuddyAllocator a,
      int baseSize, boolean deallocOneFirst, boolean deallocOneSecond, boolean doIncRef) {
    // Allocate 2-1-1-2-1-1; free 0,3 and optionally 1 or 5; allocate 4
    int offset = 0;
    LlapAllocatorBuffer[] initial = new LlapAllocatorBuffer[6];
    initial[offset++] = allocate(a, 1, baseSize * 2, offset + 1, doIncRef)[0];
    MemoryBuffer[] tmp = allocate(a, 2, baseSize, offset + 1);
    System.arraycopy(tmp, 0, initial, offset, 2);
    offset += 2;
    initial[offset++] = allocate(a, 1, baseSize * 2, offset + 1, doIncRef)[0];
    tmp = allocate(a, 2, baseSize, offset + 1);
    System.arraycopy(tmp, 0, initial, offset, 2);
    if (deallocOneFirst) {
      a.deallocate(initial[1]);
    }
    if (deallocOneSecond) {
      a.deallocate(initial[5]);
    }
    a.deallocate(initial[0]);
    a.deallocate(initial[3]);
    LOG.info("Before: " + a.testDump());
    a.setOomLoggingForTest(true);
    return initial;
  }
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