Search in sources :

Example 6 with OConcurrentModificationException

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();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORID(com.orientechnologies.orient.core.id.ORID) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 7 with OConcurrentModificationException

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);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ExecutorService(java.util.concurrent.ExecutorService) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Future(java.util.concurrent.Future) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) Callable(java.util.concurrent.Callable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 8 with OConcurrentModificationException

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());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 9 with OConcurrentModificationException

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());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 10 with OConcurrentModificationException

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);
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)40 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)25 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)11 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)11 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)11 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)8 ArrayList (java.util.ArrayList)8 Test (org.testng.annotations.Test)8 Vertex (com.tinkerpop.blueprints.Vertex)7 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)6 Test (org.junit.Test)5 ORID (com.orientechnologies.orient.core.id.ORID)4 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)4 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)4 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)4 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)3 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2