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 /plugins/org.eclipse.emf.cdo.tests/src
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
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_541003_Test.java108
1 files changed, 108 insertions, 0 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;
+ }
+}

Back to the top