Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2016-01-10 10:11:41 +0000
committerEike Stepper2016-01-12 06:58:47 +0000
commit9179b45a72a36536686f603bbfef284550302d28 (patch)
tree2e189caa1fdec3f47b7956583e803cc32aeb0201
parent5067513104cdd3f10afba56e5ebc2fe54c46b11b (diff)
downloadcdo-9179b45a72a36536686f603bbfef284550302d28.tar.gz
cdo-9179b45a72a36536686f603bbfef284550302d28.tar.xz
cdo-9179b45a72a36536686f603bbfef284550302d28.zip
[485489] CDOAutoLocker: Some locks can be left after view has been closed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=485489
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_485489_Test.java98
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/RWOLockManager.java2
2 files changed, 99 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_485489_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_485489_Test.java
new file mode 100644
index 0000000000..f561238f78
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_485489_Test.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2016 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+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.model1.Company;
+import org.eclipse.emf.cdo.transaction.CDOAutoLocker;
+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.ecore.EObject;
+
+/**
+ * Bug 485489: CDOAutoLocker: Some locks can be left after view has been closed
+ *
+ * @author Eike Stepper
+ */
+public class Bugzilla_485489_Test extends AbstractCDOTest
+{
+ public void testTransactionCommitAfterAutoLocker() throws Exception
+ {
+ Company company = getModel1Factory().createCompany();
+ company.setName("Company1");
+ company.setStreet("Street1");
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/test1"));
+ resource.getContents().add(company);
+
+ transaction.commit();
+ assertWriteLock(false, company);
+
+ transaction.addTransactionHandler(new CDOAutoLocker());
+
+ company.setName("Company2"); // Acquire write lock.
+ company.setStreet("Street2"); // Increase write lock count to 2.
+ assertWriteLock(true, company);
+
+ transaction.commit();
+ assertWriteLock(false, company);
+ }
+
+ public void testViewCloseAfterAutoLocker() throws Exception
+ {
+ Company company = getModel1Factory().createCompany();
+ company.setName("Company1");
+ company.setStreet("Street1");
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("/test1"));
+ resource.getContents().add(company);
+
+ transaction.commit();
+ assertWriteLock(false, company);
+
+ transaction.addTransactionHandler(new CDOAutoLocker());
+
+ company.setName("Company2"); // Acquire write lock.
+ company.setStreet("Street2"); // Increase write lock count to 2.
+ assertWriteLock(true, company);
+
+ transaction.close();
+ assertWriteLock(false, company);
+ }
+
+ private void assertWriteLock(boolean expected, EObject object) throws InterruptedException
+ {
+ CDOObject cdoObject = CDOUtil.getCDOObject(object);
+ CDOView view = cdoObject.cdoView();
+ CDOTransaction transaction = view.getSession().openTransaction(view.getBranch());
+
+ try
+ {
+ CDOObject txObject = transaction.getObject(cdoObject);
+
+ boolean actual = !txObject.cdoWriteLock().tryLock(500);
+ assertEquals(expected, actual);
+ }
+ finally
+ {
+ transaction.close();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/RWOLockManager.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/RWOLockManager.java
index 5cc4f42b7b..88df795238 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/RWOLockManager.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/concurrent/RWOLockManager.java
@@ -231,7 +231,7 @@ public class RWOLockManager<OBJECT, CONTEXT> extends Lifecycle implements IRWOLo
{
for (LockType lockType : LockType.values())
{
- if (lockState.hasLock(lockType, context, false))
+ while (lockState.hasLock(lockType, context, false))
{
lockState.unlock(lockType, context);
}

Back to the top