Search in sources :

Example 11 with Pointer

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

the class ConcurrentTests3 method get.

private void get(String key) {
    Pointer p = map.get(key);
    read.incrementAndGet();
    if (p != null) {
        got.incrementAndGet();
        byte[] payload = MemoryManager.retrieve(p);
        if ((new String(payload)).startsWith(key))
            good.incrementAndGet();
        else
            bad.incrementAndGet();
    } else {
        missed.incrementAndGet();
    }
}
Also used : Pointer(org.directmemory.memory.Pointer)

Example 12 with Pointer

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

the class MemoryManagerTests method fillupTest.

@Test
public void fillupTest() {
    MemoryManager.clear();
    logger.info("payload size=" + Ram.inKb(payload.length));
    long howMany = (MemoryManager.capacity() / payload.length);
    howMany = (howMany * 90) / 100;
    for (int i = 0; i < howMany; i++) {
        Pointer p = MemoryManager.store(payload);
        assertNotNull(p);
    }
    logger.info("" + howMany + " items stored");
}
Also used : Pointer(org.directmemory.memory.Pointer) Test(org.junit.Test)

Example 13 with Pointer

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

the class Cache method put.

public static Pointer put(String key, Object object, int expiresIn) {
    try {
        byte[] payload = serializer.serialize(object, object.getClass());
        Pointer ptr = putByteArray(key, payload);
        ptr.clazz = object.getClass();
        return ptr;
    } catch (IOException e) {
        logger.error(e.getMessage());
        return null;
    }
}
Also used : Pointer(org.directmemory.memory.Pointer) IOException(java.io.IOException)

Example 14 with Pointer

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

the class Cache method update.

public static Pointer update(String key, Object object) {
    Pointer p = map.get(key);
    try {
        p = MemoryManager.update(p, serializer.serialize(object, object.getClass()));
        p.clazz = object.getClass();
        return p;
    } catch (IOException e) {
        logger.error(e.getMessage());
        return null;
    }
}
Also used : Pointer(org.directmemory.memory.Pointer) IOException(java.io.IOException)

Example 15 with Pointer

use of org.directmemory.memory.Pointer 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

Pointer (org.directmemory.memory.Pointer)21 Test (org.junit.Test)12 BenchmarkOptions (com.carrotsearch.junitbenchmarks.BenchmarkOptions)4 OffHeapMemoryBuffer (org.directmemory.memory.OffHeapMemoryBuffer)4 IOException (java.io.IOException)2 Random (java.util.Random)2 MapMaker (com.google.common.collect.MapMaker)1