diff options
author | Maxime Porhel | 2016-05-15 09:34:03 +0000 |
---|---|---|
committer | Eike Stepper | 2016-05-15 09:34:03 +0000 |
commit | bc0774025a6a7fbf129938e84a2d0b7ff7118d8f (patch) | |
tree | 332e322d0a53133a30bbae449ac43b62875c8e7c /plugins/org.eclipse.emf.cdo.tests/src | |
parent | 45ead532133c5e2772a91b9d5075ca8e483d4ccf (diff) | |
download | cdo-bc0774025a6a7fbf129938e84a2d0b7ff7118d8f.tar.gz cdo-bc0774025a6a7fbf129938e84a2d0b7ff7118d8f.tar.xz cdo-bc0774025a6a7fbf129938e84a2d0b7ff7118d8f.zip |
[467174] Bad lock state with lock state and revision prefetch
https://bugs.eclipse.org/bugs/show_bug.cgi?id=467174
- Add Bugzilla_467174_Test JUnit test.
- Add fix in CDOViewImpl and AbstractCDOView.
Change-Id: Ic1ca47ac347a0909fd074bac53f222e57e25c9d8
Signed-off-by: Esteban Dugueperoux <esteban.dugueperoux@obeo.fr>
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
Signed-off-by: Eike Stepper <stepper@esc-net.de>
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_467174_Test.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_467174_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_467174_Test.java new file mode 100644 index 0000000000..210bd72325 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_467174_Test.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015 Obeo 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.id.CDOID; +import org.eclipse.emf.cdo.common.revision.CDORevision; +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.emf.internal.cdo.view.CDOViewImpl.OptionsImpl; + +import org.eclipse.net4j.util.concurrent.IRWLockManager.LockType; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; + +import org.junit.Assert; + +import java.util.Collections; + +/** + * Bug 467174 to test lock state and revision prefetch. + * + * @author Esteban Dugueperoux + */ +public class Bugzilla_467174_Test extends AbstractCDOTest +{ + public void testCDOObject_LockStateAndRevisionPrefetch() throws Exception + { + CDOSession session1 = openSession(); + CDOTransaction transaction1 = session1.openTransaction(); + + OptionsImpl options = (OptionsImpl)transaction1.options(); + options.setLockNotificationEnabled(true); + options.setLockStatePrefetchEnabled(true); + + CDOResource resource1 = transaction1.createResource(getResourcePath("test1.model1")); + Company company = getModel1Factory().createCompany(); + Category category = getModel1Factory().createCategory(); + company.getCategories().add(category); + resource1.getContents().add(company); + resource1.save(Collections.emptyMap()); + + CDOObject companyCDOObject = CDOUtil.getCDOObject(company); + CDOID companyCDOID = companyCDOObject.cdoID(); + CDOObject categoryCDOObject = CDOUtil.getCDOObject(category); + CDOID categoryCDOID = categoryCDOObject.cdoID(); + + CDOSession session2 = openSession(); + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.eAdapters().add(new AdapterImpl() + { + @Override + public void notifyChanged(Notification msg) + { + Object newValue = msg.getNewValue(); + if (newValue instanceof CDOResource) + { + ((CDOResource)newValue).cdoPrefetch(CDORevision.DEPTH_INFINITE); + } + } + }); + + CDOTransaction transaction2 = session2.openTransaction(resourceSet); + transaction2.options().setLockNotificationEnabled(true); + ((OptionsImpl)transaction2.options()).setLockStatePrefetchEnabled(true); + + transaction1.lockObjects(Collections.singletonList(categoryCDOObject), LockType.WRITE, 1); + transaction1.lockObjects(Collections.singletonList(companyCDOObject), LockType.WRITE, 1); + + CDOObject companyCDOObjectFromTx2 = transaction2.getObject(companyCDOID); + CDOObject categoryCDOObjectFromTx2 = transaction2.getObject(categoryCDOID); + Assert.assertTrue(companyCDOObjectFromTx2.cdoWriteLock().isLockedByOthers()); + Assert.assertTrue(categoryCDOObjectFromTx2.cdoWriteLock().isLockedByOthers()); + } +} |