@Test(timeout = 6_000L) public void testRandomFragmentation() {

    MemoryBuffer[] memBuffers8B = new MemoryBuffer[64];
    MemoryBuffer[] memBuffers16B = new MemoryBuffer[16];
    MemoryBuffer[] memBuffers32B = new MemoryBuffer[8];
    for (MemoryBuffer memoryBuffer : memBuffers8B) {
      Assert.assertNull(memoryBuffer);
    }

    allocator.allocateMultiple(memBuffers8B, 8, null);
    allocator.allocateMultiple(memBuffers16B, 16, null);
    allocator.allocateMultiple(memBuffers32B, 32, null);
    //all the cache is allocated with 8 X 128
    Assert.assertEquals(maxSize, ((LowLevelCacheMemoryManager) memoryManager).getCurrentUsedSize());

    for (int i = 0; i < memBuffers8B.length; i++) {
      LlapDataBuffer buffer = (LlapDataBuffer) memBuffers8B[i];
      // this is needed to make sure that the policy adds the buffers to the linked list as buffers ready to be evicted
      cachePolicy.notifyUnlock(buffer);
      // lock some buffers
      if (i % 2 == 0) {
        // lock the even buffers
        buffer.incRef();
      }
    }

    for (int i = 0; i < memBuffers16B.length; i++) {
      LlapDataBuffer buffer = (LlapDataBuffer) memBuffers16B[i];
      // this is needed to make sure that the policy adds the buffers to the linked list as buffers ready to be evicted
      cachePolicy.notifyUnlock(buffer);
      // lock some buffers
      if (i % 2 == 0) {
        // lock the even buffers
        buffer.incRef();
      }
    }

    for (int i = 0; i < memBuffers32B.length; i++) {
      LlapDataBuffer buffer = (LlapDataBuffer) memBuffers32B[i];
      // this is needed to make sure that the policy adds the buffers to the linked list as buffers ready to be evicted
      cachePolicy.notifyUnlock(buffer);
      // lock some buffers
      if (i % 2 == 0) {
        // lock the even buffers
        buffer.incRef();
      }
    }
    Assert.assertEquals(512, ((LowLevelCacheMemoryManager) memoryManager).purge());

    for (MemoryBuffer memoryBuffer : memBuffers32B) {
      LlapDataBuffer buffer = (LlapDataBuffer) memoryBuffer;
      // this is needed to make sure that the policy adds the buffers to the linked list as buffers ready to be evicted
      if (buffer.isLocked()) {
        buffer.decRef();
      }
      cachePolicy.notifyUnlock(buffer);
    }

    for (MemoryBuffer memoryBuffer : memBuffers16B) {
      LlapDataBuffer buffer = (LlapDataBuffer) memoryBuffer;
      // this is needed to make sure that the policy adds the buffers to the linked list as buffers ready to be evicted
      if (buffer.isLocked()) {
        buffer.decRef();
      }
      cachePolicy.notifyUnlock(buffer);
    }

    for (MemoryBuffer memoryBuffer : memBuffers8B) {
      LlapDataBuffer buffer = (LlapDataBuffer) memoryBuffer;
      // this is needed to make sure that the policy adds the buffers to the linked list as buffers ready to be evicted
      if (buffer.isLocked()) {
        buffer.decRef();
      }
      cachePolicy.notifyUnlock(buffer);
    }
    Assert.assertEquals(maxSize / 2, ((LowLevelCacheMemoryManager) memoryManager).getCurrentUsedSize());

    memBuffers8B = new MemoryBuffer[64];
    memBuffers16B = new MemoryBuffer[16];
    memBuffers32B = new MemoryBuffer[8];
    evictionTracker.getEvicted().clear();
    allocator.allocateMultiple(memBuffers16B, 16, null);
    allocator.allocateMultiple(memBuffers8B, 8, null);
    allocator.allocateMultiple(memBuffers32B, 32, null);
    Assert.assertEquals(maxSize, ((LowLevelCacheMemoryManager) memoryManager).getCurrentUsedSize());
    Assert.assertEquals(memBuffers32B.length / 2 + memBuffers16B.length / 2 + memBuffers8B.length / 2, evictionTracker.getEvicted().size());
    for (MemoryBuffer memoryBuffer : memBuffers8B) {
      LlapDataBuffer buffer = (LlapDataBuffer) memoryBuffer;
      allocator.deallocate(buffer);
    }
    for (MemoryBuffer memoryBuffer : memBuffers16B) {
      LlapDataBuffer buffer = (LlapDataBuffer) memoryBuffer;
      allocator.deallocate(buffer);
    }

    for (MemoryBuffer memoryBuffer : memBuffers32B) {
      LlapDataBuffer buffer = (LlapDataBuffer) memoryBuffer;
      allocator.deallocate(buffer);
    }
  }
Test case to ensure that deallocate it does merge small blocks into bigger ones.
llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestCacheAllocationsEvictionsCycles.java