Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsteban Dugueperoux2015-02-04 09:35:58 +0000
committerEsteban DUGUEPEROUX2015-02-04 13:07:09 +0000
commitd9bdccd705a19f0b6137b0254f651bae7f46c7fe (patch)
tree8def7b2b7eeea32dd757cd0298c23b3d7a758920 /plugins
parent8c711da1f172057cf2bf9c5695a47e083f63a303 (diff)
downloadcdo-d9bdccd705a19f0b6137b0254f651bae7f46c7fe.tar.gz
cdo-d9bdccd705a19f0b6137b0254f651bae7f46c7fe.tar.xz
cdo-d9bdccd705a19f0b6137b0254f651bae7f46c7fe.zip
[459104] Have requested CDOLockState stored in cache
Have requested CDOLockState stored in cache when CDOView.options().isLockNotificationEnabled() is enabled Change-Id: I8433fd0cba7d17d1b34e5281ed4a1200bdcb3a1f Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=459104 Signed-off-by: Esteban Dugueperoux <esteban.dugueperoux@obeo.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_436246_Test.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_439337_Test.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_458279_Test.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_459104_Test.java70
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/RequestCallCounter.java17
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java17
7 files changed, 106 insertions, 8 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_436246_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_436246_Test.java
index 919bbf46e4..e8cf66bb79 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_436246_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_436246_Test.java
@@ -103,6 +103,7 @@ public class Bugzilla_436246_Test extends AbstractCDOTest
testCDORevisionFetchWithChangesOnAllBranches(session, currentBranch, loadRevisionsRequestCounter, companyCDOID,
3 * NB_CATEGORY, true);
+ loadRevisionsRequestCounter.dispose();
}
/**
@@ -132,6 +133,7 @@ public class Bugzilla_436246_Test extends AbstractCDOTest
testCDORevisionFetchWithChangesOnAllBranches(session, currentBranch, loadRevisionsRequestCounter, companyCDOID,
3 * NB_CATEGORY, false);
+ loadRevisionsRequestCounter.dispose();
}
private void testCDORevisionFetchWithChangesOnAllBranches(CDOSession session, CDOBranch currentBranch,
@@ -251,6 +253,8 @@ public class Bugzilla_436246_Test extends AbstractCDOTest
view.getResourceSet().eAdapters().add(new EContentAdapter());
assertEquals(pathSegments.size() + 1, (int)nbRequestsCalls.get(CDOProtocolConstants.SIGNAL_LOAD_REVISIONS));
+
+ requestCallCounter.dispose();
}
private class CustomCDOFetchRuleManager implements CDOFetchRuleManager
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_439337_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_439337_Test.java
index ca584fb3b4..5859098c99 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_439337_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_439337_Test.java
@@ -107,6 +107,8 @@ public class Bugzilla_439337_Test extends AbstractCDOTest
assertEquals("As CDOLockState prefetch is " + (cdoLockStatePrefetchEnabled ? "" : "not ") + "enabled "
+ expectedNbLockStateRequestCalls + " LockStateRequests should have been sent to the server",
expectedNbLockStateRequestCalls, nbRequestsCalls.get(CDOProtocolConstants.SIGNAL_LOCK_STATE));
+
+ nbRequestsCallsCounter.dispose();
}
/**
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java
index 463dab7236..a5756f5c06 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_441136_Test.java
@@ -96,6 +96,8 @@ public class Bugzilla_441136_Test extends AbstractCDOTest
assertEquals(true, nbRequestsCalls.containsKey(CDOProtocolConstants.SIGNAL_COMMIT_TRANSACTION));
assertEquals(true, nbRequestsCalls.containsKey(SignalProtocol.SIGNAL_MONITOR_PROGRESS));
}
+
+ nbRequestsCallsCounter.dispose();
}
class CommitTransactionIndicationWaiting implements CDOCommitInfoHandler
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_458279_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_458279_Test.java
index c02837030b..c547bc1779 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_458279_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_458279_Test.java
@@ -85,5 +85,7 @@ public class Bugzilla_458279_Test extends AbstractCDOTest
int nbCallToChangeSubscriptionRequest = requestCallCounter.getNBRequestsCalls().get(
CDOProtocolConstants.SIGNAL_CHANGE_SUBSCRIPTION);
assertEquals("No ChangeSubscriptionRequest should be send to server", 0, nbCallToChangeSubscriptionRequest);
+
+ requestCallCounter.dispose();
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_459104_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_459104_Test.java
new file mode 100644
index 0000000000..a6af0350ec
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_459104_Test.java
@@ -0,0 +1,70 @@
+/*
+ * 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.protocol.CDOProtocolConstants;
+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.tests.util.RequestCallCounter;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView.Options;
+
+import java.util.Map;
+
+/**
+ * Bug 459104 about {@link CDOObject#cdoLockState()} which should store loaded lock state into the cache after a request to the server when {@link Options#isLockNotificationEnabled()} return true.
+ *
+ * @author Esteban Dugueperoux
+ */
+public class Bugzilla_459104_Test extends AbstractCDOTest
+{
+ private static final String RESOURCE_NAME = "test1.model1";
+
+ /**
+ * Test 2 consecutive call to {@link CDOObject#cdoLockState()}..
+ */
+ public void testCDOObject_GetLockState() throws Exception
+ {
+ CDOSession session1 = openSession();
+ CDOTransaction transaction1 = session1.openTransaction();
+ transaction1.options().setLockNotificationEnabled(true);
+ CDOResource resource1 = transaction1.createResource(getResourcePath(RESOURCE_NAME));
+ Company company = getModel1Factory().createCompany();
+ resource1.getContents().add(company);
+ transaction1.commit();
+
+ RequestCallCounter requestCallCounter = new RequestCallCounter(session1);
+
+ Map<Short, Integer> nbRequestsCalls = requestCallCounter.getNBRequestsCalls();
+ nbRequestsCalls.put(CDOProtocolConstants.SIGNAL_LOCK_STATE, 0);
+
+ CDOObject companyCDOObject = CDOUtil.getCDOObject(company);
+
+ companyCDOObject.cdoLockState();
+ int nbLockStateRequest = nbRequestsCalls.get(CDOProtocolConstants.SIGNAL_LOCK_STATE);
+ assertEquals(1, nbLockStateRequest);
+
+ companyCDOObject.cdoLockState();
+ nbLockStateRequest = nbRequestsCalls.get(CDOProtocolConstants.SIGNAL_LOCK_STATE);
+ assertEquals(1, nbLockStateRequest);
+
+ companyCDOObject.cdoLockState();
+ nbLockStateRequest = nbRequestsCalls.get(CDOProtocolConstants.SIGNAL_LOCK_STATE);
+ assertEquals(1, nbLockStateRequest);
+
+ requestCallCounter.dispose();
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/RequestCallCounter.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/RequestCallCounter.java
index b3d9d7bda6..990dd5fbf0 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/RequestCallCounter.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/util/RequestCallCounter.java
@@ -23,6 +23,8 @@ import org.eclipse.net4j.util.event.IListener;
import org.eclipse.emf.spi.cdo.CDOSessionProtocol;
import org.eclipse.emf.spi.cdo.InternalCDOSession;
+import org.junit.Assert;
+
import java.util.HashMap;
import java.util.Map;
@@ -35,12 +37,13 @@ public class RequestCallCounter implements IListener
{
private Map<Short, Integer> nbRequestsCalls = new HashMap<Short, Integer>();
+ private CDOClientProtocol cdoClientProtocol;
+
public RequestCallCounter(CDOSession session)
{
InternalCDOSession internalCDOSession = (InternalCDOSession)session;
CDOSessionProtocol sessionProtocol = internalCDOSession.getSessionProtocol();
- CDOClientProtocol cdoClientProtocol = null;
if (sessionProtocol instanceof CDOClientProtocol)
{
cdoClientProtocol = (CDOClientProtocol)sessionProtocol;
@@ -54,10 +57,9 @@ public class RequestCallCounter implements IListener
cdoClientProtocol = (CDOClientProtocol)delegate;
}
}
- if (cdoClientProtocol != null)
- {
- cdoClientProtocol.addListener(this);
- }
+
+ Assert.assertNotNull(cdoClientProtocol);
+ cdoClientProtocol.addListener(this);
}
public void notifyEvent(IEvent event)
@@ -83,4 +85,9 @@ public class RequestCallCounter implements IListener
return nbRequestsCalls;
}
+ public void dispose()
+ {
+ cdoClientProtocol.removeListener(this);
+ cdoClientProtocol = 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 65279d0506..32dd114900 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
@@ -764,18 +764,29 @@ public class CDOViewImpl extends AbstractCDOView
{
CDOSessionProtocol sessionProtocol = session.getSessionProtocol();
CDOLockState[] loadedLockStates = sessionProtocol.getLockStates(viewID, missing);
+ List<CDOLockState> newLockStateForCache = new ArrayList<CDOLockState>(loadedLockStates.length + missing.size());
+
for (CDOLockState loadedLockState : loadedLockStates)
{
lockStates.add(loadedLockState);
+ newLockStateForCache.add(loadedLockState);
CDOID cdoID = CDOIDUtil.getCDOID(loadedLockState.getLockedObject());
if (cdoID != null)
{
missing.remove(cdoID);
}
}
+
for (CDOID missingLockStateForCDOID : missing)
{
- lockStates.add(CDOLockUtil.createLockState(missingLockStateForCDOID));
+ CDOLockState defaultLockState = CDOLockUtil.createLockState(missingLockStateForCDOID);
+ lockStates.add(defaultLockState);
+ newLockStateForCache.add(defaultLockState);
+ }
+
+ if (options().isLockNotificationEnabled())
+ {
+ updateLockStates(newLockStateForCache.toArray(new CDOLockState[newLockStateForCache.size()]));
}
}
@@ -1724,9 +1735,9 @@ public class CDOViewImpl extends AbstractCDOView
CDOID id = revision.getID();
if (id != null && lockStateLoadingPolicy.loadLockState(id))
{
- // - Don't ask to create an object for CDOResource as the caller of ResourceSet.getResource()
+ // - Don't ask to create an object for CDOResource as the caller of ResourceSet.getResource()
// can have created it but not yet registered in CDOView.
- // - Don't ask others CDOResourceNode either as it will create some load revisions request
+ // - Don't ask others CDOResourceNode either as it will create some load revisions request
// in addition to mode without lock state prefetch
boolean isResourceNode = revision.isResourceNode();
InternalCDOObject object = getObject(id, !isResourceNode);

Back to the top