summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-02-10 01:52:20 (EST)
committerCaspar De Groot2011-02-10 01:52:20 (EST)
commit13b8d0ffd88f5de06a4c64b0de1452fea1230557 (patch)
tree5ad92aa0a961380ae7cb20ace67cca7fb31bf0c6
parente267ed281336345d485115cd95703d5766abf6b6 (diff)
downloadcdo-13b8d0ffd88f5de06a4c64b0de1452fea1230557.zip
cdo-13b8d0ffd88f5de06a4c64b0de1452fea1230557.tar.gz
cdo-13b8d0ffd88f5de06a4c64b0de1452fea1230557.tar.bz2
[Bug 336590] CDOConflictResolver2 receives spurious delta in case of remote removal + local add
https://bugs.eclipse.org/bugs/show_bug.cgi?id=336590
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_336590_Test.java149
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java18
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java7
4 files changed, 174 insertions, 1 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 a5c9596..0dc37fd 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
@@ -198,6 +198,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_335675_Test.class);
testClasses.add(Bugzilla_335004_Test.class);
testClasses.add(Bugzilla_336314_Test.class);
+ testClasses.add(Bugzilla_336590_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_336590_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_336590_Test.java
new file mode 100644
index 0000000..71a30dc
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_336590_Test.java
@@ -0,0 +1,149 @@
+/**
+ * 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:
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
+import org.eclipse.emf.cdo.common.revision.delta.CDOListFeatureDelta;
+import org.eclipse.emf.cdo.common.revision.delta.CDORemoveFeatureDelta;
+import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
+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.tests.model1.Model1Factory;
+import org.eclipse.emf.cdo.tests.model1.OrderDetail;
+import org.eclipse.emf.cdo.tests.model1.SalesOrder;
+import org.eclipse.emf.cdo.transaction.CDOConflictResolver2;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CommitException;
+
+import org.eclipse.net4j.util.collection.Pair;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Caspar De Groot
+ */
+public class Bugzilla_336590_Test extends AbstractCDOTest
+{
+ private CDOID removedID;
+
+ public void test() throws CommitException
+ {
+ CDOSession session = openSession();
+ session.options().setPassiveUpdateEnabled(false);
+
+ CDOTransaction tx = session.openTransaction();
+ tx.options().addConflictResolver(new TestResolver());
+
+ CDOResource resource = tx.createResource("test");
+ Model1Factory f = getModel1Factory();
+ SalesOrder order = f.createSalesOrder();
+ for (int i = 0; i < 3; i++)
+ {
+ order.getOrderDetails().add(f.createOrderDetail());
+ }
+
+ resource.getContents().add(order);
+ tx.commit();
+
+ for (int i = 0; i < 3; i++)
+ {
+ order.getOrderDetails().add(f.createOrderDetail());
+ }
+
+ OrderDetail newDetail = f.createOrderDetail();
+ order.getOrderDetails().add(newDetail);
+ System.out.println("---> New object: " + newDetail);
+
+ doRemovalInOtherSession();
+ session.refresh();
+
+ session.close();
+ }
+
+ private void doRemovalInOtherSession() throws CommitException
+ {
+ CDOSession session = openSession();
+ CDOTransaction tx = session.openTransaction();
+ CDOResource resource = tx.getResource("test");
+
+ SalesOrder order = (SalesOrder)resource.getContents().get(0);
+ OrderDetail removedDetail = order.getOrderDetails().get(0);
+ removedID = CDOUtil.getCDOObject(removedDetail).cdoID();
+ order.getOrderDetails().remove(0);
+
+ tx.commit();
+ session.close();
+ }
+
+ /**
+ * @author Caspar De Groot
+ */
+ private class TestResolver implements CDOConflictResolver2
+ {
+ private CDOTransaction tx;
+
+ public CDOTransaction getTransaction()
+ {
+ return tx;
+ }
+
+ public void setTransaction(CDOTransaction transaction)
+ {
+ tx = transaction;
+ }
+
+ public void resolveConflicts(Set<CDOObject> conflicts)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void resolveConflicts(Map<CDOObject, Pair<CDORevision, CDORevisionDelta>> conflicts,
+ List<CDORevisionDelta> allRemoteDeltas)
+ {
+ assertEquals(1, allRemoteDeltas.size());
+
+ List<CDOFeatureDelta> fDeltas = allRemoteDeltas.get(0).getFeatureDeltas();
+ assertEquals(1, fDeltas.size());
+
+ CDOFeatureDelta fDelta = fDeltas.get(0);
+ assertEquals(true, fDelta instanceof CDOListFeatureDelta);
+
+ List<CDOFeatureDelta> listDeltas = ((CDOListFeatureDelta)fDelta).getListChanges();
+ for (CDOFeatureDelta lDelta : listDeltas)
+ {
+ System.out.println("---> listDelta: " + lDelta);
+ }
+
+ // Should find only 1 delta
+ assertEquals(1, listDeltas.size());
+
+ // And it should be a remove delta
+ CDOFeatureDelta lDelta = listDeltas.get(0);
+ assertEquals(true, lDelta instanceof CDORemoveFeatureDelta);
+
+ // And its value should be a CDOID
+ CDORemoveFeatureDelta removeDelta = (CDORemoveFeatureDelta)lDelta;
+ Object removedValue = removeDelta.getValue();
+ assertEquals(true, removedValue instanceof CDOID);
+
+ // And that CDOID should match the CDOID we kept when removing the
+ // object in the 2nd session
+ assertEquals(removedID.toString(), removedValue.toString());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
index f403539..0e265fc 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
@@ -2150,6 +2150,24 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
return cleanRevisions;
}
+ @Override
+ protected InternalCDORevision getViewedRevision(InternalCDOObject object)
+ {
+ InternalCDORevision rev = super.getViewedRevision(object);
+
+ // Bug 336590: If we have a clean revision for this object, return that instead
+ if (rev != null)
+ {
+ InternalCDORevision cleanRev = cleanRevisions.get(object);
+ if (cleanRev != null)
+ {
+ return cleanRev;
+ }
+ }
+
+ return rev;
+ }
+
/**
* @author Simon McDuff
*/
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
index d5a2c96..2c2cb76 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
@@ -1276,7 +1276,7 @@ public abstract class AbstractCDOView extends Lifecycle implements InternalCDOVi
continue;
}
- InternalCDORevision revision = CDOStateMachine.INSTANCE.readNoLoad(object);
+ InternalCDORevision revision = getViewedRevision(object);
if (revision == null)
{
continue;
@@ -1286,6 +1286,11 @@ public abstract class AbstractCDOView extends Lifecycle implements InternalCDOVi
}
}
+ protected InternalCDORevision getViewedRevision(InternalCDOObject object)
+ {
+ return CDOStateMachine.INSTANCE.readNoLoad(object);
+ }
+
public synchronized CDOChangeSetData compareRevisions(CDOBranchPoint source)
{
CDOSession session = getSession();