The following unit test is adapted from TestSQLRepositoryAPI#testImportDuplicateIdNewSession) is failing on MongoDB (ok VCS h2 or postgres).
It shows that the rollback is removing an existing document after a concurrent update exception:
@Test public void testImportDuplicateIdNewSession() { DocumentModel doc = session.createDocumentModel("/", "doc", "File"); doc = session.createDocument(doc); session.save(); nextTransaction(); reopenSession(); String docId = doc.getId(); String rootId = session.getRootDocument().getId(); // try to import another doc with the same id // this is prevented by a unique index on the id field in the database DocumentModel doc2 = new DocumentModelImpl(null, "File", docId, new Path("/doc2"), null, null, new IdRef(rootId), null, null, null, null); session.importDocuments(Collections.singletonList(doc2)); try { session.save(); fail(); } catch (ConcurrentUpdateException e) { System.out.println("GOT concurrent exception"); String message = e.getMessage(); assertTrue(message, message.startsWith("Failed to save session")); assertTrue(message, message.endsWith("Concurrent update")); // let's rollback TransactionHelper.setTransactionRollbackOnly(); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); } // the document should be there (on MongoDB this is failing with DocumentNotFoundException) DocumentModel theDoc = session.getDocument(new IdRef(docId)); // and it should be the first one assertEquals(doc.getName(), theDoc.getName()); }
Output on h2 (works the same on PostgreSQL):
mvn -nsu test -Dtest=TestSQLRepositoryAPI#testImportDuplicateIdNewSession ... GOT concurrent exception [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
Output on Mongo
mvn -nsu test -Dtest=TestSQLRepositoryAPI#testImportDuplicateIdNewSession -Dnuxeo.test.core=mongodb ... GOT concurrent exception [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.624 s <<< FAILURE! - in org.nuxeo.ecm.core.TestSQLRepositoryAPI [ERROR] testImportDuplicateIdNewSession(org.nuxeo.ecm.core.TestSQLRepositoryAPI) Time elapsed: 0.122 s <<< ERROR! org.nuxeo.ecm.core.api.DocumentNotFoundException: 101de00d-cc54-41ae-8e23-27ed4527d6a4 at org.nuxeo.ecm.core.storage.dbs.DBSSession.getDocumentByUUID(DBSSession.java:413) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.nuxeo.ecm.core.storage.dbs.DBSRepositoryBase$DBSSessionInvoker.invoke(DBSRepositoryBase.java:542) at com.sun.proxy.$Proxy50.getDocumentByUUID(Unknown Source) at org.nuxeo.ecm.core.api.AbstractSession.resolveReference(AbstractSession.java:337) at org.nuxeo.ecm.core.api.AbstractSession.getDocument(AbstractSession.java:959) at org.nuxeo.ecm.core.TestSQLRepositoryAPI.testImportDuplicateIdNewSession(TestSQLRepositoryAPI.java:3897)