Search in sources :

Example 1 with OffHeapMemoryBuffer

use of org.directmemory.memory.OffHeapMemoryBuffer in project DirectMemory by raffaeleguidi.

the class MemoryManagerTests method readTest.

@Test
public void readTest() {
    for (OffHeapMemoryBuffer buffer : MemoryManager.buffers) {
        for (Pointer ptr : buffer.pointers) {
            if (!ptr.free) {
                byte[] res = MemoryManager.retrieve(ptr);
                assertNotNull(res);
                assertEquals(new String(payload), new String(res));
            }
        }
    }
}
Also used : OffHeapMemoryBuffer(org.directmemory.memory.OffHeapMemoryBuffer) Pointer(org.directmemory.memory.Pointer) Test(org.junit.Test)

Example 2 with OffHeapMemoryBuffer

use of org.directmemory.memory.OffHeapMemoryBuffer in project DirectMemory by raffaeleguidi.

the class Starter method rawInsert.

public void rawInsert(int megabytes, int howMany) {
    OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(megabytes * 1024 * 1024);
    assertNotNull(mem);
    int size = mem.capacity() / (howMany);
    size -= size / 100 * 1;
    logger.info("payload size=" + size);
    logger.info("entries=" + howMany);
    logger.info("starting...");
    long start = System.currentTimeMillis();
    byte[] payload = new byte[size];
    for (int i = 0; i < howMany; i++) {
        mem.store(payload);
    }
    logger.info("...done in " + (System.currentTimeMillis() - start) + " msecs.");
    logger.info("---------------------------------");
    dump(mem);
}
Also used : OffHeapMemoryBuffer(org.directmemory.memory.OffHeapMemoryBuffer)

Example 3 with OffHeapMemoryBuffer

use of org.directmemory.memory.OffHeapMemoryBuffer in project DirectMemory by raffaeleguidi.

the class Starter method rawInsertMultipleBuffers.

public void rawInsertMultipleBuffers(int buffers, int megabytes, int howMany) {
    MemoryManager.init(buffers, Ram.Mb(megabytes));
    int size = (int) (MemoryManager.capacity() / (howMany));
    size -= size / 100 * 1;
    logger.info("payload size=" + size);
    logger.info("entries=" + howMany);
    logger.info("starting...");
    long start = System.currentTimeMillis();
    byte[] payload = new byte[size];
    for (int i = 0; i < howMany; i++) {
        MemoryManager.store(payload);
    }
    logger.info("...done in " + (System.currentTimeMillis() - start) + " msecs.");
    logger.info("---------------------------------");
    for (OffHeapMemoryBuffer buf : MemoryManager.buffers) {
        dump(buf);
    }
}
Also used : OffHeapMemoryBuffer(org.directmemory.memory.OffHeapMemoryBuffer)

Example 4 with OffHeapMemoryBuffer

use of org.directmemory.memory.OffHeapMemoryBuffer in project DirectMemory by raffaeleguidi.

the class ConcurrentTests3 method dump.

@AfterClass
public static void dump() {
    for (OffHeapMemoryBuffer mem : MemoryManager.buffers) {
        dump(mem);
    }
    logger.info("************************************************");
    logger.info("entries: " + entries);
    logger.info("inserted: " + map.size());
    logger.info("reads: " + read);
    logger.info("count: " + count);
    logger.info("got: " + got);
    logger.info("missed: " + missed);
    logger.info("good: " + good);
    logger.info("bad: " + bad);
    logger.info("disposals: " + disposals);
    logger.info("************************************************");
}
Also used : OffHeapMemoryBuffer(org.directmemory.memory.OffHeapMemoryBuffer) AfterClass(org.junit.AfterClass)

Example 5 with OffHeapMemoryBuffer

use of org.directmemory.memory.OffHeapMemoryBuffer in project DirectMemory by raffaeleguidi.

the class BaseTests method smokeTest.

@Test
public void smokeTest() {
    OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(1 * 1024 * 1024);
    logger.info("buffer size=" + mem.capacity());
    assertNotNull(mem);
    Random rnd = new Random();
    int size = rnd.nextInt(10) * mem.capacity() / 100;
    logger.info("size=" + size);
    Pointer p = mem.store(new byte[size]);
    assertNotNull(p);
    assertEquals(size, p.end);
    assertEquals(size, mem.used());
    mem.free(p);
    assertEquals(0, mem.used());
}
Also used : Random(java.util.Random) OffHeapMemoryBuffer(org.directmemory.memory.OffHeapMemoryBuffer) Pointer(org.directmemory.memory.Pointer) Test(org.junit.Test)

Aggregations

OffHeapMemoryBuffer (org.directmemory.memory.OffHeapMemoryBuffer)9 Test (org.junit.Test)5 Pointer (org.directmemory.memory.Pointer)4 AfterClass (org.junit.AfterClass)2 Date (java.util.Date)1 Random (java.util.Random)1