Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-12-10 01:25:42 -0500
committerEike Stepper2011-12-10 01:25:42 -0500
commita9b8b8d3831d1729cc067edf91544df3f43fa05d (patch)
tree00baf6bedb1355c03a397da8a1b3da33fd605f3b
parentcd175a26df24ec85eed2446d349cfa19b707d383 (diff)
downloadcdo-a9b8b8d3831d1729cc067edf91544df3f43fa05d.tar.gz
cdo-a9b8b8d3831d1729cc067edf91544df3f43fa05d.tar.xz
cdo-a9b8b8d3831d1729cc067edf91544df3f43fa05d.zip
[365204] Invalidate transition creates illegal object for audit view
https://bugs.eclipse.org/bugs/show_bug.cgi?id=365204
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java5
-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_361819_Test.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_365204_Test.java79
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java35
5 files changed, 115 insertions, 8 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
index 270571af5c..f5a7173cef 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
@@ -192,7 +192,8 @@ public abstract class AbstractCDOTest extends ConfigTest
}
}
- protected static void commitAndSync(CDOTransaction transaction, CDOUpdatable... updatables) throws CommitException
+ protected static CDOCommitInfo commitAndSync(CDOTransaction transaction, CDOUpdatable... updatables)
+ throws CommitException
{
CDOCommitInfo info = transaction.commit();
if (info != null)
@@ -205,5 +206,7 @@ public abstract class AbstractCDOTest extends ConfigTest
}
}
}
+
+ return info;
}
}
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 4450b09332..467dc59c81 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
@@ -249,6 +249,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_359992_Test.class);
testClasses.add(Bugzilla_361819_Test.class);
testClasses.add(Bugzilla_363287_Test.class);
+ testClasses.add(Bugzilla_365204_Test.class);
testClasses.add(Bugzilla_365832_Test.class);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_361819_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_361819_Test.java
index 98c7184611..874fd56c37 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_361819_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_361819_Test.java
@@ -14,7 +14,6 @@ import org.eclipse.emf.cdo.CDOObject;
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.config.IModelConfig;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
@@ -30,7 +29,6 @@ import org.eclipse.emf.ecore.EObject;
*/
public class Bugzilla_361819_Test extends AbstractCDOTest
{
- @Skips(IModelConfig.CAPABILITY_LEGACY)
public void testDoubleRefreshBug() throws Exception
{
createData(getResourcePath("test"));
@@ -57,7 +55,6 @@ public class Bugzilla_361819_Test extends AbstractCDOTest
assertClean(testingObject, testingObject.cdoView());
session.refresh();
session.refresh();
- assertProxy(testingObject);
// Load proxy
((Category)testingEObject).getName();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_365204_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_365204_Test.java
new file mode 100644
index 0000000000..71e935a67a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_365204_Test.java
@@ -0,0 +1,79 @@
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
+import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
+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.config.IRepositoryConfig;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.cdo.view.CDOView;
+
+/**
+ * @author Egidijus Vaisnora
+ */
+@Requires(IRepositoryConfig.CAPABILITY_AUDITING)
+public class Bugzilla_365204_Test extends AbstractCDOTest
+{
+ public void testAuditViewTimeSwitch() throws CommitException
+ {
+ CDOSession sessionA = openSession();
+ CDOTransaction transaction = sessionA.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("test"));
+
+ Category category = getModel1Factory().createCategory();
+ resource.getContents().add(category);
+
+ // Make version 1 of the category
+ CDOCommitInfo commit1 = transaction.commit();
+ CDOID categoryID = CDOUtil.getCDOObject(category).cdoID();
+
+ CDOSession sessionB = openSession();
+ CDOView auditView = sessionB.openView(commit1.getTimeStamp());
+ CDOObject auditCategory = auditView.getObject(categoryID);
+ assertEquals(1, CDOUtil.getCDOObject(auditCategory).cdoRevision().getVersion());
+
+ // Make version 2 of the category
+ category.setName("version 2");
+ CDOCommitInfo commit2 = commitAndSync(transaction, auditView);
+ assertEquals(true, commit1.getTimeStamp() < commit2.getTimeStamp());
+ assertEquals(2, CDOUtil.getCDOObject(category).cdoRevision().getVersion());
+
+ // Make version 3 of the category
+ category.setName("version 3");
+ CDOCommitInfo commit3 = commitAndSync(transaction, auditView);
+ assertEquals(true, commit2.getTimeStamp() < commit3.getTimeStamp());
+ assertEquals(3, CDOUtil.getCDOObject(category).cdoRevision().getVersion());
+
+ // Load PROXY
+ ((Category)CDOUtil.getEObject(auditCategory)).getName();
+
+ // Fill cache with latest versions
+ CDORevision version2 = cacheRevision(sessionB, categoryID, 2); // Keep pointer
+ CDORevision version3 = cacheRevision(sessionB, categoryID, 3); // Keep pointer
+ System.out.println(version2);
+ System.out.println(version3);
+
+ auditView.setTimeStamp(commit3.getTimeStamp());
+
+ // Load PROXY if any
+ ((Category)CDOUtil.getEObject(auditCategory)).getName();
+
+ assertEquals(3, CDOUtil.getCDOObject(auditCategory).cdoRevision().getVersion());
+ }
+
+ private CDORevision cacheRevision(CDOSession session, CDOID id, int version)
+ {
+ CDOBranchVersion branchVersion = session.getBranchManager().getMainBranch().getVersion(version);
+ CDORevisionManager revisionManager = session.getRevisionManager();
+ return revisionManager.getRevisionByVersion(id, branchVersion, CDORevision.UNCHUNKED, true);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
index 3ba191261f..1bd7a4d3cb 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDTemp;
import org.eclipse.emf.cdo.common.model.EMFUtil;
+import org.eclipse.emf.cdo.common.revision.CDORevisable;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionFactory;
import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
@@ -23,6 +24,7 @@ import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageInfo;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionCache;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionManager;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOInvalidationPolicy;
@@ -847,10 +849,20 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
{
InternalCDOView view = object.cdoView();
- CDORevisionKey newKey = key == null ? null : CDORevisionUtil.createRevisionKey(key.getID(), key.getBranch(),
- key.getVersion() + 1);
- InternalCDORevision newRevision = newKey == null ? null : view.getSession().getRevisionManager()
- .getRevisionByVersion(newKey.getID(), newKey, 0, false);
+ CDORevisionKey newKey = null;
+ if (key != null)
+ {
+ int newVersion = getNewVersion(key);
+ newKey = CDORevisionUtil.createRevisionKey(key.getID(), key.getBranch(), newVersion);
+ }
+
+ InternalCDORevision newRevision = null;
+ if (newKey != null)
+ {
+ InternalCDORevisionCache cache = view.getSession().getRevisionManager().getCache();
+ newRevision = (InternalCDORevision)cache.getRevisionByVersion(newKey.getID(), newKey);
+ }
+
if (newRevision != null)
{
object.cdoInternalSetRevision(newRevision);
@@ -867,6 +879,21 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
}
}
}
+
+ private int getNewVersion(CDORevisionKey key)
+ {
+ if (key instanceof CDORevisionDelta)
+ {
+ CDORevisionDelta delta = (CDORevisionDelta)key;
+ CDORevisable target = delta.getTarget();
+ if (target != null && key.getBranch() == target.getBranch())
+ {
+ return target.getVersion();
+ }
+ }
+
+ return key.getVersion() + 1;
+ }
}
/**

Back to the top