use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagAtomicUpdateTest method testAddTwoAdditionalNewDocuments.
public void testAddTwoAdditionalNewDocuments() {
database.begin();
ODocument rootDoc = new ODocument();
ORidBag ridBag = new ORidBag();
rootDoc.field("ridBag", ridBag);
ODocument docOne = new ODocument();
ODocument docTwo = new ODocument();
ridBag.add(docOne);
ridBag.add(docTwo);
rootDoc.save();
database.commit();
long recordsCount = database.countClusterElements(database.getDefaultClusterId());
rootDoc = database.load(rootDoc.getIdentity());
ridBag = rootDoc.field("ridBag");
database.begin();
ODocument docThree = new ODocument();
ODocument docFour = new ODocument();
ridBag.add(docThree);
ridBag.add(docFour);
rootDoc.save();
database.rollback();
Assert.assertEquals(database.countClusterElements(database.getDefaultClusterId()), recordsCount);
rootDoc = database.load(rootDoc.getIdentity());
ridBag = rootDoc.field("ridBag");
Assert.assertEquals(ridBag.size(), 2);
Iterator<OIdentifiable> iterator = ridBag.iterator();
List<OIdentifiable> addedDocs = new ArrayList<OIdentifiable>(Arrays.asList(docOne, docTwo));
Assert.assertTrue(addedDocs.remove(iterator.next()));
Assert.assertTrue(addedDocs.remove(iterator.next()));
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagAtomicUpdateTest method testFromEmbeddedToSBTreeRollback.
public void testFromEmbeddedToSBTreeRollback() {
OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(5);
OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(5);
List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>();
ODocument document = new ODocument();
ORidBag ridBag = new ORidBag();
document.field("ridBag", ridBag);
document.save();
database.begin();
for (int i = 0; i < 3; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
ridBag.add(docToAdd);
docsToAdd.add(docToAdd);
}
document.save();
database.commit();
Assert.assertEquals(docsToAdd.size(), 3);
Assert.assertTrue(ridBag.isEmbedded());
document = database.load(document.getIdentity());
ridBag = document.field("ridBag");
database.begin();
for (int i = 0; i < 3; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
ridBag.add(docToAdd);
}
Assert.assertTrue(document.isDirty());
document.save();
database.rollback();
document = database.load(document.getIdentity());
ridBag = document.field("ridBag");
Assert.assertTrue(ridBag.isEmbedded());
for (OIdentifiable identifiable : ridBag) Assert.assertTrue(docsToAdd.remove(identifiable));
Assert.assertTrue(docsToAdd.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagAtomicUpdateTest method testFromSBTreeToEmbeddedWithCME.
/**
* This test is no longer useful
*/
@Test(enabled = false)
public void testFromSBTreeToEmbeddedWithCME() {
OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(5);
OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(7);
List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>();
ODocument document = new ODocument();
ORidBag ridBag = new ORidBag();
document.field("ridBag", ridBag);
document.save();
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
ridBag.add(docToAdd);
docsToAdd.add(docToAdd);
}
document.save();
Assert.assertEquals(docsToAdd.size(), 10);
Assert.assertTrue(!ridBag.isEmbedded());
document = database.load(document.getIdentity());
ridBag = document.field("ridBag");
ODocument cmeDoc = database.load(document.getIdentity());
cmeDoc.field("v", "v1");
cmeDoc.save();
for (int i = 0; i < 4; i++) {
OIdentifiable docToRemove = docsToAdd.get(i);
ridBag.remove(docToRemove);
}
Assert.assertTrue(document.isDirty());
try {
document.save();
Assert.fail();
} catch (OConcurrentModificationException e) {
}
document = database.load(document.getIdentity());
ridBag = document.field("ridBag");
Assert.assertTrue(!ridBag.isEmbedded());
for (OIdentifiable identifiable : ridBag) Assert.assertTrue(docsToAdd.remove(identifiable));
Assert.assertTrue(docsToAdd.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagAtomicUpdateTest method testFromSBTreeToEmbeddedRollback.
public void testFromSBTreeToEmbeddedRollback() {
OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(5);
OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(7);
List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>();
ODocument document = new ODocument();
ORidBag ridBag = new ORidBag();
document.field("ridBag", ridBag);
document.save();
database.begin();
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
ridBag.add(docToAdd);
docsToAdd.add(docToAdd);
}
document.save();
database.commit();
Assert.assertEquals(docsToAdd.size(), 10);
Assert.assertTrue(!ridBag.isEmbedded());
document = database.load(document.getIdentity());
ridBag = document.field("ridBag");
database.begin();
for (int i = 0; i < 4; i++) {
OIdentifiable docToRemove = docsToAdd.get(i);
ridBag.remove(docToRemove);
}
Assert.assertTrue(document.isDirty());
document.save();
database.rollback();
document = database.load(document.getIdentity());
ridBag = document.field("ridBag");
Assert.assertTrue(!ridBag.isEmbedded());
for (OIdentifiable identifiable : ridBag) Assert.assertTrue(docsToAdd.remove(identifiable));
Assert.assertTrue(docsToAdd.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagAtomicUpdateTest method assertDocsAfterRollback.
private void assertDocsAfterRollback(int level, int levels, Map<LevelKey, List<OIdentifiable>> addedDocPerLevel, ODocument rootDoc) {
ORidBag ridBag = rootDoc.field("ridBag");
List<OIdentifiable> addedDocs = new ArrayList<OIdentifiable>(addedDocPerLevel.get(new LevelKey(rootDoc.getIdentity(), level)));
Iterator<OIdentifiable> iterator = ridBag.iterator();
while (iterator.hasNext()) {
ODocument doc = iterator.next().getRecord();
if (level + 1 < levels)
assertDocsAfterRollback(level + 1, levels, addedDocPerLevel, doc);
else
Assert.assertNull(doc.field("ridBag"));
Assert.assertTrue(addedDocs.remove(doc));
}
Assert.assertTrue(addedDocs.isEmpty());
}
Aggregations