@Test(timeout = 6_000L) public void testMergeOfBlocksAfterDeallocate() {
    // allocate blocks of cacheSize/16, Then deallocate then Allocate of size cacheSize/2
    MemoryBuffer[] dest = new MemoryBuffer[16];
    for (MemoryBuffer memoryBuffer : dest) {
      Assert.assertNull(memoryBuffer);
    }
    allocator.allocateMultiple(dest, 64, null);
    //Check that everything is allocated
    Assert.assertEquals(maxSize, ((LowLevelCacheMemoryManager) memoryManager).getCurrentUsedSize());
    for (MemoryBuffer value : dest) {
      cachePolicy.notifyUnlock((LlapCacheableBuffer) value);
    }
    for (MemoryBuffer value : dest) {
      Assert.assertTrue(value instanceof LlapDataBuffer);
      LlapDataBuffer buffer = (LlapDataBuffer) value;
      Assert.assertEquals(buffer.getMemoryUsage(), cachePolicy.evictSomeBlocks(buffer.getMemoryUsage()));
      memoryManager.releaseMemory(buffer.getMemoryUsage());
    }

    // All is deAllocated thus used has to be zero
    Assert.assertEquals(0, ((LowLevelCacheMemoryManager) memoryManager).getCurrentUsedSize());
    MemoryBuffer[] dest2 = new MemoryBuffer[2];
    for (MemoryBuffer memoryBuffer : dest2) {
      Assert.assertNull(memoryBuffer);
    }
    allocator.allocateMultiple(dest2, 512, null);
    Assert.assertEquals(maxSize, ((LowLevelCacheMemoryManager) memoryManager).getCurrentUsedSize());
    for (int i = 0; i < dest2.length; i++) {
      Assert.assertNotNull(dest[i]);
      //we are not calling deallocate evict to avoid extra memory manager free calls
      allocator.deallocate(dest2[i]);
    }
    Assert.assertEquals(0, ((LowLevelCacheMemoryManager) memoryManager).getCurrentUsedSize());
  }
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