Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2018-11-11 02:40:02 -0500
committerEike Stepper2018-11-11 02:40:02 -0500
commita40d50ce4fd84ed7a6527a4250b61ebb755b9f1a (patch)
treebfdd336b9e02540c491d3a2384c13e7f65b392fa
parentce0922f8c77ea376bb85111a26353c29bd315218 (diff)
downloadcdo-a40d50ce4fd84ed7a6527a4250b61ebb755b9f1a.tar.gz
cdo-a40d50ce4fd84ed7a6527a4250b61ebb755b9f1a.tar.xz
cdo-a40d50ce4fd84ed7a6527a4250b61ebb755b9f1a.zip
[541003] LockStatePrefetcher does not update other views
https://bugs.eclipse.org/bugs/show_bug.cgi?id=541003
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_541003_Test.java108
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java5
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLockImpl.java21
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java5
4 files changed, 132 insertions, 7 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_541003_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_541003_Test.java
new file mode 100644
index 0000000000..ec9b7977a3
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_541003_Test.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2018 Eike Stepper (Loehne, 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOLock;
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.lock.CDOLockState;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.net4j.CDONet4jSession;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.config.ISessionConfig;
+import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.emf.internal.cdo.view.CDOViewImpl;
+import org.eclipse.emf.internal.cdo.view.CDOViewImpl.OptionsImpl;
+
+import java.util.Collections;
+
+/**
+ * Bug 541003 - LockStatePrefetcher does not update other views.
+ *
+ * @author Eike Stepper
+ */
+@Requires(ISessionConfig.CAPABILITY_NET4J)
+public class Bugzilla_541003_Test extends AbstractCDOTest
+{
+ public void testLockStateWithPrefetcher() throws Exception
+ {
+ run(true);
+ }
+
+ public void testLockStateWithoutPrefetcher() throws Exception
+ {
+ run(false);
+ }
+
+ private void run(boolean lockStatePrefetchEnabled) throws Exception
+ {
+ CDOLock lock = prepareLock();
+ lock.lock();
+
+ CDONet4jSession session = (CDONet4jSession)openSession();
+
+ CDOView view1 = openView(session, lockStatePrefetchEnabled);
+ CDOView view2 = openView(session, false);
+
+ // With lockStatePrefetchEnabled the lock state is loaded here:
+ CDOLock lock1 = loadLock(view1);
+ CDOLock lock2 = loadLock(view2);
+ assertEquals(lockStatePrefetchEnabled, hasLockState(lock1));
+ assertEquals(lockStatePrefetchEnabled, hasLockState(lock2));
+
+ // Without lockStatePrefetchEnabled the lock state is loaded here:
+ assertTrue(lock1.isLockedByOthers());
+ assertTrue(lock2.isLockedByOthers());
+ assertEquals(true, hasLockState(lock1));
+ assertEquals(true, hasLockState(lock2));
+ }
+
+ private CDOLock prepareLock() throws Exception
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("res"));
+
+ Company company = getModel1Factory().createCompany();
+ resource.getContents().add(company);
+ transaction.commit();
+
+ return CDOUtil.getCDOObject(company).cdoWriteLock();
+ }
+
+ private CDOView openView(CDOSession session, boolean lockStatePrefetchEnabled)
+ {
+ CDOView view = session.openView();
+ ((OptionsImpl)view.options()).setLockStatePrefetchEnabled(lockStatePrefetchEnabled);
+ return view;
+ }
+
+ private CDOLock loadLock(CDOView view)
+ {
+ CDOResource resource = view.getResource(getResourcePath("res"));
+ Company company = (Company)resource.getContents().get(0);
+ return CDOUtil.getCDOObject(company).cdoWriteLock();
+ }
+
+ private boolean hasLockState(CDOLock lock)
+ {
+ CDOObject object = lock.getObject();
+ CDOViewImpl view = (CDOViewImpl)object.cdoView();
+
+ CDOLockState[] lockStates = view.getLockStates(Collections.singleton(object.cdoID()), false);
+ return lockStates != null && lockStates.length == 1;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java
index 1bbc5890dd..483d75157a 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java
@@ -36,6 +36,11 @@ public interface CDOLock extends Lock
public static final int NO_WAIT = IRWLockManager.NO_WAIT;
/**
+ * @since 4.7
+ */
+ public CDOObject getObject();
+
+ /**
* @since 3.0
*/
public LockType getType();
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLockImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLockImpl.java
index 50f65b1c48..d17a903570 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLockImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLockImpl.java
@@ -12,6 +12,7 @@
package org.eclipse.emf.internal.cdo.object;
import org.eclipse.emf.cdo.CDOLock;
+import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.lock.CDOLockOwner;
import org.eclipse.emf.cdo.common.lock.CDOLockUtil;
import org.eclipse.emf.cdo.util.LockTimeoutException;
@@ -48,6 +49,11 @@ public class CDOLockImpl implements CDOLock
owner = CDOLockUtil.createLockOwner(object.cdoView());
}
+ public InternalCDOObject getObject()
+ {
+ return object;
+ }
+
public LockType getType()
{
return type;
@@ -163,6 +169,16 @@ public class CDOLockImpl implements CDOLock
{
}
+ public CDOObject getObject()
+ {
+ return null;
+ }
+
+ public LockType getType()
+ {
+ return null;
+ }
+
public boolean isLocked()
{
return false;
@@ -220,10 +236,5 @@ public class CDOLockImpl implements CDOLock
{
throw new UnsupportedOperationException();
}
-
- public LockType getType()
- {
- return null;
- }
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
index 5cae0b99ca..00d8a84fc1 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
@@ -999,7 +999,7 @@ public class CDOViewImpl extends AbstractCDOView implements IExecutorServiceProv
}
}
- protected CDOLockState[] getLockStates(Collection<CDOID> ids, boolean loadOnDemand)
+ public CDOLockState[] getLockStates(Collection<CDOID> ids, boolean loadOnDemand)
{
synchronized (getViewMonitor())
{
@@ -2677,6 +2677,7 @@ public class CDOViewImpl extends AbstractCDOView implements IExecutorServiceProv
{
Set<CDOID> ids = new HashSet<CDOID>();
CDOLockStateLoadingPolicy lockStateLoadingPolicy = options().getLockStateLoadingPolicy();
+
for (CDORevision revision : revisionsLoadedEvent.getPrimaryLoadedRevisions())
{
// Bug 466721 : Check null if it is a about a DetachedRevision
@@ -2753,7 +2754,7 @@ public class CDOViewImpl extends AbstractCDOView implements IExecutorServiceProv
{
if (view != CDOViewImpl.this && view.getBranch() == getBranch())
{
- updateLockStates(lockStates, loadOnDemand);
+ ((CDOViewImpl)view).updateLockStates(lockStates, loadOnDemand);
}
}
}

Back to the top