[jbosscache-commits] JBoss Cache SVN: r7730 - in core/trunk/src: test/java/org/jboss/cache/api/mvcc and 1 other directory.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Thu Feb 19 07:53:46 EST 2009
Author: manik.surtani at jboss.com
Date: 2009-02-19 07:53:45 -0500 (Thu, 19 Feb 2009)
New Revision: 7730
Added:
core/trunk/src/test/java/org/jboss/cache/api/mvcc/GetChildrenNamesAfterRemoveTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
Log:
JBCACHE-1480 - getChildrenNames retrieves removed children in a transaction
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2009-02-19 12:48:29 UTC (rev 7729)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2009-02-19 12:53:45 UTC (rev 7730)
@@ -67,6 +67,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Iterator;
/**
* The delegate that users (and ChainedInterceptor authors) interact with when they create a cache by using a cache factory.
@@ -627,6 +628,17 @@
cacheStatusCheck(ctx);
GetChildrenNamesCommand command = commandsFactory.buildGetChildrenNamesCommand(fqn);
Set<Object> retval = (Set<Object>) invoker.invoke(ctx, command);
+
+ // this is needed to work around JBCACHE-1480
+ if (retval != null && !retval.isEmpty())
+ {
+ for (Iterator i = retval.iterator(); i.hasNext();)
+ {
+ Object child = getNode(Fqn.fromRelativeElements(fqn, i.next()));
+ if (child == null) i.remove();
+ }
+ }
+
if (retval != null)
{
retval = Immutables.immutableSetWrap(retval); // this is already copied in the command
@@ -635,6 +647,7 @@
{
retval = Collections.emptySet();
}
+
return retval;
}
Added: core/trunk/src/test/java/org/jboss/cache/api/mvcc/GetChildrenNamesAfterRemoveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/GetChildrenNamesAfterRemoveTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/GetChildrenNamesAfterRemoveTest.java 2009-02-19 12:53:45 UTC (rev 7730)
@@ -0,0 +1,59 @@
+package org.jboss.cache.api.mvcc;
+
+import org.jboss.cache.AbstractSingleCacheTest;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.UnitTestCacheFactory;
+import org.testng.annotations.Test;
+
+import javax.transaction.TransactionManager;
+import java.util.Collections;
+import java.util.Set;
+
+ at Test(groups = {"functional", "mvcc"}, sequential = true, testName = "api.mvcc.GetChildrenNamesAfterRemoveTest")
+public class GetChildrenNamesAfterRemoveTest extends AbstractSingleCacheTest
+{
+ private CacheSPI<String, String> cache;
+
+ public CacheSPI createCache()
+ {
+ // start a single cache instance
+ UnitTestCacheFactory<String, String> cf = new UnitTestCacheFactory<String, String>();
+ cache = (CacheSPI<String, String>) cf.createCache("configs/local-tx.xml", false, getClass());
+ cache.getConfiguration().setEvictionConfig(null);
+ cache.start();
+ return cache;
+ }
+
+ public void testRemove() throws Exception
+ {
+ TransactionManager tm = cache.getTransactionManager();
+ Fqn<String> testFqn = Fqn.fromElements("test1");
+
+ tm.begin();
+ assertEmpty(testFqn);
+ cache.put(testFqn, "x", "x");
+ assertNotEmpty(testFqn);
+ cache.removeNode(testFqn);
+ assertEmpty(testFqn);
+ tm.commit();
+ assertEmpty(testFqn);
+ }
+
+ private void assertNotEmpty(Fqn<String> testFqn)
+ {
+ Set<Node<String, String>> children = cache.getNode(testFqn.getParent()).getChildren();
+ assert !children.isEmpty() : "Node " + testFqn + " should not be a leaf, but getChildren() returns: " + children;
+ Set<Object> childrenNames = cache.getNode(testFqn.getParent()).getChildrenNames();
+ assert childrenNames.equals(Collections.singleton(testFqn.getLastElement())) : "Retrieving children names on " + testFqn + " should return test1 but is: " + childrenNames;
+ }
+
+ private void assertEmpty(Fqn<String> testFqn)
+ {
+ Set<Node<String, String>> children = cache.getNode(testFqn.getParent()).getChildren();
+ assert children.isEmpty() : "Children should be empty but is " + children;
+ Set<Object> childrenNames = cache.getNode(testFqn.getParent()).getChildrenNames();
+ assert childrenNames.isEmpty() : "Children names should be empty but is " + childrenNames;
+ }
+}
More information about the jbosscache-commits
mailing list