Search in sources :

Example 1 with SharedFileDescriptorFactory

use of org.apache.hadoop.io.nativeio.SharedFileDescriptorFactory in project hadoop by apache.

the class TestShortCircuitShm method testAllocateSlots.

@Test(timeout = 60000)
public void testAllocateSlots() throws Exception {
    File path = new File(TEST_BASE, "testAllocateSlots");
    path.mkdirs();
    SharedFileDescriptorFactory factory = SharedFileDescriptorFactory.create("shm_", new String[] { path.getAbsolutePath() });
    FileInputStream stream = factory.createDescriptor("testAllocateSlots", 4096);
    ShortCircuitShm shm = new ShortCircuitShm(ShmId.createRandom(), stream);
    int numSlots = 0;
    ArrayList<Slot> slots = new ArrayList<Slot>();
    while (!shm.isFull()) {
        Slot slot = shm.allocAndRegisterSlot(new ExtendedBlockId(123L, "test_bp1"));
        slots.add(slot);
        numSlots++;
    }
    LOG.info("allocated " + numSlots + " slots before running out.");
    int slotIdx = 0;
    for (Iterator<Slot> iter = shm.slotIterator(); iter.hasNext(); ) {
        Assert.assertTrue(slots.contains(iter.next()));
    }
    for (Slot slot : slots) {
        Assert.assertFalse(slot.addAnchor());
        Assert.assertEquals(slotIdx++, slot.getSlotIdx());
    }
    for (Slot slot : slots) {
        slot.makeAnchorable();
    }
    for (Slot slot : slots) {
        Assert.assertTrue(slot.addAnchor());
    }
    for (Slot slot : slots) {
        slot.removeAnchor();
    }
    for (Slot slot : slots) {
        shm.unregisterSlot(slot.getSlotIdx());
        slot.makeInvalid();
    }
    shm.free();
    stream.close();
    FileUtil.fullyDelete(path);
}
Also used : ExtendedBlockId(org.apache.hadoop.hdfs.ExtendedBlockId) ArrayList(java.util.ArrayList) Slot(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.Slot) File(java.io.File) FileInputStream(java.io.FileInputStream) SharedFileDescriptorFactory(org.apache.hadoop.io.nativeio.SharedFileDescriptorFactory) Test(org.junit.Test)

Example 2 with SharedFileDescriptorFactory

use of org.apache.hadoop.io.nativeio.SharedFileDescriptorFactory in project hadoop by apache.

the class TestShortCircuitShm method testStartupShutdown.

@Test(timeout = 60000)
public void testStartupShutdown() throws Exception {
    File path = new File(TEST_BASE, "testStartupShutdown");
    path.mkdirs();
    SharedFileDescriptorFactory factory = SharedFileDescriptorFactory.create("shm_", new String[] { path.getAbsolutePath() });
    FileInputStream stream = factory.createDescriptor("testStartupShutdown", 4096);
    ShortCircuitShm shm = new ShortCircuitShm(ShmId.createRandom(), stream);
    shm.free();
    stream.close();
    FileUtil.fullyDelete(path);
}
Also used : File(java.io.File) FileInputStream(java.io.FileInputStream) SharedFileDescriptorFactory(org.apache.hadoop.io.nativeio.SharedFileDescriptorFactory) Test(org.junit.Test)

Aggregations

File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 SharedFileDescriptorFactory (org.apache.hadoop.io.nativeio.SharedFileDescriptorFactory)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 ExtendedBlockId (org.apache.hadoop.hdfs.ExtendedBlockId)1 Slot (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.Slot)1