use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagTest method testAddRemove.
public void testAddRemove() {
ORidBag bag = new ORidBag();
bag.setAutoConvertToRecord(false);
bag.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:2"));
bag.add(new ORecordId("#77:3"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:4"));
bag.add(new ORecordId("#77:5"));
bag.add(new ORecordId("#77:6"));
bag.remove(new ORecordId("#77:1"));
bag.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:2"));
bag.remove(new ORecordId("#77:4"));
bag.remove(new ORecordId("#77:6"));
Assert.assertTrue(bag.contains(new ORecordId("#77:3")));
Assert.assertTrue(bag.contains(new ORecordId("#77:4")));
Assert.assertTrue(bag.contains(new ORecordId("#77:5")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:2")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:6")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:1")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:0")));
assertEmbedded(bag.isEmbedded());
final List<OIdentifiable> rids = new ArrayList<OIdentifiable>();
rids.add(new ORecordId("#77:3"));
rids.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:4"));
rids.add(new ORecordId("#77:5"));
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
for (OIdentifiable identifiable : bag) rids.add(identifiable);
ODocument doc = new ODocument();
doc.field("ridbag", bag);
doc.save();
ORID rid = doc.getIdentity();
doc = database.load(rid);
doc.setLazyLoad(false);
bag = doc.field("ridbag");
assertEmbedded(bag.isEmbedded());
Assert.assertTrue(bag.contains(new ORecordId("#77:3")));
Assert.assertTrue(bag.contains(new ORecordId("#77:4")));
Assert.assertTrue(bag.contains(new ORecordId("#77:5")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:2")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:6")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:1")));
Assert.assertTrue(!bag.contains(new ORecordId("#77:0")));
for (OIdentifiable identifiable : bag) assertTrue(rids.remove(identifiable));
assertTrue(rids.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagTest method testSaveLoad.
public void testSaveLoad() throws Exception {
Set<OIdentifiable> expected = new HashSet<OIdentifiable>(8);
expected.add(new ORecordId("#77:12"));
expected.add(new ORecordId("#77:13"));
expected.add(new ORecordId("#77:14"));
expected.add(new ORecordId("#77:15"));
expected.add(new ORecordId("#77:16"));
expected.add(new ORecordId("#77:17"));
expected.add(new ORecordId("#77:18"));
expected.add(new ORecordId("#77:19"));
expected.add(new ORecordId("#77:20"));
expected.add(new ORecordId("#77:21"));
expected.add(new ORecordId("#77:22"));
ODocument doc = new ODocument();
final ORidBag bag = new ORidBag();
bag.addAll(expected);
doc.field("ridbag", bag);
assertEmbedded(bag.isEmbedded());
doc.save();
final ORID id = doc.getIdentity();
OStorage storage = database.getStorage();
database.close();
storage.close(true, false);
database = new ODatabaseDocumentTx(database.getURL());
database.open("admin", "admin");
doc = database.load(id);
doc.setLazyLoad(false);
final ORidBag loaded = doc.field("ridbag");
assertEmbedded(loaded.isEmbedded());
Assert.assertEquals(loaded.size(), expected.size());
for (OIdentifiable identifiable : loaded) Assert.assertTrue(expected.remove(identifiable));
Assert.assertTrue(expected.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagTest method testAddMixedValues.
public void testAddMixedValues() {
ORidBag ridBag = new ORidBag();
ODocument document = new ODocument();
document.field("ridBag", ridBag);
assertEmbedded(ridBag.isEmbedded());
List<OIdentifiable> itemsToAdd = new ArrayList<OIdentifiable>();
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
for (int k = 0; k < 2; k++) {
ridBag.add(docToAdd);
itemsToAdd.add(docToAdd);
}
}
assertEmbedded(ridBag.isEmbedded());
document.save();
document.reload();
ridBag = document.field("ridBag");
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
for (int k = 0; k < 2; k++) {
ridBag.add(docToAdd);
itemsToAdd.add(docToAdd);
}
}
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
ridBag.add(docToAdd);
itemsToAdd.add(docToAdd);
}
assertEmbedded(ridBag.isEmbedded());
document.save();
document.reload();
ridBag = document.field("ridBag");
database.begin();
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
docToAdd.save();
for (int k = 0; k < 2; k++) {
ridBag.add(docToAdd);
itemsToAdd.add(docToAdd);
}
}
for (int i = 0; i < 10; i++) {
ODocument docToAdd = new ODocument();
ridBag.add(docToAdd);
itemsToAdd.add(docToAdd);
}
assertEmbedded(ridBag.isEmbedded());
document.save();
database.commit();
assertEmbedded(ridBag.isEmbedded());
Assert.assertEquals(ridBag.size(), itemsToAdd.size());
document.reload();
Assert.assertEquals(ridBag.size(), itemsToAdd.size());
for (OIdentifiable id : ridBag) Assert.assertTrue(itemsToAdd.remove(id));
Assert.assertTrue(itemsToAdd.isEmpty());
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagTest method massiveInsertionIteration.
private void massiveInsertionIteration(Random rnd, List<OIdentifiable> rids, ORidBag bag) {
Iterator<OIdentifiable> bagIterator = bag.iterator();
while (bagIterator.hasNext()) {
OIdentifiable bagValue = bagIterator.next();
Assert.assertTrue(rids.contains(bagValue));
}
Assert.assertEquals(bag.size(), rids.size());
for (int i = 0; i < 100; i++) {
if (rnd.nextDouble() < 0.2 & rids.size() > 5) {
final int index = rnd.nextInt(rids.size());
final OIdentifiable rid = rids.remove(index);
bag.remove(rid);
} else {
final int positionIndex = rnd.nextInt(300);
final long position = positionIndex;
final ORecordId recordId = new ORecordId(1, position);
rids.add(recordId);
bag.add(recordId);
}
}
bagIterator = bag.iterator();
while (bagIterator.hasNext()) {
final OIdentifiable bagValue = bagIterator.next();
Assert.assertTrue(rids.contains(bagValue));
if (rnd.nextDouble() < 0.05) {
bagIterator.remove();
Assert.assertTrue(rids.remove(bagValue));
}
}
Assert.assertEquals(bag.size(), rids.size());
bagIterator = bag.iterator();
while (bagIterator.hasNext()) {
final OIdentifiable bagValue = bagIterator.next();
Assert.assertTrue(rids.contains(bagValue));
}
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ORidBagTest method testRemove.
public void testRemove() {
final Set<OIdentifiable> expected = new HashSet<OIdentifiable>(8);
expected.add(new ORecordId("#77:12"));
expected.add(new ORecordId("#77:13"));
expected.add(new ORecordId("#77:14"));
expected.add(new ORecordId("#77:15"));
expected.add(new ORecordId("#77:16"));
final ORidBag bag = new ORidBag();
assertEmbedded(bag.isEmbedded());
bag.setAutoConvertToRecord(false);
bag.addAll(expected);
assertEmbedded(bag.isEmbedded());
bag.remove(new ORecordId("#77:23"));
assertEmbedded(bag.isEmbedded());
final Set<OIdentifiable> expectedTwo = new HashSet<OIdentifiable>(8);
expectedTwo.addAll(expected);
for (OIdentifiable identifiable : bag) {
assertTrue(expectedTwo.remove(identifiable));
}
Assert.assertTrue(expectedTwo.isEmpty());
expected.remove(new ORecordId("#77:14"));
bag.remove(new ORecordId("#77:14"));
assertEmbedded(bag.isEmbedded());
expectedTwo.addAll(expected);
for (OIdentifiable identifiable : bag) {
assertTrue(expectedTwo.remove(identifiable));
}
}
Aggregations