Search in sources :

Example 41 with OCachePointer

use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.

the class LRUListTest method testAddElevenGetMiddle.

@Test
public void testAddElevenGetMiddle() {
    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));
    }
    Assert.assertTrue(lruList.contains(1, 50));
    Assert.assertEquals(lruList.get(1, 50), new OCacheEntry(1, 50, cachePointers[5], false));
    Assert.assertFalse(lruList.contains(2, 50));
    Assert.assertEquals(lruList.size(), 11);
    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));
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 42 with OCachePointer

use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.

the class LRUListTest method testAddElevenPutMiddleToTopChangePointer.

@Test
public void testAddElevenPutMiddleToTopChangePointer() {
    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.putToMRU(new OCacheEntry(1, 50, cachePointers[5], false));
    Assert.assertEquals(lruList.size(), 11);
    Iterator<OCacheEntry> entryIterator = lruList.iterator();
    Assert.assertTrue(entryIterator.hasNext());
    Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 50, cachePointers[5], false));
    for (int i = 10; i >= 0; i--) {
        if (i == 5)
            continue;
        Assert.assertTrue(entryIterator.hasNext());
        Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, i * 10, cachePointers[i], false));
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 43 with OCachePointer

use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.

the class LRUListTest method testAdd9128Remove4564.

@Test
public void testAdd9128Remove4564() {
    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));
    }
    for (int i = 4564; i < 9128; i++) Assert.assertEquals(lruList.remove(1, i * 10), new OCacheEntry(1, i * 10, cachePointers[i], false));
    Assert.assertEquals(lruList.size(), 4564);
    Iterator<OCacheEntry> entryIterator = lruList.iterator();
    for (int i = 4563; i >= 0; i--) {
        Assert.assertTrue(entryIterator.hasNext());
        Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, i * 10, cachePointers[i], false));
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 44 with OCachePointer

use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.

the class LRUListTest method testAddThreePutMiddleToTop.

@Test
public void testAddThreePutMiddleToTop() {
    final OByteBufferPool bufferPool = new OByteBufferPool(1);
    ByteBuffer bufferOne = bufferPool.acquireDirect(true);
    ByteBuffer bufferTwo = bufferPool.acquireDirect(true);
    ByteBuffer bufferThree = 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);
    OCachePointer cachePointerThree = new OCachePointer(bufferThree, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
    lruList.putToMRU(new OCacheEntry(1, 10, cachePointerOne, false));
    lruList.putToMRU(new OCacheEntry(1, 20, cachePointerTwo, false));
    lruList.putToMRU(new OCacheEntry(3, 30, cachePointerThree, false));
    lruList.putToMRU(new OCacheEntry(1, 20, cachePointerTwo, false));
    Assert.assertEquals(lruList.size(), 3);
    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(3, 30, cachePointerThree, false));
    Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, 10, cachePointerOne, false));
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) Test(org.testng.annotations.Test)

Example 45 with OCachePointer

use of com.orientechnologies.orient.core.storage.cache.OCachePointer 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);
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) Test(org.testng.annotations.Test)

Aggregations

OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)77 ByteBuffer (java.nio.ByteBuffer)73 OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)68 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)65 OByteBufferPool (com.orientechnologies.common.directmemory.OByteBufferPool)61 Test (org.testng.annotations.Test)22 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 OWALChangesTree (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree)19 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)9 OFileClassic (com.orientechnologies.orient.core.storage.fs.OFileClassic)9 Random (java.util.Random)9 ORecordId (com.orientechnologies.orient.core.id.ORecordId)8 WriteAheadLogTest (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.WriteAheadLogTest)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 TreeSet (java.util.TreeSet)8 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)2 Assert (org.testng.Assert)2