JBoss Cache SVN: r5390 - in core/trunk/src: test/java/org/jboss/cache/marshall and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-03-05 19:45:19 -0500 (Wed, 05 Mar 2008)
New Revision: 5390
Added:
core/trunk/src/main/java/org/jboss/cache/marshall/UnmarshalledReferences.java
core/trunk/src/test/java/org/jboss/cache/marshall/UnmarshalledReferencesTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
Log:
fixed an issue that influenced state transfer after activation and added unit tests to guard the problem
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-03-05 17:19:14 UTC (rev 5389)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-03-06 00:45:19 UTC (rev 5390)
@@ -843,47 +843,3 @@
}
}
-/**
- * An efficient array-based list of referenced objects, using the reference id as a subscript for the array.
- */
-class UnmarshalledReferences
-{
- private ArrayList<Object> referencedObjects = new ArrayList<Object>();
-
- /**
- * Retrieves an object referenced by an id
- *
- * @param ref reference
- * @return object
- */
- public Object getReferencedObject(int ref)
- {
- if (ref >= referencedObjects.size())
- throw new CacheException("Attempting to look up a ref that hasn't been inserted yet");
- return referencedObjects.get(ref);
- }
-
- /**
- * Adds a referenced object to the list of references
- *
- * @param ref reference id
- * @param o object
- */
- public void putReferencedObject(int ref, Object o)
- {
- int sz = referencedObjects.size();
- // if we are not adding the object to the end of the list, make sure we use a specific position
- if (ref < sz)
- {
- referencedObjects.add(ref, o);
- return;
- }
- else if (ref > sz)
- {
- // if we are adding the reference to a position beyond the end of the list, make sure we expand the list first.
- // this can happen, weirdly enough, since marshallObject() can be called recursively, such as from marshallFqn().
- for (int i = sz; i < ref; i++) referencedObjects.add(null);
- }
- referencedObjects.add(o);
- }
-}
Added: core/trunk/src/main/java/org/jboss/cache/marshall/UnmarshalledReferences.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/UnmarshalledReferences.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/UnmarshalledReferences.java 2008-03-06 00:45:19 UTC (rev 5390)
@@ -0,0 +1,52 @@
+package org.jboss.cache.marshall;
+
+import org.jboss.cache.CacheException;
+
+import java.util.ArrayList;
+
+/**
+ * An efficient array-based list of referenced objects, using the reference id as a subscript for the array.
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
+ */
+public class UnmarshalledReferences
+{
+ private ArrayList<Object> referencedObjects = new ArrayList<Object>();
+
+ /**
+ * Retrieves an object referenced by an id
+ *
+ * @param ref reference
+ * @return object
+ */
+ public Object getReferencedObject(int ref)
+ {
+ if (ref >= referencedObjects.size())
+ throw new CacheException("Attempting to look up a ref that hasn't been inserted yet");
+ return referencedObjects.get(ref);
+ }
+
+ /**
+ * Adds a referenced object to the list of references
+ *
+ * @param ref reference id
+ * @param o object
+ */
+ public void putReferencedObject(int ref, Object o)
+ {
+ int sz = referencedObjects.size();
+ // if we are not adding the object to the end of the list, make sure we use a specific position
+ if (ref < sz)
+ {
+ referencedObjects.set(ref, o);
+ return;
+ }
+ else if (ref > sz)
+ {
+ // if we are adding the reference to a position beyond the end of the list, make sure we expand the list first.
+ // this can happen, weirdly enough, since marshallObject() can be called recursively, such as from marshallFqn().
+ for (int i = sz; i < ref; i++) referencedObjects.add(null);
+ }
+ referencedObjects.add(o);
+ }
+}
Added: core/trunk/src/test/java/org/jboss/cache/marshall/UnmarshalledReferencesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/UnmarshalledReferencesTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/UnmarshalledReferencesTest.java 2008-03-06 00:45:19 UTC (rev 5390)
@@ -0,0 +1,52 @@
+package org.jboss.cache.marshall;
+
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+import static org.testng.Assert.assertEquals;
+
+/**
+ * Tester for <code>UnmarshalledReferences</code>.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+@Test(groups = {"functional"})
+public class UnmarshalledReferencesTest
+{
+ public void testSimpleGetPut()
+ {
+ UnmarshalledReferences refs = new UnmarshalledReferences();
+ for (int i = 0; i < 100; i++)
+ {
+ refs.putReferencedObject(i, String.valueOf(i));
+ }
+ for (int i = 0; i < 100; i++)
+ {
+ assertEquals(refs.getReferencedObject(i), String.valueOf(i));
+ }
+ }
+
+ public void testPutWithGap()
+ {
+ UnmarshalledReferences refs = new UnmarshalledReferences();
+ refs.putReferencedObject(0, "0");
+ refs.putReferencedObject(2, "2");
+ assertEquals(refs.getReferencedObject(0), "0");
+ assertNull(refs.getReferencedObject(1));
+ assertEquals(refs.getReferencedObject(2), "2");
+ }
+
+ public void testPutBefore()
+ {
+ UnmarshalledReferences refs = new UnmarshalledReferences();
+ refs.putReferencedObject(2, "2");
+ refs.putReferencedObject(3, "3");
+
+ //when adding this make sure other positions are not shifted
+ refs.putReferencedObject(1, "1");
+
+ assertNull(refs.getReferencedObject(0));
+ assertEquals("1", refs.getReferencedObject(1));
+ assertEquals("2", refs.getReferencedObject(2));
+ assertEquals("3", refs.getReferencedObject(3));
+ }
+}
16 years, 10 months
JBoss Cache SVN: r5389 - in core/trunk/src: test/java/org/jboss/cache/api and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-05 12:19:14 -0500 (Wed, 05 Mar 2008)
New Revision: 5389
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java
Log:
JBCACHE-1296 - Also applies to data in undeleted nodes
JBCACHE-1294 - Double removal of a node may cause unintended resurrection
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-03-05 16:55:13 UTC (rev 5388)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-03-05 17:19:14 UTC (rev 5389)
@@ -96,6 +96,7 @@
protected void undeleteWorkspaceNode(WorkspaceNode nodeToUndelete, WorkspaceNode parent)
{
nodeToUndelete.markAsDeleted(false);
+ nodeToUndelete.clearData();
// add in parent again
parent.addChild(nodeToUndelete);
nodeToUndelete.markAsResurrected(true);
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-03-05 16:55:13 UTC (rev 5388)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-03-05 17:19:14 UTC (rev 5389)
@@ -69,7 +69,7 @@
GlobalTransaction gtx = getGlobalTransaction(ctx);
TransactionWorkspace workspace = getTransactionWorkspace(gtx);
Fqn fqn = getFqn(args, m.getMethodId());
- WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, true, true);
+ WorkspaceNode workspaceNode = fetchWorkspaceNode(ctx, fqn, workspace, MethodDeclarations.removeNodeMethodLocal_id != m.getMethodId(), true);
// in the case of a data gravitation cleanup, if the primary Fqn does not exist the backup one may.
if (workspaceNode == null && m.getMethodId() == MethodDeclarations.dataGravitationCleanupMethod_id)
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-03-05 16:55:13 UTC (rev 5388)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-03-05 17:19:14 UTC (rev 5389)
@@ -628,6 +628,7 @@
if (gtx != null && needToReverseRemove)
{
childNode.markAsDeleted(false);
+ childNode.clearDataDirect();
if (createdNodes != null)
{
createdNodes.add(childNode);
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2008-03-05 16:55:13 UTC (rev 5388)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2008-03-05 17:19:14 UTC (rev 5389)
@@ -111,7 +111,20 @@
tm.commit();
}
+ public void testOverwritingDataTx() throws Exception
+ {
+ Node<Object, Object> nodeA = rootNode.addChild(A);
+ nodeA.put("key", "value");
+ assertEquals("value", nodeA.get("key"));
+ tm.begin();
+ rootNode.removeChild(A);
+ cache.put(A, "k2", "v2");
+ tm.commit();
+ assertNull(nodeA.get("key"));
+ assertEquals("v2", nodeA.get("k2"));
+ }
+
/**
* Remember, Fqns are relative!!
*/
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java 2008-03-05 16:55:13 UTC (rev 5388)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java 2008-03-05 17:19:14 UTC (rev 5389)
@@ -15,10 +15,8 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.NodeLock;
-import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -45,7 +43,7 @@
@Test(groups = {"functional", "transaction"})
public class TransactionTest
{
- CacheSPI cache = null;
+ CacheSPI<String, Comparable> cache = null;
UserTransaction tx = null;
Exception thread_ex;
@@ -53,8 +51,8 @@
public void setUp() throws Exception
{
- CacheFactory<String, Comparable> instance = new DefaultCacheFactory();
- cache = (CacheSPI) instance.createCache(false);
+ CacheFactory<String, Comparable> instance = new DefaultCacheFactory<String, Comparable>();
+ cache = (CacheSPI<String, Comparable>) instance.createCache(false);
cache.getConfiguration().setClusterName("test");
cache.getConfiguration().setStateRetrievalTimeout(10000);
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -616,12 +614,6 @@
assertEquals(0, cache.getNumberOfLocksHeld());
}
- private Map getLockTable(CacheSPI c)
- {
- ComponentRegistry cr = TestingUtil.extractComponentRegistry(c);
- return cr.getComponent("LockTable", Map.class);
- }
-
public void testRemove() throws CacheException, SystemException, NotSupportedException, HeuristicMixedException, HeuristicRollbackException, RollbackException
{
cache.put("/a/b/c", null);
16 years, 10 months
JBoss Cache SVN: r5388 - in core/trunk/src/main/java/org/jboss/cache: interceptors and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-05 11:55:13 -0500 (Wed, 05 Mar 2008)
New Revision: 5388
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNode.java
core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
Log:
JBCACHE-1296 - Deleting and reading parent node in tx causes deleted children to survive
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-03-05 16:54:24 UTC (rev 5387)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-03-05 16:55:13 UTC (rev 5388)
@@ -1291,7 +1291,7 @@
else
{
found = n.isValid() && !n.isDeleted();
- n.markAsDeleted(true);
+ n.markAsDeleted(true, true);
}
if (eviction && parent_node != null)
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-03-05 16:54:24 UTC (rev 5387)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-03-05 16:55:13 UTC (rev 5388)
@@ -195,12 +195,7 @@
{
// exists in workspace and has just been created.
currentNode = peekInWorkspace.getNode();
- if (peekInWorkspace.isDeleted())
- {
- peekInWorkspace.markAsDeleted(false);
- // add in parent again
- workspaceNode.addChild(peekInWorkspace);
- }
+ if (peekInWorkspace.isDeleted()) undeleteWorkspaceNode(peekInWorkspace, workspaceNode);
}
}
@@ -249,7 +244,7 @@
// node does exist but might not be in the workspace
workspaceNode = workspace.getNode(currentNode.getFqn());
// wrap it up so we can put it in later if we need to
- if (workspaceNode == null || workspaceNode.isDeleted())
+ if (workspaceNode == null)
{
if (trace)
log.trace("Child node " + currentNode.getFqn() + " doesn't exist in workspace or has been deleted. Adding to workspace in gtx " + gtx);
@@ -272,6 +267,11 @@
log.trace("setting versioning of " + workspaceNode.getFqn() + " to be " + (workspaceNode.isVersioningImplicit() ? "implicit" : "explicit"));
workspace.addNode(workspaceNode);
}
+ else if (workspaceNode.isDeleted())
+ {
+ if (trace) log.trace("Found node but it is deleted in this workspace. Needs resurrecting.");
+ undeleteWorkspaceNode(workspaceNode, workspace);
+ }
else
{
if (trace) log.trace("Found child node in the workspace: " + currentNode);
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-03-05 16:54:24 UTC (rev 5387)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-03-05 16:55:13 UTC (rev 5388)
@@ -12,6 +12,7 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.optimistic.TransactionWorkspace;
+import org.jboss.cache.optimistic.WorkspaceNode;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
@@ -82,5 +83,23 @@
return gtx;
}
+ protected void undeleteWorkspaceNode(WorkspaceNode nodeToUndelete, TransactionWorkspace workspace)
+ {
+ undeleteWorkspaceNode(nodeToUndelete, workspace.getNode(nodeToUndelete.getFqn().getParent()));
+ }
+ /**
+ * Undeletes a node that already exists in the workspace, by setting appropriate flags and re-adding to parent's child map.
+ *
+ * @param nodeToUndelete WorkspaceNode to undelete
+ */
+ protected void undeleteWorkspaceNode(WorkspaceNode nodeToUndelete, WorkspaceNode parent)
+ {
+ nodeToUndelete.markAsDeleted(false);
+ // add in parent again
+ parent.addChild(nodeToUndelete);
+ nodeToUndelete.markAsResurrected(true);
+ }
+
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-03-05 16:54:24 UTC (rev 5387)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-03-05 16:55:13 UTC (rev 5388)
@@ -335,9 +335,8 @@
// pre-notify
if (notify) notifier.notifyNodeRemoved(workspaceNode.getFqn(), true, workspaceNode.getData(), ctx);
- parentNode.removeChild(workspaceNode.getFqn().getLastElement());
-
Fqn nodeFqn = workspaceNode.getFqn();
+ parentNode.removeChild(nodeFqn.getLastElement());
SortedMap<Fqn, WorkspaceNode> tailMap = workspace.getNodesAfter(workspaceNode.getFqn());
@@ -544,10 +543,7 @@
if (trace) log.trace("Node " + fqn + " has been deleted in the workspace.");
if (undeleteIfNecessary)
{
- workspaceNode.markAsDeleted(false);
- // re-add to parent
- WorkspaceNode parent = fetchWorkspaceNode(ctx, fqn.getParent(), workspace, true, includeInvalidNodes);
- parent.addChild(workspaceNode);
+ undeleteWorkspaceNode(workspaceNode, fetchWorkspaceNode(ctx, fqn.getParent(), workspace, true, includeInvalidNodes));
}
else
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2008-03-05 16:54:24 UTC (rev 5387)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2008-03-05 16:55:13 UTC (rev 5388)
@@ -192,17 +192,34 @@
else
{
boolean updateVersion = false;
- if (workspaceNode.isChildrenModified())
+ if (workspaceNode.isChildrenModified() || workspaceNode.isResurrected()) // if it is newly created make sure we remove all underlying children that may exist, to solve a remove-and-create-in-tx condition
{
if (trace) log.trace("Updating children since node has modified children");
// merge children.
List<Set<Fqn>> deltas = workspaceNode.getMergedChildren();
if (trace) log.trace("Applying children deltas to parent node " + underlyingNode.getFqn());
+
+ if (workspaceNode.isResurrected())
+ {
+ // mark it as invalid so any direct references are marked as such
+ Map childNode = underlyingNode.getChildrenMapDirect();
+ if (childNode != null)
+ {
+ for (Object o : childNode.values())
+ {
+ NodeSPI cn = (NodeSPI) o;
+ cn.setValid(false, true);
+ if (!useTombstones) underlyingNode.removeChildDirect(cn.getFqn().getLastElement());
+ }
+ }
+ }
+
for (Fqn child : deltas.get(0))
{
-// underlyingNode.addChildDirect(workspaceNode.getChild(child.getLastElement()));
- underlyingNode.addChildDirect(workspace.getNode(child).getNode());
+ NodeSPI childNode = workspace.getNode(child).getNode();
+ underlyingNode.addChildDirect(childNode);
+ childNode.setValid(true, false);
}
for (Fqn child : deltas.get(1))
@@ -211,14 +228,11 @@
NodeSPI childNode = underlyingNode.getChildDirect(child.getLastElement());
if (childNode != null) childNode.setValid(false, true);
- if (!useTombstones)
- {
- // don't retain the tombstone
- underlyingNode.removeChildDirect(child.getLastElement());
- }
+ if (!useTombstones) underlyingNode.removeChildDirect(child.getLastElement());
}
updateVersion = underlyingNode.isLockForChildInsertRemove();
+
// do we need to notify listeners of a modification?? If all we've done is added children then don't
// notify.
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-03-05 16:54:24 UTC (rev 5387)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-03-05 16:55:13 UTC (rev 5388)
@@ -274,9 +274,10 @@
// we need to mark new nodes created as deleted since they are only created to form a path to the node being removed, to
// create a lock.
boolean created = acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.WRITE, true, false, true, true, createdNodes, true);
+ TransactionEntry entry = null;
if (ctx.getGlobalTransaction() != null)
{
- TransactionEntry entry = tx_table.get(ctx.getGlobalTransaction());
+ entry = tx_table.get(ctx.getGlobalTransaction());
entry.addRemovedNode(fqn);
for (NodeSPI nodeSPI : createdNodes)
{
@@ -284,10 +285,11 @@
nodeSPI.markAsDeleted(true);
}
}
- acquireLocksOnChildren(peekNode(ctx, fqn, false, false, false), NodeLock.LockType.WRITE, ctx);
+ acquireLocksOnChildren(peekNode(ctx, fqn, false, false, false), NodeLock.LockType.WRITE, ctx, entry, true);
+
if (!createdNodes.isEmpty())
{
- if (trace) log.trace("There were new nodes created, skiping notification on delete");
+ if (trace) log.trace("There were new nodes created, skipping notification on delete");
Object[] args = ctx.getMethodCall().getArgs();
if (trace)
log.trace("Changing 'skipNotification' for method '_remove' from " + args[args.length - 1] + " to true");
@@ -530,12 +532,16 @@
return created;
}
+ private void acquireLocksOnChildren(NodeSPI parentNode, NodeLock.LockType lockType, InvocationContext ctx) throws InterruptedException
+ {
+ acquireLocksOnChildren(parentNode, lockType, ctx, null, false);
+ }
/**
* Acquires nodes on the children of this node. nodes on the node itself are not aquired.
* If the supplied parent node is null the method returns(no op).
*/
- private void acquireLocksOnChildren(NodeSPI parentNode, NodeLock.LockType lockType, InvocationContext ctx)
+ private void acquireLocksOnChildren(NodeSPI parentNode, NodeLock.LockType lockType, InvocationContext ctx, TransactionEntry entry, boolean addChildrenToDeletedList)
throws InterruptedException
{
if (parentNode == null)
@@ -552,6 +558,13 @@
if (gtx != null)
{
cache.getTransactionTable().addLocks(gtx, acquiredLocks);
+ if (addChildrenToDeletedList)
+ {
+ for (NodeLock l : acquiredLocks)
+ {
+ entry.addRemovedNode(l.getFqn());
+ }
+ }
}
else
{
Modified: core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNode.java 2008-03-05 16:54:24 UTC (rev 5387)
+++ core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNode.java 2008-03-05 16:55:13 UTC (rev 5388)
@@ -164,7 +164,7 @@
*
* @param workspaceNode
*/
- void addChild(WorkspaceNode<K,V> workspaceNode);
+ void addChild(WorkspaceNode<K, V> workspaceNode);
/**
* @return true if children have been added to or removed from this node. Not the same as 'dirty'.
@@ -172,8 +172,19 @@
boolean isChildrenModified();
/**
- *
* @return true if the child map has been loaded from the underlying data structure into the workspace.
*/
boolean isChildrenLoaded();
+
+ /**
+ * @return teur if this node has been resurrected, i.e., it was deleted and re-added within the same transaction
+ */
+ boolean isResurrected();
+
+ /**
+ * Marks a node as resurrected, i.e., deleted and created again within the same transaction
+ *
+ * @param resurrected
+ */
+ void markAsResurrected(boolean resurrected);
}
Modified: core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java 2008-03-05 16:54:24 UTC (rev 5387)
+++ core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java 2008-03-05 16:55:13 UTC (rev 5388)
@@ -48,7 +48,18 @@
private Set<Fqn> childrenRemoved;// = new HashSet<Fqn>();
private Map<K, V> optimisticDataMap;
private boolean versioningImplicit = true; // default
+ private boolean resurrected = false;
+ // the following boolean attributes are encoded as bits in a byte:
+ // modified: attr & 1 (2 ^ 0)
+ // created: attr & 2 (2 ^ 1)
+ // childrenModified: attr & 4 (2 ^ 2)
+ // versioningImplicit: attr & 8 (2 ^ 3)
+ // resurrected: attr & 16 (2 ^ 4)
+
+ // versioningImplicit is enabled by default.
+ //private byte attr = 8;
+
/**
* Constructs with a node and workspace.
*/
@@ -92,6 +103,27 @@
return optimisticChildNodeMap != null;
}
+ public boolean isResurrected()
+ {
+ return resurrected;
+ }
+
+ public void markAsResurrected(boolean resurrected)
+ {
+ this.resurrected = resurrected;
+ }
+
+ @Override
+ public void markAsDeleted(boolean marker, boolean recursive)
+ {
+ super.markAsDeleted(marker, recursive);
+ if (marker)
+ {
+ if (childrenAdded != null) childrenAdded.clear();
+ if (childrenRemoved != null) childrenRemoved.clear();
+ }
+ }
+
/**
* Returns true if this node is modified.
*/
16 years, 10 months
JBoss Cache SVN: r5387 - core/trunk/src/test/java/org/jboss/cache/api.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-05 11:54:24 -0500 (Wed, 05 Mar 2008)
New Revision: 5387
Modified:
core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java
core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
Log:
Cleaned up tests
Modified: core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java 2008-03-05 12:36:31 UTC (rev 5386)
+++ core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java 2008-03-05 16:54:24 UTC (rev 5387)
@@ -1,25 +1,23 @@
package org.jboss.cache.api;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.TransactionManager;
+
/**
* Tests whether, in a single tx, deleting a parent node with an pre-existing
* child and then re-adding a node with the parent Fqn results
- * in the pre-existing child remaining in the cache after tx commit.
+ * in the pre-existing child remaining in the cache after tx commit.
*
* @author Brian Stansberry
* @since 2.1.0
@@ -28,57 +26,64 @@
public class DeletedChildResurrectionTest
{
private Cache<Object, Object> cache;
+ private static final Fqn<String> A_B = Fqn.fromString("/a/b");
+ private static final Fqn<String> A = Fqn.fromString("/a");
+ private static final Fqn<String> A_C = Fqn.fromString("/a/c");
+ private static final String KEY = "key";
+ private static final String VALUE = "value";
+ private static final String K2 = "k2";
+ private static final String V2 = "v2";
@BeforeMethod(alwaysRun = true)
public void setUp()
- {
+ {
+ cache = new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true), false);
+ cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- cache.stop();
- cache.destroy();
- cache = null;
+ TestingUtil.killCaches(cache);
}
-
+
/**
* Tests whether the deleted child re-appears if the parent node is re-added
* via a simple node.addChild(parentFqn) call. Pessimistic locking case.
- *
+ *
* @throws Exception
*/
public void testDeletedChildResurrectionPessimistic1() throws Exception
{
deletedChildResurrectionTest1(false);
}
-
+
/**
* Tests whether the deleted child re-appears if the parent node is re-added
* via a simple node.addChild(parentFqn) call. Optimistic locking case.
- *
+ *
* @throws Exception
*/
public void testDeletedChildResurrectionOptimistic1() throws Exception
{
deletedChildResurrectionTest1(true);
}
-
+
/**
* Tests whether the deleted child re-appears if the parent node is re-added
* via a node.addChild(differentChildofParentFqn) call. Pessimistic locking case.
- *
+ *
* @throws Exception
*/
public void testDeletedChildResurrectionPessimistic2() throws Exception
{
deletedChildResurrectionTest2(false);
}
-
+
/**
* Tests whether the deleted child re-appears if the parent node is re-added
* via a node.addChild(differentChildofParentFqn) call. Optimistic locking case.
- *
+ *
* @throws Exception
*/
public void testDeletedChildResurrectionOptimistic2() throws Exception
@@ -89,51 +94,50 @@
/**
* Tests whether, in a single tx, deleting a parent node with an pre-existing
* child and then inserting a different child under the parent Fqn results
- * in the pre-existing child remaining in the cache after tx commit.
+ * in the pre-existing child remaining in the cache after tx commit.
*/
private void deletedChildResurrectionTest1(boolean optimistic) throws Exception
{
+ cache.getConfiguration().setNodeLockingOptimistic(optimistic);
+ cache.start();
+ CacheSPI spi = (CacheSPI) cache;
+ Node<Object, Object> root = cache.getRoot();
- Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
- config.setCacheMode(Configuration.CacheMode.LOCAL);
- config.setNodeLockingOptimistic(optimistic);
- cache = (Cache<Object, Object>) new DefaultCacheFactory().createCache(config, true);
+ TransactionManager txManager = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
- TransactionManager txManager = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
-
- cache.getRoot().addChild(Fqn.fromString("/a/b")).put("key", "value");
+ root.addChild(A_B).put(KEY, VALUE);
txManager.begin();
- cache.getRoot().removeChild(Fqn.fromString("/a"));
- cache.getRoot().addChild(Fqn.fromString("/a"));
+ root.removeChild(A);
+ root.addChild(A);
txManager.commit();
- assertNull(cache.getRoot().getChild(Fqn.fromString("/a/b")));
- Node a = cache.getRoot().getChild(Fqn.fromString("/a"));
- assertNotNull(a);
+ assert !root.hasChild(A_B);
+ // do a peek to ensure the node really has been removed and not just marked for removal
+ assert spi.peek(A_B, true, true) == null;
+ assert root.hasChild(A);
}
/**
* Tests whether, in a single tx, deleting a parent node with an pre-existing
* child and then inserting a different child under the parent Fqn results
- * in the pre-existing child remaining in the cache after tx commit.
+ * in the pre-existing child remaining in the cache after tx commit.
*/
private void deletedChildResurrectionTest2(boolean optimistic) throws Exception
{
- Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
- config.setCacheMode(Configuration.CacheMode.LOCAL);
- config.setNodeLockingOptimistic(optimistic);
- cache = (Cache<Object, Object>) new DefaultCacheFactory().createCache(config, true);
+ cache.getConfiguration().setNodeLockingOptimistic(optimistic);
+ cache.start();
+ Node<Object, Object> root = cache.getRoot();
TransactionManager txManager = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
-
- cache.getRoot().addChild(Fqn.fromString("/a/b")).put("key", "value");
-
+
+ root.addChild(A_B).put(KEY, VALUE);
+
txManager.begin();
- cache.getRoot().removeChild(Fqn.fromString("/a"));
- cache.getRoot().addChild(Fqn.fromString("/a/c")).put("k2", "v2");
+ root.removeChild(A);
+ root.addChild(A_C).put(K2, V2);
txManager.commit();
- assertNull(cache.getRoot().getChild(Fqn.fromString("/a/b")));
- Node ac = cache.getRoot().getChild(Fqn.fromString("/a/c"));
- assertNotNull(ac);
- assertEquals("v2", ac.get("k2"));
+
+ assert !root.hasChild(A_B);
+ assert root.hasChild(A_C);
+ assert V2.equals(root.getChild(A_C).get(K2));
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2008-03-05 12:36:31 UTC (rev 5386)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2008-03-05 16:54:24 UTC (rev 5387)
@@ -356,29 +356,20 @@
assertEquals(childrenNames, rootNode.getChildrenNames());
}
- public void testDoubleRemovalOfData()
+ public void testDoubleRemovalOfData() throws Exception
{
- try
- {
- cache.put("/foo/1/2/3", "item", 1);
- tm.begin();
- assertEquals(cache.get("/foo/1/2/3", "item"), 1);
- cache.removeNode("/foo/1");
- assertNull(cache.get("/foo/1", "item"));
- cache.removeNode("/foo/1/2/3");
- assertNull(cache.get("/foo/1/2/3", "item"));
- assertNull(cache.get("/foo/1", "item"));
- tm.commit();
- assertFalse(cache.exists("/foo/1"));
- assertNull(cache.get("/foo/1/2/3", "item"));
- assertNull(cache.get("/foo/1", "item"));
- }
- catch (Throwable t)
- {
- t.printStackTrace();
- fail(t.toString());
- }
-
+ cache.put("/foo/1/2/3", "item", 1);
+ tm.begin();
+ assertEquals(cache.get("/foo/1/2/3", "item"), 1);
+ cache.removeNode("/foo/1");
+ assertNull(cache.get("/foo/1", "item"));
+ cache.removeNode("/foo/1/2/3");
+ assertNull(cache.get("/foo/1/2/3", "item"));
+ assertNull(cache.get("/foo/1", "item"));
+ tm.commit();
+ assertFalse(cache.exists("/foo/1"));
+ assertNull(cache.get("/foo/1/2/3", "item"));
+ assertNull(cache.get("/foo/1", "item"));
}
}
16 years, 10 months
JBoss Cache SVN: r5386 - core/trunk/src/main/java/org/jboss/cache/lock.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-05 07:36:31 -0500 (Wed, 05 Mar 2008)
New Revision: 5386
Modified:
core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
Log:
Added comment on constructor and removed creation of an unmodifiable collection when returning the readOwners collection.
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2008-03-04 20:37:51 UTC (rev 5385)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2008-03-05 12:36:31 UTC (rev 5386)
@@ -8,7 +8,7 @@
import org.jboss.cache.util.concurrent.ConcurrentHashSet;
-import java.util.*;
+import java.util.Collection;
/**
* Provide lock ownership mapping.
@@ -25,7 +25,6 @@
private Object writeOwner_ = null;
-
// This is more efficient (lower CPU utilisation and better concurrency) than a CopyOnWriteArraySet or ConcurrentHashSet.
// for some reason this barfs with concurrent mod exceptions. Need to see why.
private final Collection<Object> readOwners;
@@ -37,6 +36,11 @@
this(new ConcurrentHashSet<Object>());
}
+ /**
+ * This constructor is made available for testing with different collection types for the readOwners collection.
+ *
+ * @param readOwners
+ */
public LockMap(Collection<Object> readOwners)
{
this.readOwners = readOwners;
@@ -128,7 +132,9 @@
*/
public Collection<Object> readerOwners()
{
- return Collections.unmodifiableCollection(readOwners);
+ // not necessary if the collection is a CHS. Saves on overhead.
+// return Collections.unmodifiableCollection(readOwners);
+ return readOwners;
}
public void releaseReaderOwners(LockStrategy lock)
16 years, 10 months
JBoss Cache SVN: r5385 - core/trunk/src/test-perf/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-03-04 15:37:51 -0500 (Tue, 04 Mar 2008)
New Revision: 5385
Added:
core/trunk/src/test-perf/java/org/jboss/cache/LockMapPerformanceTest.java
Log:
test for benchmarking LockMap
Added: core/trunk/src/test-perf/java/org/jboss/cache/LockMapPerformanceTest.java
===================================================================
--- core/trunk/src/test-perf/java/org/jboss/cache/LockMapPerformanceTest.java (rev 0)
+++ core/trunk/src/test-perf/java/org/jboss/cache/LockMapPerformanceTest.java 2008-03-04 20:37:51 UTC (rev 5385)
@@ -0,0 +1,212 @@
+package org.jboss.cache;
+
+import org.jboss.cache.lock.LockMap;
+import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+
+import java.util.*;
+
+import junit.framework.TestCase;
+
+/**
+ * Class that tests LockMap performances on various access patterns and internal implementation of readers array.
+ * Following access patterns on readers array were identified:
+ * <pre>
+ * - add to the end of the collection
+ * - remove(object); in other words random removals
+ * - contains (element)
+ * - (less frequnetly used) obtain the collection of readers and iterate over its
+ * </pre>
+ * todo - add a test to simulate concurrency (30% addition, 30%removals, 30% search and 10% iteration over the elements)
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class LockMapPerformanceTest extends TestCase
+{
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ configs = new Collection[4];
+ configs[0] = new Vector<Object>();
+ configs[1] = Collections.synchronizedList(new ArrayList<Object>());
+ configs[2] = Collections.synchronizedList(new LinkedList<Object>());
+ configs[3] = new ConcurrentHashSet<Object>();
+ }
+
+ Collection<Object>[] configs;
+ int[] readersSize = {10000};
+ int repeatCount = 100;
+
+
+ public void testPlainRead()
+ {
+ for (int size : readersSize)
+ {
+ Object[] objectPool = createObjectPool(size);
+ Object[] shuffledPool = shufflePool(objectPool);
+ for (Collection<Object> col : configs)
+ {
+ LockMap lockMap = new LockMap(col);
+ String benchDescription = "[" + col.getClass().getName() + ", " + size + "]";
+ benchmarkAddition(objectPool, lockMap, benchDescription);
+ benchmarkSearch(lockMap, shuffledPool, benchDescription);
+ benchmarkRemoval(lockMap, shuffledPool, benchDescription);
+ }
+ }
+ }
+
+ private void benchmarkRemoval(LockMap lockMap, Object[] shuffledPool, String benchDescription)
+ {
+ long start = System.currentTimeMillis();
+ for (Object anObjectPool : shuffledPool)
+ {
+ lockMap.removeReader(anObjectPool);
+ }
+ long durration = System.currentTimeMillis() - start;
+ log("removal", durration, benchDescription);
+ }
+
+ private void benchmarkSearch(LockMap lockMap, Object[] shuffledPool, String benchDescription)
+ {
+ long start = System.currentTimeMillis();
+ for (Object anObjectPool : shuffledPool)
+ {
+ lockMap.isOwner(anObjectPool, LockMap.OWNER_READ);
+ }
+ long durration = System.currentTimeMillis() - start;
+ log("search", durration, benchDescription);
+ }
+
+ private void benchmarkAddition(Object[] objectPool, LockMap lockMap, String benchDescription)
+ {
+ long start = System.currentTimeMillis();
+ for (Object anObjectPool : objectPool)
+ {
+ lockMap.addReader(anObjectPool);
+ }
+ long durration = System.currentTimeMillis() - start;
+ log("addition", durration, benchDescription);
+ }
+
+ private void log(String s, long durration, String benchDescription)
+ {
+ System.out.println(benchDescription + " - " + s + " - " + durration + " millis ");
+ }
+
+ private Object[] shufflePool(Object[] objectPool)
+ {
+ List objects = Arrays.asList(objectPool);
+ Collections.shuffle(objects);
+ return objects.toArray();
+ }
+
+ private Object[] createObjectPool(int size)
+ {
+ Object[] result = new Object[size];
+ for (int i = 0; i < size; i++)
+ {
+ result[i] = new Object();
+ }
+ return result;
+ }
+
+ int threadCount = 10;
+ int[] operationPercentage = {30, 60, 90, 100}; //additions, removals, searches, iterations
+ int poolSize = 10;
+ int operationCount = 1000;
+ public void testConcurrnecy() throws InterruptedException
+ {
+ LockMap lm = new LockMap(Collections.synchronizedList(new LinkedList()));
+ Object[] objectPool = createObjectPool(poolSize);
+ Object mutex = new Object();
+ Accessor[] accessors = new Accessor[threadCount];
+ for (int i = 0; i < threadCount; i++)
+ {
+ accessors[i] = new Accessor(lm,objectPool,mutex);
+ accessors[i].start();
+ }
+ Thread.sleep(1000);
+ long start = System.currentTimeMillis();
+ synchronized (mutex)
+ {
+ mutex.notifyAll();
+ }
+ for (int i = 0; i < threadCount; i++)
+ {
+ try
+ {
+ accessors[i].join();
+ } catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ long durration = System.currentTimeMillis() - start;
+ System.out.println("Total durration is: " + durration);
+ }
+
+ class Accessor extends Thread
+ {
+ Random rnd = new Random();
+ LockMap lockMap;
+ Object[] objectPool;
+ Object mtex;
+
+ Accessor( LockMap lockMap, Object[] objectPool, Object mtex)
+ {
+ this.lockMap = lockMap;
+ this.objectPool = objectPool;
+ this.mtex = mtex;
+ }
+
+ int iterations;// just to avoid compiler optimizing the code
+ public void run()
+ {
+ try
+ {
+ synchronized (mtex)
+ {
+ mtex.wait();
+ }
+ } catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ System.out.println("thread started");
+ for (int i =0 ; i < operationCount; i++)
+ {
+ int operation = getOperation();
+ switch (operation) {
+ case 0: lockMap.addReader(objectPool[rnd.nextInt(poolSize)]); break;
+ case 1: lockMap.removeReader(objectPool[rnd.nextInt(poolSize)]); break;
+ case 2: lockMap.isOwner(objectPool[rnd.nextInt(poolSize)], LockMap.OWNER_READ); break;
+ case 3:
+ {
+ for (Object obj: lockMap.readerOwners())
+ {
+ iterations ++;
+ }
+ break;
+ }
+ default:
+ {
+ throw new RuntimeException("Unknown operation :" + operation);
+ }
+ }
+ }
+ }
+
+ private int getOperation()
+ {
+ int val = rnd.nextInt(100);
+ for (int i =0; i < operationPercentage.length; i++)
+ {
+ if (operationPercentage[i] > val)
+ {
+ return i;
+ }
+ }
+ throw new RuntimeException("Did not expect " + val);
+ }
+ }
+}
+
16 years, 10 months
JBoss Cache SVN: r5384 - core/trunk/src/main/java/org/jboss/cache/lock.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-03-04 15:36:26 -0500 (Tue, 04 Mar 2008)
New Revision: 5384
Modified:
core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
Log:
- rolled back to ConcurrentHashSet as benchmark showed that this brings best performance. Also added LockMapPerformanceTest perf test for further testing.
- made the readers collection injectable to facilitate testing
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2008-03-04 11:43:07 UTC (rev 5383)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2008-03-04 20:36:26 UTC (rev 5384)
@@ -6,6 +6,8 @@
*/
package org.jboss.cache.lock;
+import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+
import java.util.*;
/**
@@ -22,11 +24,24 @@
private Object writeOwner_ = null;
+
+
// This is more efficient (lower CPU utilisation and better concurrency) than a CopyOnWriteArraySet or ConcurrentHashSet.
// for some reason this barfs with concurrent mod exceptions. Need to see why.
- private final List<Object> readOwnerList_ = Collections.synchronizedList(new LinkedList<Object>());
-// private final Set<Object> readOwnerList_ = new ConcurrentHashSet<Object>();
+ private final Collection<Object> readOwners;
+// private final Set<Object> readOwners = new ConcurrentHashSet<Object>();
+
+ public LockMap()
+ {
+ this(new ConcurrentHashSet<Object>());
+ }
+
+ public LockMap(Collection<Object> readOwners)
+ {
+ this.readOwners = readOwners;
+ }
+
/**
* Check whether this owner has reader or writer ownership.
*
@@ -45,9 +60,9 @@
switch (ownership)
{
case OWNER_ANY:
- return ((writeOwner_ != null && caller.equals(writeOwner_)) || readOwnerList_.contains(caller));
+ return ((writeOwner_ != null && caller.equals(writeOwner_)) || readOwners.contains(caller));
case OWNER_READ:
- return (readOwnerList_.contains(caller));
+ return (readOwners.contains(caller));
case OWNER_WRITE:
return (writeOwner_ != null && caller.equals(writeOwner_));
default:
@@ -63,7 +78,7 @@
*/
public void addReader(Object owner)
{
- readOwnerList_.add(owner);
+ readOwners.add(owner);
}
/**
@@ -101,7 +116,7 @@
*/
public boolean upgrade(Object owner) throws OwnerNotExistedException
{
- boolean old_value = readOwnerList_.remove(owner);
+ boolean old_value = readOwners.remove(owner);
if (!old_value) // didn't exist in the list
throw new OwnerNotExistedException("Can't upgrade lock. Read lock owner did not exist");
setWriter(owner);
@@ -113,21 +128,12 @@
*/
public Collection<Object> readerOwners()
{
- //make a defense copy, otherwise ConcurrentModificationException might appear while client code is iterating
- // the original map (see IdentityLockTest.testConcurrentModificationOfReadLocksAndToString)
- List readOwnersListCopy;
- synchronized (readOwnerList_) //readOwnerList_ is a sync list, make sure noone modifies it while we make a copy of it.
- {
- readOwnersListCopy = new ArrayList(readOwnerList_);
- readOwnersListCopy.addAll(readOwnerList_);
- }
- return Collections.unmodifiableList(readOwnersListCopy);
-// return readOwnerList_;
+ return Collections.unmodifiableCollection(readOwners);
}
public void releaseReaderOwners(LockStrategy lock)
{
- int size = readOwnerList_.size();
+ int size = readOwners.size();
for (int i = 0; i < size; i++)
lock.readLock().unlock();
}
@@ -145,7 +151,7 @@
*/
public void removeReader(Object owner)
{
- readOwnerList_.remove(owner);
+ readOwners.remove(owner);
}
/**
@@ -165,7 +171,7 @@
public void removeAll()
{
removeWriter();
- readOwnerList_.clear();
+ readOwners.clear();
}
/**
@@ -176,13 +182,13 @@
public String printInfo()
{
StringBuffer buf = new StringBuffer(64);
- buf.append("Read lock owners: ").append(readOwnerList_).append('\n');
+ buf.append("Read lock owners: ").append(readOwners).append('\n');
buf.append("Write lock owner: ").append(writeOwner_).append('\n');
return buf.toString();
}
public boolean isReadLocked()
{
- return !readOwnerList_.isEmpty();
+ return !readOwners.isEmpty();
}
}
16 years, 10 months
JBoss Cache SVN: r5383 - in core/trunk/src/test/java/org/jboss/cache: api and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-04 06:43:07 -0500 (Tue, 04 Mar 2008)
New Revision: 5383
Modified:
core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java
core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
core/trunk/src/test/java/org/jboss/cache/lock/NonBlockingWriterLockTest.java
core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java
core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
Log:
Reinstated disabled tests
Modified: core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java 2008-03-04 10:32:35 UTC (rev 5382)
+++ core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java 2008-03-04 11:43:07 UTC (rev 5383)
@@ -282,8 +282,6 @@
}
}
- @Test(enabled = false)
- // TODO: needs investigation ... !
public void testRemoteInvalidStateInvocations2() throws Exception
{
createAndRegisterCache(Configuration.CacheMode.REPL_SYNC, true);
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java 2008-03-04 10:32:35 UTC (rev 5382)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java 2008-03-04 11:43:07 UTC (rev 5383)
@@ -461,9 +461,6 @@
@Test(groups = {"functional"})
public void testConcurrency() throws InterruptedException
{
- // TODO: investigate intermittent failure when in optimistic mode.
- if (optimistic) return;
-
final int N = 3;// number of threads
final int loops = 1 << 6;// number of loops
// tests a tree structure as such:
Modified: core/trunk/src/test/java/org/jboss/cache/lock/NonBlockingWriterLockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/NonBlockingWriterLockTest.java 2008-03-04 10:32:35 UTC (rev 5382)
+++ core/trunk/src/test/java/org/jboss/cache/lock/NonBlockingWriterLockTest.java 2008-03-04 11:43:07 UTC (rev 5383)
@@ -26,8 +26,7 @@
* @author <a href="mailto:cavin_song@yahoo.com">Cavin Song</a> April 22, 2004
* @version 1.0
*/
-@Test(groups = {"functional"}, invocationCount = 30, enabled = false)
-// todo: look into intermittent failures in this test; probably due to LockMap changes.
+@Test(groups = {"functional"}, invocationCount = 30)
public class NonBlockingWriterLockTest
{
static final NonBlockingWriterLock lock_ = new NonBlockingWriterLock();
Modified: core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java 2008-03-04 10:32:35 UTC (rev 5382)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java 2008-03-04 11:43:07 UTC (rev 5383)
@@ -630,8 +630,7 @@
assertEquals(expected, eventLog2.events);
}
- @Test(enabled = false)
- // TODO: Enable and fix after CR4. This needs to be addressed!! Why is the state transfer process doing a get() on an internal node?1??
+ @Test(enabled = true)
public void testStateTransfer() throws Exception
{
// first stop cache2
Modified: core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java 2008-03-04 10:32:35 UTC (rev 5382)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java 2008-03-04 11:43:07 UTC (rev 5383)
@@ -8,12 +8,6 @@
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
-/**
- * // TODO Document this
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 2.1.0
- */
@Test(groups = "profiling")
public abstract class AbstractProfileTest
{
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java 2008-03-04 10:32:35 UTC (rev 5382)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java 2008-03-04 11:43:07 UTC (rev 5383)
@@ -31,7 +31,6 @@
* Abstract superclass of "StateTransferVersion"-specific tests
* of CacheSPI's state transfer capability.
* <p/>
- * TODO add tests with classloader regions
*
* @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
* @version $Id$
@@ -52,8 +51,7 @@
*
* @throws Exception
*/
- @Test(invocationCount = 25, enabled = false)
- // TODO: Fix this before 2.1.0.GA !! - Manik
+ @Test(invocationCount = 25, enabled = true)
public void testConcurrentActivationSync() throws Exception
{
concurrentActivationTest(true);
@@ -66,8 +64,7 @@
*
* @throws Exception
*/
- @Test(invocationCount = 25, enabled = false)
- // TODO: Fix this before 2.1.0.GA !! - Manik
+ @Test(invocationCount = 25, enabled = true)
public void testConcurrentActivationAsync() throws Exception
{
concurrentActivationTest(false);
@@ -286,8 +283,7 @@
* Failure condition is if any node sees an exception or if the final state
* of all caches is not consistent.
*/
- @Test(invocationCount = 25, enabled = false)
- // TODO: Fix this before 2.1.0.GA !! - Manik
+ @Test(invocationCount = 25, enabled = true)
public void testConcurrentStartupActivationAsync() throws Exception
{
concurrentActivationTest2(false);
@@ -308,8 +304,7 @@
* Failure condition is if any node sees an exception or if the final state
* of all caches is not consistent.
*/
- @Test(invocationCount = 25, enabled = false)
- // TODO: Fix this before 2.1.0.GA !! - Manik
+ @Test(invocationCount = 25, enabled = true)
public void testConcurrentStartupActivationSync() throws Exception
{
concurrentActivationTest2(true);
16 years, 10 months
JBoss Cache SVN: r5382 - core/trunk.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-03-04 05:32:35 -0500 (Tue, 04 Mar 2008)
New Revision: 5382
Modified:
core/trunk/pom.xml
Log:
UPgraded to JGroups 2.6.2
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2008-02-29 21:28:02 UTC (rev 5381)
+++ core/trunk/pom.xml 2008-03-04 10:32:35 UTC (rev 5382)
@@ -21,7 +21,7 @@
<dependency>
<groupId>jgroups</groupId>
<artifactId>jgroups</artifactId>
- <version>2.6.1</version>
+ <version>2.6.2</version>
</dependency>
<dependency>
@@ -128,30 +128,30 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
- <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
- <mainClass>org.jboss.cache.Version</mainClass>
- </manifest>
- </archive>
- </configuration>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ <mainClass>org.jboss.cache.Version</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
<executions>
- <execution>
- <id>build-test-jar</id>
- <goals>
- <goal>test-jar</goal>
- </goals>
- <configuration>
- <archive>
- <manifest>
- <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
- <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
- </manifest>
- </archive>
- </configuration>
- </execution>
+ <execution>
+ <id>build-test-jar</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ </archive>
+ </configuration>
+ </execution>
</executions>
</plugin>
<!-- the docbook generation plugin for the user guide -->
@@ -309,43 +309,43 @@
</repositories>
<profiles>
- <profile>
- <id>JBossAS</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
- <properties>
- <jbosscache-core-version>2.1.0.CR3-JBossAS</jbosscache-core-version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>jgroups</groupId>
- <artifactId>jgroups</artifactId>
- <version>2.6.1</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.javaee</groupId>
- <artifactId>jboss-javaee</artifactId>
- <version>5.0.0.Beta3Update1</version>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- <version>2.2.3.GA</version>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1.0.jboss</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.transaction</groupId>
- <artifactId>jboss-jta</artifactId>
- <version>4.3.0.BETA2</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </profile>
- </profiles>
+ <profile>
+ <id>JBossAS</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <properties>
+ <jbosscache-core-version>2.1.0.CR3-JBossAS</jbosscache-core-version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>jgroups</groupId>
+ <artifactId>jgroups</artifactId>
+ <version>2.6.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.javaee</groupId>
+ <artifactId>jboss-javaee</artifactId>
+ <version>5.0.0.Beta3Update1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ <version>2.2.3.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.0.jboss</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.transaction</groupId>
+ <artifactId>jboss-jta</artifactId>
+ <version>4.3.0.BETA2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
</project>
16 years, 10 months