summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-01-25 21:56:43 (EST)
committerCaspar De Groot2011-01-25 21:56:43 (EST)
commitc70c6cae2a21d73d58777ea84561578e1379c0a3 (patch)
tree2a8bade777235f146178601936366c270d4e9db9
parentd97921be219dc278f8efa47b5e02787cbe7b534f (diff)
downloadcdo-c70c6cae2a21d73d58777ea84561578e1379c0a3.zip
cdo-c70c6cae2a21d73d58777ea84561578e1379c0a3.tar.gz
cdo-c70c6cae2a21d73d58777ea84561578e1379c0a3.tar.bz2
[334608] CommitIntegrityCheck erroneously checks non-persistent features
https://bugs.eclipse.org/bugs/show_bug.cgi?id=334608
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java110
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334608_Test.java115
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java12
3 files changed, 131 insertions, 106 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
index 9e5bdb7..3c78e08 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
@@ -10,104 +10,7 @@
*/
package org.eclipse.emf.cdo.tests;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_241464_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_243310_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_246442_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_246622_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_248052_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_248124_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_248915_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_250036_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_250757_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_250910_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_251087_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_251263_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_251544_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_251752_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_252214_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_252909_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_254489_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_255662_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_256141_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_258278_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_258850_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_258933_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_259695_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_259949_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_260756_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_260764_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_261218_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_265114_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_266857_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_266982_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_267050_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_267352_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_270429_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_272861_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_273233_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_273565_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_273758_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_276696_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_278900_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_279565_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_279982_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_280102_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_283985_CDOTest;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_283985_CDOTest2;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_283985_SavePointTest;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_285008_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_289932_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_293283_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_294859_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_296561_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_298561_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_299190_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_302233_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_302414_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303466_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_303807_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_305527_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_306710_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_306998_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_308895_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_310574_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_314186_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_314264_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_315043_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_316145_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_316273_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_316434_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_316444_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_318518_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_318844_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_318876_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_318919_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_318998_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_319836_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_320690_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_320837_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_321699_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_322754_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_322804_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_323930_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_323958_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_324084_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_324585_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_324635_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_324756_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_325603_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_325866_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_326518_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_326743_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_328790_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_329752_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_329753_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_329869_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_330052_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_331619_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_333157_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_333299_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_333950_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.*;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTestSuite;
@@ -186,6 +89,9 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(BackupTest.class);
// Bugzilla verifications
+ // testClasses.add(Bugzilla_259869_Test.class); // This is no real test, but relies on timing and fails often
+ // testClasses.add(Bugzilla_313326_Test.class);
+ // testClasses.add(Bugzilla_316887_Test.class); // The test logic is buggy
testClasses.add(Bugzilla_241464_Test.class);
testClasses.add(Bugzilla_243310_Test.class);
testClasses.add(Bugzilla_246442_Test.class);
@@ -209,7 +115,6 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_258850_Test.class);
testClasses.add(Bugzilla_258933_Test.class);
testClasses.add(Bugzilla_259695_Test.class);
- // testClasses.add(Bugzilla_259869_Test.class); // This is no real test, but relies on timing and fails often
testClasses.add(Bugzilla_259949_Test.class);
testClasses.add(Bugzilla_260756_Test.class);
testClasses.add(Bugzilla_260764_Test.class);
@@ -248,12 +153,11 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_306998_Test.class);
testClasses.add(Bugzilla_308895_Test.class);
testClasses.add(Bugzilla_310574_Test.class);
- // testClasses.add(Bugzilla_313326_Test.class);
testClasses.add(Bugzilla_314186_Test.class);
testClasses.add(Bugzilla_314264_Test.class);
+ testClasses.add(Bugzilla_315043_Test.class);
testClasses.add(Bugzilla_316145_Test.class);
testClasses.add(Bugzilla_316273_Test.class);
- // testClasses.add(Bugzilla_316887_Test.class); // The test logic is buggy
testClasses.add(Bugzilla_316434_Test.class);
testClasses.add(Bugzilla_316444_Test.class);
testClasses.add(Bugzilla_318518_Test.class);
@@ -278,15 +182,15 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_326518_Test.class);
testClasses.add(Bugzilla_326743_Test.class);
testClasses.add(Bugzilla_328790_Test.class);
- testClasses.add(Bugzilla_330052_Test.class);
testClasses.add(Bugzilla_329752_Test.class);
testClasses.add(Bugzilla_329753_Test.class);
testClasses.add(Bugzilla_329869_Test.class);
+ testClasses.add(Bugzilla_330052_Test.class);
testClasses.add(Bugzilla_331619_Test.class);
testClasses.add(Bugzilla_333157_Test.class);
testClasses.add(Bugzilla_333299_Test.class);
- testClasses.add(Bugzilla_315043_Test.class);
testClasses.add(Bugzilla_333950_Test.class);
+ testClasses.add(Bugzilla_334608_Test.class);
// TODO testClasses.add(NonCDOResourceTest.class);
// TODO testClasses.add(GeneratedEcoreTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334608_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334608_Test.java
new file mode 100644
index 0000000..3ddb7b1
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_334608_Test.java
@@ -0,0 +1,115 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Egidijus Vaishnora - initial API and implementation
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl;
+import org.eclipse.emf.internal.cdo.util.CommitIntegrityCheck;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext;
+
+import junit.framework.Assert;
+
+/**
+ * Bug 334608 - CommitIntegrityCheck erroneously checks non-persistent features
+ *
+ * @author Egidijus Vaishnora, Caspar De Groot
+ */
+public class Bugzilla_334608_Test extends AbstractCDOTest
+{
+ public void testOpposites() throws Exception
+ {
+ EPackage pkg1 = null;
+ {
+ pkg1 = EcoreFactory.eINSTANCE.createEPackage();
+ pkg1.setNsURI("http://test.com/custom");
+ pkg1.setName("test");
+ pkg1.setNsPrefix("t");
+
+ EClass customClassA = EcoreFactory.eINSTANCE.createEClass();
+ customClassA.setName("A");
+ pkg1.getEClassifiers().add(customClassA);
+
+ EClass customClassB = EcoreFactory.eINSTANCE.createEClass();
+ customClassB.setName("B");
+ pkg1.getEClassifiers().add(customClassB);
+
+ createOpposites(customClassA, customClassB);
+ }
+
+ {
+ // create model and commit it
+ CDOSession openSession = openSession();
+ CDOTransaction transaction = openSession.openTransaction();
+ CDOResource resource = transaction.createResource("test");
+
+ EClass classAClass = (EClass)pkg1.getEClassifier("A");
+ EClass classBClass = (EClass)pkg1.getEClassifier("B");
+
+ EObject instanceA = EcoreUtil.create(classAClass);
+ EObject instanceB = EcoreUtil.create(classBClass);
+ EStructuralFeature eStructuralFeatureA = classAClass.getEStructuralFeature("AB");
+ EStructuralFeature eStructuralFeatureB = instanceB.eClass().getEStructuralFeature("_AB");
+
+ instanceA.eSet(eStructuralFeatureA, instanceB);
+
+ resource.getContents().add(instanceA);
+ resource.getContents().add(instanceB);
+
+ Assert.assertTrue(eStructuralFeatureB.isTransient());
+ Assert.assertTrue(eStructuralFeatureA.isTransient());
+ Assert.assertEquals(instanceA, instanceB.eGet(eStructuralFeatureB));
+ transaction.commit();
+
+ resource.getContents().remove(instanceA);
+ resource.getContents().remove(instanceB);
+
+ InternalCDOCommitContext commitContext = ((CDOTransactionImpl)transaction).createCommitContext();
+ CommitIntegrityCheck integrityCheck = new CommitIntegrityCheck(commitContext,
+ CommitIntegrityCheck.Style.NO_EXCEPTION);
+ integrityCheck.check();
+
+ transaction.commit();
+ openSession.close();
+ }
+ }
+
+ private void createOpposites(EClass A, EClass B)
+ {
+ EReference tmpRefA_B = EcoreFactory.eINSTANCE.createEReference();
+ tmpRefA_B.setTransient(true);
+ tmpRefA_B.setName(A.getName() + B.getName());
+ A.getEStructuralFeatures().add(tmpRefA_B);
+ tmpRefA_B.setEType(B);
+
+ EReference tmpRefB_A = EcoreFactory.eINSTANCE.createEReference();
+ tmpRefB_A.setTransient(true);
+ tmpRefB_A.setName("_" + tmpRefA_B.getName());
+ B.getEStructuralFeatures().add(tmpRefB_A);
+ tmpRefB_A.setEType(A);
+
+ tmpRefA_B.setEOpposite(tmpRefB_A);
+ tmpRefB_A.setEOpposite(tmpRefA_B);
+ Assert.assertSame(tmpRefA_B, tmpRefB_A.getEOpposite());
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java
index 81b486f..d2733c6 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.internal.cdo.util;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.model.EMFUtil;
import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOClearFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOContainerFeatureDelta;
@@ -161,7 +162,7 @@ public class CommitIntegrityCheck
else if (feat instanceof EReference)
{
EReference ref = (EReference)feat;
- if (ref.isContainment() || ref.getEOpposite() != null)
+ if (ref.isContainment() || hasPersistentOpposite(ref))
{
// Object is dirty with respect to a containment feature or a feature with an eOpposite
// We must ensure that any reference targets that were added/removed/set, are also
@@ -314,7 +315,7 @@ public class CommitIntegrityCheck
{
for (EReference eRef : referencer.eClass().getEAllReferences())
{
- if (eRef.getEOpposite() != null)
+ if (hasPersistentOpposite(eRef))
{
if (eRef.isMany())
{
@@ -347,7 +348,7 @@ public class CommitIntegrityCheck
for (EReference eRef : referencer.eClass().getEAllReferences())
{
- if (eRef.getEOpposite() != null)
+ if (hasPersistentOpposite(eRef))
{
Object value = cleanRev.get(eRef, EStore.NO_INDEX);
if (value != null)
@@ -400,6 +401,11 @@ public class CommitIntegrityCheck
checkIncluded(id, "former container (or resource) of detached", detachedObject);
}
+ private static boolean hasPersistentOpposite(EReference ref)
+ {
+ return ref.getEOpposite() != null && EMFUtil.isPersistent(ref);
+ }
+
/**
* Designates an exception style for a {@link CommitIntegrityCheck}
*