Exemplo n.º 1
0
 @Test
 public void testReturns() {
   Slab slab = new Slab(0, SLAB_SIZE, PAGE_SIZE);
   ByteBuffer[] pages = new ByteBuffer[PAGES];
   // Take all pages
   for (int p = 0; p < PAGES; p++) {
     pages[p] = slab.takePageBuffer();
   }
   // Put them back
   for (int p = 0; p < PAGES; p++) {
     slab.returnPageBuffer(pages[p]);
   }
   // Take them again
   int[] arrayOffsets = new int[PAGES];
   for (int p = 0; p < PAGES; p++) {
     ByteBuffer buffer = slab.takePageBuffer();
     assertNotNull(buffer);
     assertEquals(0, buffer.position());
     assertEquals(PAGE_SIZE, buffer.limit());
     arrayOffsets[p] = buffer.arrayOffset();
   }
   assertNull(slab.takePageBuffer());
   Arrays.sort(arrayOffsets);
   int expectedArrayOffset = 0;
   for (int b = 0; b < PAGES; b++) {
     assertEquals(expectedArrayOffset, arrayOffsets[b]);
     expectedArrayOffset += PAGE_SIZE;
   }
 }
Exemplo n.º 2
0
 @Test
 public void testInitialAllocations() {
   Slab slab = new Slab(0, SLAB_SIZE, PAGE_SIZE);
   int[] arrayOffsets = new int[PAGES];
   for (int p = 0; p < PAGES; p++) {
     ByteBuffer buffer = slab.takePageBuffer();
     assertNotNull(buffer);
     assertEquals(0, buffer.position());
     assertEquals(PAGE_SIZE, buffer.limit());
     arrayOffsets[p] = buffer.arrayOffset();
   }
   assertNull(slab.takePageBuffer());
   Arrays.sort(arrayOffsets);
   int expectedArrayOffset = 0;
   for (int b = 0; b < PAGES; b++) {
     assertEquals(expectedArrayOffset, arrayOffsets[b]);
     expectedArrayOffset += PAGE_SIZE;
   }
 }