Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests/src/org/eclipse')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SessionTest.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_355045_Test.java204
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_387563_Test.java179
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_387563b_Test.java85
4 files changed, 476 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SessionTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SessionTest.java
index bdebdba5b6..6721079c85 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SessionTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/SessionTest.java
@@ -63,6 +63,14 @@ public class SessionTest extends AbstractCDOTest
private static final char[] PASSWORD2 = "invalid".toCharArray(); //$NON-NLS-1$
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ enableConsole();
+
+ }
+
public void testIsSupportingAudits() throws Exception
{
CDOSession session = openSession();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_355045_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_355045_Test.java
new file mode 100644
index 0000000000..5dc2a66c74
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_355045_Test.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2004 - 2012 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:
+ * Esteban Dugueperoux - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.CDOState;
+import org.eclipse.emf.cdo.common.CDOCommonSession.Options.LockNotificationMode;
+import org.eclipse.emf.cdo.common.lock.CDOLockState;
+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.Category;
+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.net4j.util.concurrent.IRWLockManager.LockType;
+
+import org.junit.Assert;
+
+import java.util.Collections;
+
+/**
+ * @author Esteban Dugueperoux
+ */
+public class Bugzilla_355045_Test extends AbstractCDOTest
+{
+ private static final String RESOURCE_PATH = "/test1";
+
+ private CDOTransaction transaction;
+
+ private Company company;
+
+ private Category category1;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ CDOSession cdoSession = openSession();
+ cdoSession.options().setLockNotificationMode(LockNotificationMode.ALWAYS);
+ transaction = cdoSession.openTransaction();
+ // cdoTransaction.options().setAutoReleaseLocksEnabled(false);
+ CDOResource cdoResource = transaction.createResource(getResourcePath(RESOURCE_PATH));
+
+ company = getModel1Factory().createCompany();
+ category1 = getModel1Factory().createCategory();
+ company.getCategories().add(category1);
+
+ cdoResource.getContents().add(company);
+ cdoResource.save(Collections.emptyMap());
+ }
+
+ public void testLockOnCommitOfSingleNewObject() throws Exception
+ {
+ Category category2 = getModel1Factory().createCategory();
+ category2.setName("category2");
+ category1.getCategories().add(category2);
+
+ transaction.lockObjects(CDOUtil.getCDOObjects(category2), LockType.WRITE, DEFAULT_TIMEOUT);
+ assertLockStatus(category2, true, false);
+
+ transaction.commit();
+ assertEquals(CDOState.CLEAN, CDOUtil.getCDOObject(category2).cdoState());
+ assertLockStatus(category2, true, false);
+ }
+
+ public void testRecursiveLockOnCommitOfNewObjectsTree() throws Exception
+ {
+ Category category2 = getModel1Factory().createCategory();
+ category2.setName("category2");
+ Category category4 = getModel1Factory().createCategory();
+ category4.setName("category4");
+ Category category5 = getModel1Factory().createCategory();
+ category5.setName("category5");
+ Category category6 = getModel1Factory().createCategory();
+ category6.setName("category6");
+ Category category7 = getModel1Factory().createCategory();
+ category7.setName("category7");
+
+ category2.getCategories().add(category4);
+ category2.getCategories().add(category5);
+ category4.getCategories().add(category6);
+ category5.getCategories().add(category7);
+ category1.getCategories().add(category2);
+
+ Category category3 = getModel1Factory().createCategory();
+ category3.setName("category3");
+ Category category8 = getModel1Factory().createCategory();
+ category8.setName("category8");
+ Category category9 = getModel1Factory().createCategory();
+ category9.setName("category9");
+ Category category10 = getModel1Factory().createCategory();
+ category10.setName("category10");
+ Category category11 = getModel1Factory().createCategory();
+ category11.setName("category11");
+
+ category3.getCategories().add(category8);
+ category3.getCategories().add(category9);
+ category8.getCategories().add(category10);
+ category9.getCategories().add(category11);
+ category1.getCategories().add(category3);
+
+ transaction.lockObjects(CDOUtil.getCDOObjects(category2), LockType.WRITE, DEFAULT_TIMEOUT, true);
+ transaction.options().addAutoReleaseLocksExemptions(true, category2);
+
+ assertLockStatus(category1, false, false);
+ assertLockStatus(category2, true, true);
+ assertLockStatus(category3, false, true);
+
+ transaction.lockObjects(CDOUtil.getCDOObjects(category3), LockType.WRITE, DEFAULT_TIMEOUT, true);
+ transaction.options().addAutoReleaseLocksExemptions(true, category3);
+
+ assertLockStatus(category1, false, false);
+ assertLockStatus(category2, true, true);
+ assertLockStatus(category3, true, true);
+
+ transaction.unlockObjects(CDOUtil.getCDOObjects(category3), LockType.WRITE);
+
+ assertLockStatus(category1, false, false);
+ assertLockStatus(category2, true, true);
+ assertLockStatus(category3, false, false);
+ assertLockStatus(category8, true, true);
+ assertLockStatus(category9, true, true);
+
+ transaction.commit();
+
+ assertLockStatus(category1, false, false);
+ assertLockStatus(category2, true, true);
+ assertLockStatus(category3, false, false);
+ assertLockStatus(category8, true, true);
+ assertLockStatus(category9, true, true);
+ }
+
+ public void testRecursiveLockOfObjectsTreeContainingASubTreeOfNewObjects() throws Exception
+ {
+ Category category2 = getModel1Factory().createCategory();
+ category2.setName("category2");
+ Category category4 = getModel1Factory().createCategory();
+ category4.setName("category4");
+ Category category5 = getModel1Factory().createCategory();
+ category5.setName("category5");
+ Category category6 = getModel1Factory().createCategory();
+ category6.setName("category6");
+ Category category7 = getModel1Factory().createCategory();
+ category7.setName("category7");
+
+ category2.getCategories().add(category4);
+ category2.getCategories().add(category5);
+ category4.getCategories().add(category6);
+ category5.getCategories().add(category7);
+ category1.getCategories().add(category2);
+
+ Category category3 = getModel1Factory().createCategory();
+ category3.setName("category3");
+ Category category8 = getModel1Factory().createCategory();
+ category8.setName("category8");
+ Category category9 = getModel1Factory().createCategory();
+ category9.setName("category9");
+ Category category10 = getModel1Factory().createCategory();
+ category10.setName("category10");
+ Category category11 = getModel1Factory().createCategory();
+ category11.setName("category11");
+
+ category3.getCategories().add(category8);
+ category3.getCategories().add(category9);
+ category8.getCategories().add(category10);
+ category9.getCategories().add(category11);
+ category1.getCategories().add(category3);
+
+ transaction.lockObjects(CDOUtil.getCDOObjects(category1), LockType.WRITE, DEFAULT_TIMEOUT, true);
+ transaction.options().addAutoReleaseLocksExemptions(false, category1);
+ assertLockStatus(category1, true, false);
+
+ transaction.commit();
+ assertLockStatus(category1, true, false);
+ }
+
+ private void assertLockStatus(Category category, boolean lockedByMe, boolean recursive)
+ {
+ CDOObject categoryCDOObject = CDOUtil.getCDOObject(category);
+ CDOLockState cdoLockState = categoryCDOObject.cdoLockState();
+ Assert.assertEquals(
+ "new object " + category.getName()
+ + (lockedByMe ? " should be locally locked" : " shouldn't be locally locked"),
+ lockedByMe, cdoLockState.isLocked(LockType.WRITE, transaction, false));
+
+ if (recursive)
+ {
+ for (Category subCategory : category.getCategories())
+ {
+ assertLockStatus(subCategory, lockedByMe, recursive);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_387563_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_387563_Test.java
new file mode 100644
index 0000000000..638c3292c6
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_387563_Test.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2004 - 2012 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:
+ * Esteban Dugueperoux - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.CDOCommonSession.Options.LockNotificationMode;
+import org.eclipse.emf.cdo.common.lock.CDOLockState;
+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.Category;
+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.net4j.util.concurrent.IRWLockManager.LockType;
+
+/**
+ * @author Esteban Dugueperoux
+ */
+public class Bugzilla_387563_Test extends AbstractCDOTest
+{
+ private CDOTransaction transaction;
+
+ private Company company;
+
+ private Category category1;
+
+ private Category category2;
+
+ private Category category3;
+
+ private Category category4;
+
+ private Category category5;
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ super.doSetUp();
+
+ CDOSession session = openSession();
+ session.options().setLockNotificationMode(LockNotificationMode.ALWAYS);
+
+ transaction = session.openTransaction();
+ // transaction.options().setAutoReleaseLocksEnabled(false);
+
+ CDOResource resource = transaction.createResource(getResourcePath("test1"));
+
+ category1 = getModel1Factory().createCategory();
+ category1.setName("category1");
+
+ category2 = getModel1Factory().createCategory();
+ category2.setName("category2");
+
+ category3 = getModel1Factory().createCategory();
+ category3.setName("category3");
+
+ category4 = getModel1Factory().createCategory();
+ category4.setName("category4");
+
+ category5 = getModel1Factory().createCategory();
+ category5.setName("category5");
+
+ Category category6 = getModel1Factory().createCategory();
+ category6.setName("category6");
+
+ Category category7 = getModel1Factory().createCategory();
+ category7.setName("category7");
+
+ Category category8 = getModel1Factory().createCategory();
+ category8.setName("category8");
+
+ Category category9 = getModel1Factory().createCategory();
+ category9.setName("category9");
+
+ Category category10 = getModel1Factory().createCategory();
+ category10.setName("category10");
+
+ Category category11 = getModel1Factory().createCategory();
+ category11.setName("category11");
+
+ category1.getCategories().add(category2);
+ category1.getCategories().add(category3);
+ category2.getCategories().add(category4);
+ category2.getCategories().add(category5);
+ category3.getCategories().add(category8);
+ category3.getCategories().add(category9);
+ category4.getCategories().add(category6);
+ category5.getCategories().add(category7);
+ category8.getCategories().add(category10);
+ category9.getCategories().add(category11);
+
+ company = getModel1Factory().createCompany();
+ company.getCategories().add(category1);
+
+ resource.getContents().add(company);
+ }
+
+ public void testPartialLockOnCommit() throws Exception
+ {
+ // Mark all objects to be locked on commit
+ transaction.lockObjects(CDOUtil.getCDOObjects(category1), LockType.WRITE, DEFAULT_TIMEOUT, true);
+ transaction.options().addAutoReleaseLocksExemptions(true, category1);
+ assertLockStatus(category1, true, true);
+
+ // Mark category2 to be unlocked on commit
+ transaction.options().removeAutoReleaseLocksExemptions(false, category2);
+
+ assertLockStatus(category1, true, false);
+
+ LOCAL LOCK NOT RELEASED!
+ assertLockStatus(category2, false, false);
+
+ assertLockStatus(category4, true, true);
+ assertLockStatus(category5, true, true);
+ assertLockStatus(category3, true, true);
+
+ // Mark category3 and its descendants to be unlocked on commit
+ transaction.options().removeAutoReleaseLocksExemptions(true, category3);
+
+ assertLockStatus(category1, true, false);
+ assertLockStatus(category2, false, false);
+ assertLockStatus(category4, true, true);
+ assertLockStatus(category5, true, true);
+ assertLockStatus(category3, false, true);
+
+ transaction.commit();
+
+ assertLockStatus(category1, true, false);
+ assertLockStatus(category2, false, false);
+ assertLockStatus(category4, true, true);
+ assertLockStatus(category5, true, true);
+ assertLockStatus(category3, false, true);
+ }
+
+ public void testPartialUnlockOnCommit() throws Exception
+ {
+ // Mark category1 as locked and all contained new category as to be locked on commit
+ transaction.lockObjects(CDOUtil.getCDOObjects(category1), LockType.WRITE, DEFAULT_TIMEOUT, true);
+ transaction.options().addAutoReleaseLocksExemptions(true, category1);
+ assertLockStatus(category1, true, true);
+
+ transaction.unlockObjects(CDOUtil.getCDOObjects(category3), LockType.WRITE, true);
+ assertLockStatus(category3, false, true);
+
+ transaction.commit();
+
+ assertLockStatus(category1, true, false);
+ assertLockStatus(category2, true, true);
+ assertLockStatus(category3, false, true);
+ }
+
+ private static void assertLockStatus(Category category, boolean expected, boolean recursive)
+ {
+ CDOObject cdoObject = CDOUtil.getCDOObject(category);
+ CDOLockState lockState = cdoObject.cdoLockState();
+
+ assertEquals(
+ "new object " + category.getName() + (expected ? " should be locally locked" : " shouldn't be locally locked"),
+ expected, lockState.isLocked(LockType.WRITE, cdoObject.cdoView(), false));
+
+ if (recursive)
+ {
+ for (Category subCategory : category.getCategories())
+ {
+ assertLockStatus(subCategory, expected, recursive);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_387563b_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_387563b_Test.java
new file mode 100644
index 0000000000..9efc07f4ec
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_387563b_Test.java
@@ -0,0 +1,85 @@
+/*
+ * 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.common.lock.CDOLockState;
+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.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.emf.internal.cdo.view.CDOViewImpl;
+
+import org.eclipse.net4j.util.ReflectUtil;
+
+import org.eclipse.emf.ecore.EObject;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author Eike Stepper
+ */
+public class Bugzilla_387563b_Test extends AbstractCDOTest
+{
+ private static final Method GET_LOCK_STATE_METHOD = ReflectUtil.getMethod(CDOViewImpl.class, "getLockState",
+ CDOObject.class);
+
+ public void testNoImplicitLockingOfNewObject() throws Exception
+ {
+ Company company = getModel1Factory().createCompany();
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ transaction.options().setAutoReleaseLocksEnabled(true);
+
+ CDOResource resource = transaction.createResource(getResourcePath("test1"));
+ resource.getContents().add(company);
+
+ CDOObject cdoObject = CDOUtil.getCDOObject(company);
+ CDOLockState lockState = cdoObject.cdoLockState();
+ assertNull(lockState.getWriteLockOwner());
+
+ transaction.commit();
+ assertNull(getLockState(cdoObject));
+ }
+
+ public void testExplicitLockingOfNewObject() throws Exception
+ {
+ Company company = getModel1Factory().createCompany();
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ transaction.options().setAutoReleaseLocksEnabled(true);
+
+ CDOResource resource = transaction.createResource(getResourcePath("test1"));
+ resource.getContents().add(company);
+
+ CDOObject cdoObject = CDOUtil.getCDOObject(company);
+ cdoObject.cdoWriteLock().lock();
+
+ CDOLockState lockState = cdoObject.cdoLockState();
+ assertEquals(transaction, lockState.getWriteLockOwner());
+
+ transaction.commit();
+ assertNull(getLockState(cdoObject));
+ }
+
+ private static CDOLockState getLockState(EObject object)
+ {
+ CDOObject cdoObject = CDOUtil.getCDOObject(object);
+ CDOViewImpl view = (CDOViewImpl)cdoObject.cdoView();
+
+ return (CDOLockState)ReflectUtil.invokeMethod(GET_LOCK_STATE_METHOD, view, cdoObject);
+ }
+}

Back to the top