use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class TransactionConsistencyTest method test4RollbackWithPin.
@Test
public void test4RollbackWithPin() throws IOException {
database1 = new ODatabaseDocumentTx(url).open("admin", "admin");
// Create docA.
ODocument vDocA_db1 = database1.newInstance();
vDocA_db1.field(NAME, "docA");
database1.save(vDocA_db1);
// Keep the IDs.
ORID vDocA_Rid = vDocA_db1.getIdentity().copy();
database2 = new ODatabaseDocumentTx(url).open("admin", "admin");
database2.begin(TXTYPE.OPTIMISTIC);
try {
// Get docA and update in db2 transaction context
ODocument vDocA_db2 = database2.load(vDocA_Rid);
vDocA_db2.field(NAME, "docA_v2");
database2.save(vDocA_db2);
database1.activateOnCurrentThread();
database1.begin(TXTYPE.OPTIMISTIC);
try {
vDocA_db1.field(NAME, "docA_v3");
database1.save(vDocA_db1);
database1.commit();
} catch (OConcurrentModificationException e) {
Assert.fail("Should not failed here...");
}
Assert.assertEquals(vDocA_db1.field(NAME), "docA_v3");
// Will throw OConcurrentModificationException
database2.activateOnCurrentThread();
database2.commit();
Assert.fail("Should throw OConcurrentModificationException");
} catch (OConcurrentModificationException e) {
database2.rollback();
}
// Force reload all (to be sure it is not a cache problem)
database1.activateOnCurrentThread();
database1.close();
database2.activateOnCurrentThread();
database2.close();
database2 = new ODatabaseDocumentTx(url).open("admin", "admin");
// docB should be in the last state : "docA_v3"
ODocument vDocB_db2 = database2.load(vDocA_Rid);
Assert.assertEquals(vDocB_db2.field(NAME), "docA_v3");
database1.activateOnCurrentThread();
database1.close();
database2.activateOnCurrentThread();
database2.close();
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class TransactionOptimisticTest method testNestedTxRollbackOne.
public void testNestedTxRollbackOne() throws Exception {
final ExecutorService executorService = Executors.newSingleThreadExecutor();
final Callable<Void> assertEmptyRecord = new Callable<Void>() {
@Override
public Void call() throws Exception {
final ODatabaseDocumentTx db = new ODatabaseDocumentTx(database.getURL());
db.open("admin", "admin");
try {
Assert.assertEquals(db.countClass("NestedTxRollbackOne"), 1);
} finally {
db.close();
}
return null;
}
};
final OSchema schema = database.getMetadata().getSchema();
if (!schema.existsClass("NestedTxRollbackOne"))
schema.createClass("NestedTxRollbackOne");
ODocument brokenDocOne = new ODocument("NestedTxRollbackOne");
brokenDocOne.save();
brokenDocOne = database.load(brokenDocOne.getIdentity(), "*:-1", true);
ODocument brokenDocTwo = database.load(brokenDocOne.getIdentity(), "*:-1", true);
brokenDocTwo.setDirty();
brokenDocTwo.field("v", "vstr");
brokenDocTwo.save();
try {
database.begin();
final ODocument externalDocOne = new ODocument("NestedTxRollbackOne");
externalDocOne.field("v", "val1");
externalDocOne.save();
Future assertFuture = executorService.submit(assertEmptyRecord);
assertFuture.get();
database.begin();
ODocument externalDocTwo = new ODocument("NestedTxRollbackOne");
externalDocTwo.field("v", "val2");
externalDocTwo.save();
assertFuture = executorService.submit(assertEmptyRecord);
assertFuture.get();
brokenDocOne.setDirty();
brokenDocOne.save();
database.commit();
assertFuture = executorService.submit(assertEmptyRecord);
assertFuture.get();
final ODocument externalDocThree = new ODocument("NestedTxRollbackOne");
externalDocThree.field("v", "val3");
externalDocThree.save();
database.commit();
Assert.fail();
} catch (OConcurrentModificationException e) {
database.rollback();
}
Assert.assertTrue(!database.getTransaction().isActive());
Assert.assertEquals(database.countClass("NestedTxRollbackOne"), 1);
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class ORidBagAtomicUpdateTest method testAddOneSavedDocumentsAndDeleteOneWithoutTx.
/**
* This test is no longer useful
*/
@Test(enabled = false)
public void testAddOneSavedDocumentsAndDeleteOneWithoutTx() {
ODocument docOne = new ODocument();
docOne.save();
ODocument docTwo = new ODocument();
docTwo.save();
ODocument docThree = new ODocument();
docThree.save();
ODocument rootDoc = new ODocument();
ORidBag ridBag = new ORidBag();
rootDoc.field("ridBag", ridBag);
ridBag.add(docOne);
ridBag.add(docTwo);
rootDoc.save();
ODocument staleRooDoc = database.load(rootDoc.getIdentity());
ORidBag staleRidBag = staleRooDoc.field("ridBag");
Iterator<OIdentifiable> iterator = staleRidBag.iterator();
iterator.next();
iterator.remove();
staleRidBag.add(docThree);
rootDoc.setDirty();
rootDoc.save();
try {
staleRooDoc.save();
Assert.fail();
} catch (OConcurrentModificationException e) {
}
rootDoc = database.load(rootDoc.getIdentity());
ridBag = rootDoc.field("ridBag");
Assert.assertEquals(ridBag.size(), 2);
iterator = ridBag.iterator();
Assert.assertEquals(iterator.next(), docOne);
Assert.assertEquals(iterator.next(), docTwo);
Assert.assertTrue(!iterator.hasNext());
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException 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.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class ORidBagAtomicUpdateTest method testAddTwoNewDocumentsWithCME.
public void testAddTwoNewDocumentsWithCME() {
final ODocument cmeDoc = new ODocument();
cmeDoc.save();
database.begin();
ODocument rootDoc = new ODocument();
ORidBag ridBag = new ORidBag();
rootDoc.field("ridBag", ridBag);
rootDoc.save();
database.commit();
database.getLocalCache().clear();
ODocument staleCMEDoc = database.load(cmeDoc.getIdentity());
Assert.assertNotSame(staleCMEDoc, cmeDoc);
cmeDoc.field("v", "v");
cmeDoc.save();
database.begin();
ODocument docOne = new ODocument();
ODocument docTwo = new ODocument();
ridBag.add(docOne);
ridBag.add(docTwo);
staleCMEDoc.field("v", "v1");
staleCMEDoc.save();
try {
database.commit();
Assert.fail();
} catch (OConcurrentModificationException e) {
}
rootDoc = database.load(rootDoc.getIdentity());
ridBag = rootDoc.field("ridBag");
Assert.assertEquals(ridBag.size(), 0);
}
Aggregations