Search in sources :

Example 11 with OIndexRIDContainer

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer in project orientdb by orientechnologies.

the class OStreamSerializerSBTreeIndexRIDContainerTest method testSerializeWALChangesEmbeddedNonDurable.

public void testSerializeWALChangesEmbeddedNonDurable() {
    final OIndexRIDContainer indexRIDContainer = new OIndexRIDContainer("test", false);
    indexRIDContainer.setTopThreshold(100);
    for (int i = 0; i < 5; i++) {
        indexRIDContainer.add(new ORecordId(1, i));
    }
    Assert.assertTrue(indexRIDContainer.isEmbedded());
    final int len = streamSerializerSBTreeIndexRIDContainer.getObjectSize(indexRIDContainer);
    final int serializationOffset = 5;
    final ByteBuffer buffer = ByteBuffer.allocateDirect(len + serializationOffset).order(ByteOrder.nativeOrder());
    final byte[] data = new byte[len];
    streamSerializerSBTreeIndexRIDContainer.serializeNativeObject(indexRIDContainer, data, 0);
    final OWALChanges walChanges = new OWALChangesTree();
    walChanges.setBinaryValue(buffer, data, serializationOffset);
    Assert.assertEquals(streamSerializerSBTreeIndexRIDContainer.getObjectSizeInByteBuffer(buffer, walChanges, serializationOffset), len);
    OIndexRIDContainer newRidContainer = streamSerializerSBTreeIndexRIDContainer.deserializeFromByteBufferObject(buffer, walChanges, serializationOffset);
    Assert.assertNotSame(newRidContainer, indexRIDContainer);
    Assert.assertTrue(newRidContainer.isEmbedded());
    Assert.assertFalse(newRidContainer.isDurableNonTxMode());
    final Set<OIdentifiable> storedRids = new HashSet<OIdentifiable>(newRidContainer);
    final Set<OIdentifiable> newRids = new HashSet<OIdentifiable>(indexRIDContainer);
    Assert.assertEquals(newRids, storedRids);
}
Also used : OWALChangesTree(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree) OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) OWALChanges(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges) ByteBuffer(java.nio.ByteBuffer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) HashSet(java.util.HashSet)

Example 12 with OIndexRIDContainer

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer in project orientdb by orientechnologies.

the class OStreamSerializerSBTreeIndexRIDContainerTest method testSerializeWALChangesNonEmbeddedDurable.

public void testSerializeWALChangesNonEmbeddedDurable() {
    final OIndexRIDContainer indexRIDContainer = new OIndexRIDContainer("test", true);
    indexRIDContainer.setTopThreshold(1);
    for (int i = 0; i < 5; i++) {
        indexRIDContainer.add(new ORecordId(1, i * 4));
    }
    Assert.assertFalse(indexRIDContainer.isEmbedded());
    final int len = streamSerializerSBTreeIndexRIDContainer.getObjectSize(indexRIDContainer);
    final int serializationOffset = 5;
    final ByteBuffer buffer = ByteBuffer.allocateDirect(len + serializationOffset).order(ByteOrder.nativeOrder());
    final byte[] data = new byte[len];
    streamSerializerSBTreeIndexRIDContainer.serializeNativeObject(indexRIDContainer, data, 0);
    final OWALChanges walChanges = new OWALChangesTree();
    walChanges.setBinaryValue(buffer, data, serializationOffset);
    Assert.assertEquals(streamSerializerSBTreeIndexRIDContainer.getObjectSizeInByteBuffer(buffer, walChanges, serializationOffset), len);
    OIndexRIDContainer newRidContainer = streamSerializerSBTreeIndexRIDContainer.deserializeFromByteBufferObject(buffer, walChanges, serializationOffset);
    Assert.assertNotSame(newRidContainer, indexRIDContainer);
    Assert.assertFalse(newRidContainer.isEmbedded());
    Assert.assertTrue(newRidContainer.isDurableNonTxMode());
    final Set<OIdentifiable> storedRids = new HashSet<OIdentifiable>(newRidContainer);
    final Set<OIdentifiable> newRids = new HashSet<OIdentifiable>(indexRIDContainer);
    Assert.assertEquals(newRids, storedRids);
}
Also used : OWALChangesTree(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree) OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) OWALChanges(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges) ByteBuffer(java.nio.ByteBuffer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) HashSet(java.util.HashSet)

Example 13 with OIndexRIDContainer

use of com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer in project orientdb by orientechnologies.

the class OStreamSerializerSBTreeIndexRIDContainerTest method testSerializeWALChangesNonEmbeddedNonDurable.

public void testSerializeWALChangesNonEmbeddedNonDurable() {
    final OIndexRIDContainer indexRIDContainer = new OIndexRIDContainer("test", false);
    indexRIDContainer.setTopThreshold(1);
    for (int i = 0; i < 5; i++) {
        indexRIDContainer.add(new ORecordId(1, i * 3));
    }
    Assert.assertFalse(indexRIDContainer.isEmbedded());
    final int len = streamSerializerSBTreeIndexRIDContainer.getObjectSize(indexRIDContainer);
    final int serializationOffset = 5;
    final ByteBuffer buffer = ByteBuffer.allocateDirect(len + serializationOffset).order(ByteOrder.nativeOrder());
    final byte[] data = new byte[len];
    streamSerializerSBTreeIndexRIDContainer.serializeNativeObject(indexRIDContainer, data, 0);
    final OWALChanges walChanges = new OWALChangesTree();
    walChanges.setBinaryValue(buffer, data, serializationOffset);
    Assert.assertEquals(streamSerializerSBTreeIndexRIDContainer.getObjectSizeInByteBuffer(buffer, walChanges, serializationOffset), len);
    OIndexRIDContainer newRidContainer = streamSerializerSBTreeIndexRIDContainer.deserializeFromByteBufferObject(buffer, walChanges, serializationOffset);
    Assert.assertNotSame(newRidContainer, indexRIDContainer);
    Assert.assertFalse(newRidContainer.isEmbedded());
    Assert.assertFalse(newRidContainer.isDurableNonTxMode());
    final Set<OIdentifiable> storedRids = new HashSet<OIdentifiable>(newRidContainer);
    final Set<OIdentifiable> newRids = new HashSet<OIdentifiable>(indexRIDContainer);
    Assert.assertEquals(newRids, storedRids);
}
Also used : OWALChangesTree(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree) OIndexRIDContainer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer) OWALChanges(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges) ByteBuffer(java.nio.ByteBuffer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) HashSet(java.util.HashSet)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)13 OIndexRIDContainer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer)13 HashSet (java.util.HashSet)12 ORecordId (com.orientechnologies.orient.core.id.ORecordId)8 ByteBuffer (java.nio.ByteBuffer)8 OWALChanges (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChanges)4 OWALChangesTree (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree)4 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)3 OIndexRIDContainerSBTree (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainerSBTree)3 OBonsaiBucketPointer (com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer)3 ODatabase (com.orientechnologies.orient.core.db.ODatabase)2 OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)2 ORID (com.orientechnologies.orient.core.id.ORID)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1