Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Porhel2018-01-30 06:10:05 -0500
committerEike Stepper2018-01-30 10:05:03 -0500
commit4e1a55a49b6cdf31dcf7213c8add89f189ba3773 (patch)
tree38299acd5e3bf7dc2086212c5f5cd1e524d21d20 /plugins/org.eclipse.emf.cdo.tests/src
parente916a1a9febe2fccd366eb7f9a24cdfbb9f394cc (diff)
downloadcdo-4e1a55a49b6cdf31dcf7213c8add89f189ba3773.tar.gz
cdo-4e1a55a49b6cdf31dcf7213c8add89f189ba3773.tar.xz
cdo-4e1a55a49b6cdf31dcf7213c8add89f189ba3773.zip
[530498] Handle reattached elements in RewriteTransition
When the CDOUndoDetector detects an undo dirty elements are removed from dirty object, their state is set from DIRTY to CLEAN but they also need to be removed from reattached/detached objects, otherwise this could later lead to IllegalStateException if CDOTransaction.rollback is called (their is no more revision in CDOTransactionImpl.cleanRevisions for an element known in detachedObjects). https://bugs.eclipse.org/bugs/show_bug.cgi?id=530498 Change-Id: Ib77ac7e72bec165ecac9faf05590385e1d77ec06 Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr> Signed-off-by: Eike Stepper <stepper@esc-net.de>
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_530498_Test.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_530498_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_530498_Test.java
new file mode 100644
index 0000000000..8b0e22e1cd
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_530498_Test.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2018 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:
+ * Maxime Porhel (Obeo) - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+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.Company;
+import org.eclipse.emf.cdo.tests.model1.Customer;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+/**
+ * Bug 530498: Null revision after transaction rollback on transaction with re-attached objects.
+ *
+ * @author Maxime Porhel
+ */
+public class Bugzilla_530498_Test extends AbstractCDOTest
+{
+ public void testNoNullRevisionAfterTransactionRollback() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ // Initialize model.
+ Company company1 = getModel1Factory().createCompany();
+ Company company2 = getModel1Factory().createCompany();
+ Customer customer = getModel1Factory().createCustomer();
+
+ CDOResource resource = transaction.createResource(getResourcePath("res"));
+ resource.getContents().add(company1);
+ resource.getContents().add(company2);
+ company1.getCustomers().add(customer);
+
+ transaction.commit();
+
+ CDOID company1ID = CDOUtil.getCDOObject(company1).cdoID();
+ CDOID company2ID = CDOUtil.getCDOObject(company2).cdoID();
+ CDOID customerID = CDOUtil.getCDOObject(customer).cdoID();
+
+ // Simulate a Drag and Drop of Customer to another Company: in 2 steps, the drag command is a RemoveCommand
+ // and then the drop command is an AddCommand.
+ // Step 1: Simulate the first step of the DnD: the drag, a RemoveCommand equivalent.
+ company1.getCustomers().remove(customer);
+
+ assertFalse(transaction.getDirtyObjects().containsKey(customerID));
+ assertTrue(transaction.getDirtyObjects().containsKey(company1ID));
+ assertFalse(transaction.getDirtyObjects().containsKey(company2ID));
+
+ assertTrue(transaction.getDetachedObjects().containsKey(customerID));
+ assertTrue(transaction.getLastSavepoint().getAllDetachedObjects().containsKey(customerID));
+ assertTrue(transaction.getLastSavepoint().getDetachedObjects().containsKey(customerID));
+ assertFalse(transaction.getLastSavepoint().getReattachedObjects().containsKey(customerID));
+
+ // Simulate the second step of the DnD : the drop, an AddCommand equivalent.
+ company2.getCustomers().add(customer);
+
+ assertTrue(transaction.getDirtyObjects().containsKey(customerID));
+ assertTrue(transaction.getDirtyObjects().containsKey(company1ID));
+ assertTrue(transaction.getDirtyObjects().containsKey(company2ID));
+
+ assertFalse(transaction.getDetachedObjects().containsKey(customerID));
+ assertFalse(transaction.getLastSavepoint().getAllDetachedObjects().containsKey(customerID));
+ assertTrue(transaction.getLastSavepoint().getDetachedObjects().containsKey(customerID));
+ assertTrue(transaction.getLastSavepoint().getReattachedObjects().containsKey(customerID));
+
+ // Simulate DnD undo (or rollback of a EMF Transaction command doing the dnd: the ChangeDescription will be applied but
+ // the concrete resulting command will result in a simple add (thanks to the EMF containment management, the
+ // cancellation of the "Remove" step will do nothing).
+ company1.getCustomers().add(customer);
+
+ assertFalse(transaction.getDirtyObjects().containsKey(customerID));
+ assertFalse(transaction.getDirtyObjects().containsKey(company1ID));
+ assertFalse(transaction.getDirtyObjects().containsKey(company2ID));
+
+ assertFalse(transaction.getDetachedObjects().containsKey(customerID));
+ assertFalse(transaction.getLastSavepoint().getAllDetachedObjects().containsKey(customerID));
+ assertFalse(transaction.getLastSavepoint().getDetachedObjects().containsKey(customerID));
+ assertFalse(transaction.getLastSavepoint().getReattachedObjects().containsKey(customerID));
+
+ // Rollback the transaction
+ transaction.rollback();
+
+ assertNotNull("Transaction has been rollbakced, the revision of the car element must not be null", CDOUtil.getCDOObject(customer).cdoRevision());
+ }
+}

Back to the top