### Question:
SkipListArena { public MemorySlice allocateBytes(int size) { assert size >= 0; if (size > maxAlloc) { return null; } while (true) { Chunk c = getCurrentChunk(); int allocOffset = c.alloc(size); if (allocOffset != -1) { return new MemorySlice(c.data, allocOffset); } retireCurrentChunk(c); } } SkipListArena(ServerConfiguration cfg); MemorySlice allocateBytes(int size);  }### Answer:
@Test public void testRandomAllocation() { Random rand = new Random(); SkipListArena arena = new SkipListArena(cfg); int expectedOff = 0; byte[] lastBuffer = null; for (int i = 0; i < 10000; i++) { int size = rand.nextInt(512); MemorySlice alloc = arena.allocateBytes(size); if (alloc.getData() != lastBuffer) { expectedOff = 0; lastBuffer = alloc.getData(); } assertTrue(expectedOff == alloc.getOffset()); assertTrue("Allocation " + alloc + " overruns buffer", alloc.getOffset() + size <= alloc.getData().length); expectedOff += size; } }
@Test public void testLargeAllocation() { SkipListArena arena = new SkipListArena(cfg); MemorySlice alloc = arena.allocateBytes(1024 + 1024); assertNull("2KB allocation shouldn't be satisfied by LAB.", alloc); }