use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class LRUListTest method testRemoveLRUShouldReturnNullIfAllRecordsAreUsed.
@Test
public void testRemoveLRUShouldReturnNullIfAllRecordsAreUsed() {
final OByteBufferPool bufferPool = new OByteBufferPool(1);
ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointerOne = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
OCacheEntry cacheEntry = new OCacheEntry(1, 10, cachePointerOne, false);
lruList.putToMRU(cacheEntry);
cacheEntry.incrementUsages();
OCacheEntry removedLRU = lruList.removeLRU();
Assert.assertNull(removedLRU);
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class LRUListTest method testAddTwo.
@Test
public void testAddTwo() {
final OByteBufferPool bufferPool = new OByteBufferPool(1);
ByteBuffer bufferOne = bufferPool.acquireDirect(true);
ByteBuffer bufferTwo = bufferPool.acquireDirect(true);
OCachePointer cachePointerOne = new OCachePointer(bufferOne, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
OCachePointer cachePointerTwo = new OCachePointer(bufferTwo, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
lruList.putToMRU(new OCacheEntry(1, 10, cachePointerOne, false));
lruList.putToMRU(new OCacheEntry(1, 20, cachePointerTwo, false));
Assert.assertEquals(lruList.size(), 2);
Iterator<OCacheEntry> entryIterator = lruList.iterator();
Assert.assertTrue(entryIterator.hasNext());
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 20, cachePointerTwo, false));
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 10, cachePointerOne, false));
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class LRUListTest method testAdd9128PutLastAndMiddleToTop.
@Test
public void testAdd9128PutLastAndMiddleToTop() {
final OByteBufferPool bufferPool = new OByteBufferPool(1);
OCachePointer[] cachePointers = new OCachePointer[9128];
for (int i = 0; i < 9128; i++) {
ByteBuffer buffer = bufferPool.acquireDirect(true);
cachePointers[i] = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
lruList.putToMRU(new OCacheEntry(1, i * 10, cachePointers[i], false));
}
lruList.putToMRU(new OCacheEntry(1, 0, cachePointers[0], false));
lruList.putToMRU(new OCacheEntry(1, 4500 * 10, cachePointers[4500], false));
Assert.assertEquals(lruList.size(), 9128);
Iterator<OCacheEntry> entryIterator = lruList.iterator();
Assert.assertTrue(entryIterator.hasNext());
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 4500 * 10, cachePointers[4500], false));
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 0, cachePointers[0], false));
for (int i = 9127; i >= 1; i--) {
if (i == 4500)
continue;
Assert.assertTrue(entryIterator.hasNext());
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, i * 10, cachePointers[i], false));
}
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class LRUListTest method testAddElevenRemoveLRU.
@Test
public void testAddElevenRemoveLRU() {
final OByteBufferPool bufferPool = new OByteBufferPool(1);
OCachePointer[] cachePointers = new OCachePointer[11];
for (int i = 0; i < 11; i++) {
ByteBuffer buffer = bufferPool.acquireDirect(true);
cachePointers[i] = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
lruList.putToMRU(new OCacheEntry(1, i * 10, cachePointers[i], false));
}
lruList.removeLRU();
Assert.assertEquals(lruList.size(), 10);
Iterator<OCacheEntry> entryIterator = lruList.iterator();
for (int i = 10; i > 0; i--) {
Assert.assertTrue(entryIterator.hasNext());
Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, i * 10, cachePointers[i], false));
}
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ONullBucketTest method testAddGetValue.
public void testAddGetValue() throws IOException {
OByteBufferPool bufferPool = new OByteBufferPool(1024);
ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
cachePointer.incrementReferrer();
OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
cacheEntry.acquireExclusiveLock();
ONullBucket<String> bucket = new ONullBucket<String>(cacheEntry, null, OStringSerializer.INSTANCE, true);
bucket.setValue(new OSBTreeValue<String>(false, -1, "test"));
OSBTreeValue<String> treeValue = bucket.getValue();
Assert.assertEquals(treeValue.getValue(), "test");
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
Aggregations