use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ONullBucketTest method testEmptyBucket.
public void testEmptyBucket() {
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);
Assert.assertNull(bucket.getValue());
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class WALChangesTreeTest method testAddOverlappedVersionsDM.
public void testAddOverlappedVersionsDM() {
final OWALChangesTree tree = new OWALChangesTree();
tree.setDebug(true);
tree.add(new byte[] { 35, 30 }, 11);
tree.add(new byte[] { 10, 20 }, 10);
OByteBufferPool bufferPool = new OByteBufferPool(20);
ByteBuffer buffer = bufferPool.acquireDirect(true);
tree.applyChanges(buffer);
Assert.assertEquals(getByteArray(buffer, 10, 3), new byte[] { 10, 20, 30 });
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class WALChangesTreeTest method testInsertCase4and5DM.
public void testInsertCase4and5DM() {
final OWALChangesTree tree = new OWALChangesTree();
tree.setDebug(true);
tree.add(new byte[] { 50 }, 50);
tree.add(new byte[] { 60 }, 60);
tree.add(new byte[] { 40 }, 40);
tree.add(new byte[] { 30 }, 30);
tree.add(new byte[] { 35 }, 35);
OByteBufferPool bufferPool = new OByteBufferPool(80);
ByteBuffer buffer = bufferPool.acquireDirect(true);
tree.applyChanges(buffer);
Assert.assertEquals(getByteArray(buffer, 50, 1), new byte[] { 50 });
Assert.assertEquals(getByteArray(buffer, 60, 1), new byte[] { 60 });
Assert.assertEquals(getByteArray(buffer, 40, 1), new byte[] { 40 });
Assert.assertEquals(getByteArray(buffer, 30, 1), new byte[] { 30 });
Assert.assertEquals(getByteArray(buffer, 35, 1), new byte[] { 35 });
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ReadWriteDiskCacheTest method testFrequentlyAddItemsAreMovedInAm.
public void testFrequentlyAddItemsAreMovedInAm() throws Exception {
long fileId = readBuffer.addFile(fileName, writeBuffer);
OCacheEntry[] entries = new OCacheEntry[10];
for (int i = 0; i < 10; i++) {
entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
if (entries[i] == null) {
entries[i] = readBuffer.allocateNewPage(fileId, writeBuffer, true);
Assert.assertEquals(entries[i].getPageIndex(), i);
}
entries[i].getCachePointer().acquireExclusiveLock();
entries[i].markDirty();
final ByteBuffer buffer = entries[i].getCachePointer().getSharedBuffer();
buffer.position(systemOffset);
buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i });
setLsn(buffer, new OLogSequenceNumber(1, i));
entries[i].getCachePointer().releaseExclusiveLock();
readBuffer.release(entries[i], writeBuffer);
}
LRUList am = readBuffer.getAm();
LRUList a1in = readBuffer.getA1in();
LRUList a1out = readBuffer.getA1out();
Assert.assertEquals(a1in.size(), 4);
Assert.assertEquals(a1out.size(), 2);
Assert.assertEquals(am.size(), 0);
OByteBufferPool bufferPool = OByteBufferPool.instance();
for (int i = 6; i < 10; i++) {
OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(0, 0));
Assert.assertEquals(a1in.get(fileId, i), lruEntry);
}
for (int i = 4; i < 6; i++) {
OCacheEntry lruEntry = generateRemovedEntry(fileId, i);
Assert.assertEquals(a1out.get(fileId, i), lruEntry);
}
for (int i = 4; i < 6; i++) {
entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
readBuffer.release(entries[i], writeBuffer);
}
Assert.assertEquals(am.size(), 2);
Assert.assertEquals(a1in.size(), 2);
Assert.assertEquals(a1out.size(), 2);
for (int i = 4; i < 6; i++) {
OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(1, i));
Assert.assertEquals(am.get(fileId, i), lruEntry);
}
for (int i = 6; i < 8; i++) {
OCacheEntry lruEntry = generateRemovedEntry(fileId, i);
Assert.assertEquals(a1out.get(fileId, i), lruEntry);
}
for (int i = 8; i < 10; i++) {
OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(0, 0));
Assert.assertEquals(a1in.get(fileId, i), lruEntry);
}
writeBuffer.flush();
for (int i = 0; i < 10; i++) assertFile(i, new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i }, new OLogSequenceNumber(1, i));
}
use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.
the class ClusterPageTest method testDeleteAddBiggerVersion.
public void testDeleteAddBiggerVersion() throws Exception {
OByteBufferPool bufferPool = OByteBufferPool.instance();
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();
ByteBuffer directBuffer = bufferPool.acquireDirect(true);
OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
directCachePointer.incrementReferrer();
OCacheEntry directCacheEntry = new OCacheEntry(0, 0, directCachePointer, false);
directCacheEntry.acquireExclusiveLock();
try {
OClusterPage localPage = new OClusterPage(cacheEntry, true, new OWALChangesTree());
OClusterPage directLocalPage = new OClusterPage(directCacheEntry, true, null);
deleteAddBiggerVersion(localPage);
deleteAddBiggerVersion(directLocalPage);
assertChangesTracking(localPage, directBuffer, bufferPool);
} finally {
cacheEntry.releaseExclusiveLock();
directCacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
directCachePointer.decrementReferrer();
}
}
Aggregations