use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class BaseTests method aFewEntriesWithCheck.
@Test
public void aFewEntriesWithCheck() {
OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(10 * 1024 * 1024);
logger.info("total capacity=" + Ram.inMb(mem.capacity()));
assertNotNull(mem);
int howMany = 10;
logger.info("payload size is variable");
logger.info("entries=" + howMany);
String test = "this is a nicely crafted test";
Pointer lastP = null;
for (int i = 0; i < howMany; i++) {
byte[] payload = (test + " - " + i).getBytes();
Pointer p = mem.store(payload);
logger.info("p.start=" + p.start);
logger.info("p.end=" + p.end);
if (lastP != null) {
assertEquals(lastP.end + 1, p.start);
}
assertEquals(p.end - p.start, payload.length);
lastP = p;
logger.info("---");
}
logger.info("total used=" + Ram.inMb(mem.used()));
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class BaseTests method aFewEntriesWithRead.
@Test
public void aFewEntriesWithRead() {
OffHeapMemoryBuffer mem = OffHeapMemoryBuffer.createNew(100 * 1024 * 1024);
logger.info("total capacity=" + Ram.inMb(mem.capacity()));
assertNotNull(mem);
int howMany = 10000;
logger.info("payload size is variable");
logger.info("entries=" + howMany);
String test = "this is a nicely crafted test";
for (int i = 0; i < howMany; i++) {
final byte[] payload = (test + " - " + i).getBytes();
Pointer p = mem.store(payload);
final byte[] check = mem.retrieve(p);
assertNotNull(check);
assertEquals(test + " - " + i, new String(check));
long crc1 = OffHeapMemoryBuffer.crc32(payload);
long crc2 = OffHeapMemoryBuffer.crc32(check);
assertEquals(crc1, crc2);
}
logger.info("total used=" + Ram.inMb(mem.used()));
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class ConcurrentTests method get.
private void get(String key) {
Pointer p = map.get(key);
read.incrementAndGet();
if (p != null) {
got.incrementAndGet();
byte[] payload = mem.retrieve(p);
if (key.equals(new String(payload)))
good.incrementAndGet();
else
bad.incrementAndGet();
} else {
missed.incrementAndGet();
}
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class ConcurrentTests method retrieveCatchHalfOfThem.
@BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds = 0, concurrency = 100)
@Test
public void retrieveCatchHalfOfThem() {
String key = "test-" + (rndGen.nextInt(entries * 2) + 1);
Pointer p = map.get(key);
read.incrementAndGet();
if (p != null) {
got.incrementAndGet();
byte[] payload = mem.retrieve(p);
if (key.equals(new String(payload)))
good.incrementAndGet();
else
bad.incrementAndGet();
} else {
missed.incrementAndGet();
}
}
use of org.directmemory.memory.Pointer in project DirectMemory by raffaeleguidi.
the class ConcurrentTests2 method retrieveCatchHalfOfThem.
@BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds = 0, concurrency = 100)
@Test
public void retrieveCatchHalfOfThem() {
String key = "test-" + (rndGen.nextInt(entries * 2) + 1);
Pointer p = map.get(key);
read.incrementAndGet();
if (p != null) {
got.incrementAndGet();
byte[] payload = MemoryManager.retrieve(p);
if (key.equals(new String(payload)))
good.incrementAndGet();
else
bad.incrementAndGet();
} else {
missed.incrementAndGet();
}
}
Aggregations