use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class OSBTreeBonsaiLeafBucketTest method testInitialization.
public void testInitialization() 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();
OSBTreeBonsaiBucket<Long, OIdentifiable> treeBucket = new OSBTreeBonsaiBucket<Long, OIdentifiable>(cacheEntry, 0, true, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null, null);
Assert.assertEquals(treeBucket.size(), 0);
Assert.assertTrue(treeBucket.isLeaf());
treeBucket = new OSBTreeBonsaiBucket<Long, OIdentifiable>(cacheEntry, 0, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null, null);
Assert.assertEquals(treeBucket.size(), 0);
Assert.assertTrue(treeBucket.isLeaf());
Assert.assertFalse(treeBucket.getLeftSibling().isValid());
Assert.assertFalse(treeBucket.getRightSibling().isValid());
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class OSBTreeBonsaiNonLeafBucketTest method testInitialization.
public void testInitialization() 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();
OSBTreeBonsaiBucket<Long, OIdentifiable> treeBucket = new OSBTreeBonsaiBucket<Long, OIdentifiable>(cacheEntry, 0, false, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null, null);
Assert.assertEquals(treeBucket.size(), 0);
Assert.assertFalse(treeBucket.isLeaf());
treeBucket = new OSBTreeBonsaiBucket<Long, OIdentifiable>(cacheEntry, 0, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null, null);
Assert.assertEquals(treeBucket.size(), 0);
Assert.assertFalse(treeBucket.isLeaf());
Assert.assertEquals(treeBucket.getLeftSibling().getPageIndex(), -1);
Assert.assertEquals(treeBucket.getRightSibling().getPageIndex(), -1);
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class WOWCacheTest method testNoChecksumFailureIfNoChecksumProvided.
@Test
public void testNoChecksumFailureIfNoChecksumProvided() throws IOException {
wowCache.setChecksumMode(OChecksumMode.Off);
final long fileId = wowCache.addFile(fileName);
OCachePointer cachePointer = wowCache.load(fileId, 0, 1, true, new OModifiableBoolean(), true)[0];
cachePointer.acquireExclusiveLock();
final ByteBuffer buffer = cachePointer.getSharedBuffer();
buffer.position(systemOffset);
buffer.put(new byte[buffer.remaining()]);
cachePointer.releaseExclusiveLock();
wowCache.store(fileId, 0, cachePointer);
cachePointer.decrementReadersReferrer();
wowCache.flush();
final String path = storageLocal.getConfiguration().getDirectory() + File.separator + fileName;
final OFileClassic file = new OFileClassic(path, "rw");
file.open();
file.writeByte(systemOffset, (byte) 1);
file.close();
wowCache.setChecksumMode(OChecksumMode.StoreAndThrow);
cachePointer = wowCache.load(fileId, 0, 1, true, new OModifiableBoolean(), true)[0];
cachePointer.decrementReadersReferrer();
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class WOWCacheTest method testLoadStore.
public void testLoadStore() throws IOException {
Random random = new Random();
byte[][] pageData = new byte[200][];
long fileId = wowCache.addFile(fileName);
for (int i = 0; i < pageData.length; i++) {
byte[] data = new byte[8];
random.nextBytes(data);
pageData[i] = data;
final OCachePointer cachePointer = wowCache.load(fileId, i, 1, true, new OModifiableBoolean(), true)[0];
cachePointer.acquireExclusiveLock();
ByteBuffer buffer = cachePointer.getSharedBuffer();
buffer.position(systemOffset);
buffer.put(data);
cachePointer.releaseExclusiveLock();
wowCache.store(fileId, i, cachePointer);
cachePointer.decrementReadersReferrer();
}
for (int i = 0; i < pageData.length; i++) {
byte[] dataOne = pageData[i];
OCachePointer cachePointer = wowCache.load(fileId, i, 1, false, new OModifiableBoolean(), true)[0];
byte[] dataTwo = new byte[8];
ByteBuffer buffer = cachePointer.getSharedBuffer();
buffer.position(systemOffset);
buffer.get(dataTwo);
cachePointer.decrementReadersReferrer();
Assert.assertEquals(dataTwo, dataOne);
}
wowCache.flush();
for (int i = 0; i < pageData.length; i++) {
byte[] dataContent = pageData[i];
assertFile(i, dataContent, new OLogSequenceNumber(0, 0));
}
}
use of com.orientechnologies.orient.core.storage.cache.OCachePointer in project orientdb by orientechnologies.
the class WOWCacheTest method testChecksumFailure.
@Test
public void testChecksumFailure() throws IOException {
wowCache.setChecksumMode(OChecksumMode.StoreAndThrow);
final long fileId = wowCache.addFile(fileName);
final OCachePointer cachePointer = wowCache.load(fileId, 0, 1, true, new OModifiableBoolean(), true)[0];
cachePointer.acquireExclusiveLock();
final ByteBuffer buffer = cachePointer.getSharedBuffer();
buffer.position(systemOffset);
buffer.put(new byte[buffer.remaining()]);
cachePointer.releaseExclusiveLock();
wowCache.store(fileId, 0, cachePointer);
cachePointer.decrementReadersReferrer();
wowCache.flush();
final String path = storageLocal.getConfiguration().getDirectory() + File.separator + fileName;
final OFileClassic file = new OFileClassic(path, "rw");
file.open();
file.writeByte(systemOffset, (byte) 1);
file.close();
Assert.assertThrows(OStorageException.class, new Assert.ThrowingRunnable() {
@Override
public void run() throws Throwable {
wowCache.load(fileId, 0, 1, true, new OModifiableBoolean(), true);
}
});
}
Aggregations