use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagAtomicUpdateTest method testFromEmbeddedToSBTreeWithCME.
public void testFromEmbeddedToSBTreeWithCME() {
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();
for (int i = 0; i < 3; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
ridBag.add(docToAdd);
docsToAdd.add(docToAdd);
}
document.save();
Assert.assertEquals(docsToAdd.size(), 3);
Assert.assertTrue(ridBag.isEmbedded());
document = database.load(document.getIdentity());
ridBag = document.field("ridBag");
database.getLocalCache().clear();
ODocument cmeDocument = database.load(document.getIdentity());
Assert.assertNotSame(cmeDocument, document);
cmeDocument.field("v", "v1");
cmeDocument.save();
for (int i = 0; i < 3; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
ridBag.add(docToAdd);
}
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 testAddTwoAdditionalSavedDocumentsWithCME.
public void testAddTwoAdditionalSavedDocumentsWithCME() {
final ODocument cmeDoc = new ODocument();
cmeDoc.save();
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.getLocalCache().clear();
ODocument staleCMEDoc = database.load(cmeDoc.getIdentity());
Assert.assertNotSame(staleCMEDoc, cmeDoc);
cmeDoc.field("v", "v");
cmeDoc.save();
database.begin();
ODocument docThree = new ODocument();
docThree.save();
ODocument docFour = new ODocument();
docFour.save();
ridBag.add(docThree);
ridBag.add(docFour);
rootDoc.save();
staleCMEDoc.field("v", "vn");
staleCMEDoc.save();
try {
database.commit();
Assert.fail();
} catch (OConcurrentModificationException e) {
}
Assert.assertEquals(database.countClusterElements(database.getDefaultClusterId()), recordsCount);
rootDoc = database.load(rootDoc.getIdentity());
ridBag = rootDoc.field("ridBag");
Assert.assertEquals(ridBag.size(), 2);
List<OIdentifiable> addedDocs = new ArrayList<OIdentifiable>(Arrays.asList(docOne, docTwo));
Iterator<OIdentifiable> iterator = ridBag.iterator();
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 ODirtyManagerTest method testLinkSetNoConvert.
@Test
public void testLinkSetNoConvert() {
ODocument doc = new ODocument();
doc.field("test", "ddd");
Set<OIdentifiable> set = new ORecordLazySet(doc);
ODocument link = new ODocument();
set.add(link);
doc.field("set", set, OType.LINKSET);
ODirtyManager manager = ORecordInternal.getDirtyManager(doc);
assertEquals(2, manager.getNewRecords().size());
assertEquals(1, manager.getPointed(doc).size());
assertTrue(manager.getPointed(doc).contains(link));
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ODirtyManagerTest method testLinkSetNoConvertRemove.
@Test(enabled = false)
public void testLinkSetNoConvertRemove() {
ODocument doc = new ODocument();
doc.field("test", "ddd");
Set<OIdentifiable> set = new ORecordLazySet(doc);
ODocument link = new ODocument();
set.add(link);
doc.field("set", set, OType.LINKSET);
doc.removeField("set");
ODirtyManager manager = ORecordInternal.getDirtyManager(doc);
assertEquals(2, manager.getNewRecords().size());
assertEquals(0, manager.getPointed(doc).size());
assertTrue(manager.getPointed(doc).contains(link));
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ODirtyManagerTest method testLinkMapLoop.
@Test
public void testLinkMapLoop() {
ODocument doc1 = new ODocument().field("name", "doc1");
ODocument doc2 = new ODocument().field("name", "doc2");
ODocument doc3 = new ODocument().field("name", "doc3");
Map<String, OIdentifiable> map1 = new HashMap<String, OIdentifiable>();
map1.put("a", doc2);
map1.put("b", doc3);
doc1.field("other", map1);
Map<String, OIdentifiable> map2 = new HashMap<String, OIdentifiable>();
map2.put("a", doc1);
map2.put("b", doc3);
doc2.field("other", map2);
Map<String, OIdentifiable> map3 = new HashMap<String, OIdentifiable>();
map3.put("a", doc1);
map3.put("b", doc2);
doc3.field("other", map3);
ODocumentInternal.convertAllMultiValuesToTrackedVersions(doc1);
ODirtyManager manager = ORecordInternal.getDirtyManager(doc1);
assertEquals(3, manager.getNewRecords().size());
assertTrue(manager.getPointed(doc1).contains(doc2));
assertTrue(manager.getPointed(doc1).contains(doc3));
assertTrue(manager.getPointed(doc2).contains(doc1));
assertTrue(manager.getPointed(doc2).contains(doc3));
assertTrue(manager.getPointed(doc3).contains(doc1));
assertTrue(manager.getPointed(doc3).contains(doc2));
}
Aggregations