JBoss Cache SVN: r4636 - core/trunk/src/test/java/org/jboss/cache/invalidation.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-10-17 12:32:01 -0400 (Wed, 17 Oct 2007)
New Revision: 4636
Modified:
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
Log:
[JBCACHE-1200] Modify test to show the issue
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-10-17 16:08:52 UTC (rev 4635)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-10-17 16:32:01 UTC (rev 4636)
@@ -412,11 +412,11 @@
// this fqn is relative, but since it is from the root it may as well be absolute
Fqn<String> fqn = Fqn.fromString("/test/fqn");
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- root1.addChild(fqn);
- assertTrue(root1.hasChild(fqn));
+ cache1.put(fqn, "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- root2.addChild(fqn);
- assertTrue(root2.hasChild(fqn));
+ cache2.put(fqn, "key", "value");
+ assertEquals("value", cache2.get(fqn, "key"));
assertEquals(true, cache1.removeNode(fqn));
assertFalse(root1.hasChild(fqn));
@@ -426,11 +426,11 @@
Fqn<String> child = Fqn.fromString("/test/fqn/child");
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- root1.addChild(child);
- assertTrue(root1.hasChild(child));
+ cache1.put(child, "key", "value");
+ assertEquals("value", cache1.get(child, "key"));
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- root2.addChild(child);
- assertTrue(root2.hasChild(child));
+ cache2.put(child, "key", "value");
+ assertEquals("value", cache2.get(child, "key"));
assertEquals(true, cache1.removeNode(fqn));
assertFalse(root1.hasChild(fqn));
17 years
JBoss Cache SVN: r4634 - core/trunk/src/test/java/org/jboss/cache/invalidation.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-10-17 12:00:26 -0400 (Wed, 17 Oct 2007)
New Revision: 4634
Modified:
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
Log:
Add test that recreating removed node works properly
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-10-17 15:56:21 UTC (rev 4633)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-10-17 16:00:26 UTC (rev 4634)
@@ -468,6 +468,78 @@
checkRemoteNodeIsRemoved(child);
}
}
+
+ public void testPessimisticNodeResurrection() throws Exception {
+ nodeResurrectionTest(false);
+ }
+
+ public void testOptimisticNodeResurrection() throws Exception {
+ nodeResurrectionTest(true);
+ }
+
+ private void nodeResurrectionTest(boolean optimistic) throws Exception
+ {
+ CacheImpl<Object, Object> cache1 = null;
+ CacheImpl<Object, Object> cache2 = null;
+ try
+ {
+ cache1 = createCache(optimistic);
+ cache2 = createCache(optimistic);
+
+ // this fqn is relative, but since it is from the root it may as well be absolute
+ Fqn<String> fqn = Fqn.fromString("/test/fqn1");
+ cache1.put(fqn, "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+ // Change the value in order to increment the version if Optimistic is used
+ cache1.put(fqn, "key", "newValue");
+ assertEquals("newValue", cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertEquals(null, cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+
+ // Restore locally
+ cache1.put(fqn, "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+
+ // Repeat, but now restore the node on the remote cache
+ fqn = Fqn.fromString("/test/fqn2");
+ cache1.put(fqn, "key", "value");
+ assertEquals("value", cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+ // Change the value in order to increment the version if Optimistic is used
+ cache1.put(fqn, "key", "newValue");
+ assertEquals("newValue", cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertEquals(null, cache1.get(fqn, "key"));
+ assertEquals(null, cache2.get(fqn, "key"));
+
+ // Restore on remote cache
+ cache2.put(fqn, "key", "value");
+ assertEquals("value", cache2.get(fqn, "key"));
+ assertEquals(null, cache1.get(fqn, "key"));
+ }
+ finally
+ {
+ if (cache1 != null)
+ {
+ cache1.stop();
+ cache1.destroy();
+ }
+ if (cache2 != null)
+ {
+ cache2.stop();
+ cache2.destroy();
+ }
+
+ }
+
+ }
private void dumpVersionInfo(CacheSPI c1, CacheSPI c2, Fqn fqn)
{
17 years
JBoss Cache SVN: r4633 - in core/trunk/src: main/java/org/jboss/cache/interceptors and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-10-17 11:56:21 -0400 (Wed, 17 Oct 2007)
New Revision: 4633
Added:
core/trunk/src/test/java/org/jboss/cache/optimistic/ChildMapLazyLoadingTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.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/optimistic/WorkspaceNode.java
core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java
Log:
JBCACHE-1121 : Avoid copying child maps into transaction workspace to improve scalability
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-10-17 15:25:57 UTC (rev 4632)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-10-17 15:56:21 UTC (rev 4633)
@@ -417,8 +417,7 @@
public Set<Object> getChildrenNamesDirect()
{
- return children == null ? Collections.<Object>emptySet() : new HashSet<Object>(children.keySet());
- //return childrenNames();
+ return children == null ? Collections.emptySet() : new HashSet<Object>(children.keySet());
}
public Set<K> getKeys()
@@ -499,7 +498,7 @@
public boolean removeChild(Object childName)
{
- return removeChild(new Fqn(getFqn(), childName));
+ return cache.removeNode(new Fqn(getFqn(), childName));
}
public boolean removeChildDirect(Object childName)
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2007-10-17 15:25:57 UTC (rev 4632)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2007-10-17 15:56:21 UTC (rev 4633)
@@ -10,6 +10,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
import org.jboss.cache.NodeFactory;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.marshall.MethodCall;
@@ -151,7 +152,7 @@
// try and get the child of current node
if (debug) log.debug("Attempting to get child " + childName);
- NodeSPI currentNode = workspaceNode.getChild(childName);
+ NodeSPI currentNode = workspaceNode.getNode().getChildDirect(childName);
if (currentNode == null)
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2007-10-17 15:25:57 UTC (rev 4632)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2007-10-17 15:56:21 UTC (rev 4633)
@@ -150,6 +150,9 @@
case MethodDeclarations.getKeysMethodLocal_id:
result = getKeysAndNotify(args, getTransactionWorkspace(getGlobalTransaction(ctx)), ctx);
break;
+ case MethodDeclarations.getDataMapMethodLocal_id:
+ result = getDataAndNotify(args, getTransactionWorkspace(getGlobalTransaction(ctx)), ctx);
+ break;
case MethodDeclarations.getChildrenNamesMethodLocal_id:
result = getChildNamesAndNotify(args, getTransactionWorkspace(getGlobalTransaction(ctx)), ctx);
break;
@@ -416,6 +419,11 @@
if (trace) log.trace("Unable to find node " + fqn + " in workspace.");
return null;
}
+ else if (workspaceNode.isDeleted())
+ {
+ if (trace) log.trace("Attempted to retrieve node " + fqn + " but it has been deleted!");
+ return null;
+ }
else
{
notifier.notifyNodeVisited(fqn, true, ctx);
@@ -446,6 +454,27 @@
}
}
+ private Object getDataAndNotify(Object[] args, TransactionWorkspace workspace, InvocationContext ctx)
+ {
+ Fqn fqn = (Fqn) args[0];
+
+ WorkspaceNode workspaceNode = fetchWorkspaceNode(fqn, workspace, false);
+
+ if (workspaceNode == null)
+ {
+ if (trace) log.trace("unable to find node " + fqn + " in workspace.");
+ return null;
+ }
+ else
+ {
+ notifier.notifyNodeVisited(fqn, true, ctx);
+ Object data = workspaceNode.getData();
+ workspace.addNode(workspaceNode);
+ notifier.notifyNodeVisited(fqn, false, ctx);
+ return data;
+ }
+ }
+
private Object getChildNamesAndNotify(Object[] args, TransactionWorkspace workspace, InvocationContext ctx)
{
Fqn fqn = (Fqn) args[0];
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2007-10-17 15:25:57 UTC (rev 4632)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2007-10-17 15:56:21 UTC (rev 4633)
@@ -191,7 +191,8 @@
if (trace) log.trace("Applying children deltas to parent node " + underlyingNode.getFqn());
for (Fqn child : deltas.get(0))
{
- underlyingNode.addChildDirect(workspaceNode.getChild(child.getLastElement()));
+// underlyingNode.addChildDirect(workspaceNode.getChild(child.getLastElement()));
+ underlyingNode.addChildDirect(workspace.getNode(child).getNode());
}
for (Fqn child : deltas.get(1))
Modified: core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNode.java 2007-10-17 15:25:57 UTC (rev 4632)
+++ core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNode.java 2007-10-17 15:56:21 UTC (rev 4633)
@@ -170,4 +170,10 @@
* @return true if children have been added to or removed from this node. Not the same as 'dirty'.
*/
boolean isChildrenModified();
+
+ /**
+ *
+ * @return true if the child map has been loaded from the underlying data structure into the workspace.
+ */
+ boolean isChildrenLoaded();
}
Modified: core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java 2007-10-17 15:25:57 UTC (rev 4632)
+++ core/trunk/src/main/java/org/jboss/cache/optimistic/WorkspaceNodeImpl.java 2007-10-17 15:56:21 UTC (rev 4633)
@@ -60,12 +60,6 @@
this.node = node;
this.workspace = workspace;
optimisticDataMap = new HashMap<K, V>(node.getDataDirect());
- Map<Object, Node<K, V>> childrenMap = node.getChildrenMapDirect();
- // we NEED this null check otherwise the ConcurrentHashMap constructor could throw an NPE
- // could this not be a HashMap? After all, each WNI is only used within a single Workspace, which is only
- // attached to a single transaction entry.
- this.optimisticChildNodeMap = childrenMap == null ? new HashMap() : new HashMap(childrenMap);
-// optimisticChildNodeMap = new HashMap(childrenMap);
this.version = node.getVersion();
if (version == null)
{
@@ -78,6 +72,11 @@
return childrenModified;
}
+ public boolean isChildrenLoaded()
+ {
+ return optimisticChildNodeMap != null;
+ }
+
/**
* Returns true if this node is modified.
*/
@@ -140,9 +139,20 @@
//not able to delete from this
public Set<Object> getChildrenNames()
{
+ if (optimisticChildNodeMap == null)
+ {
+ initialiseChildMap();
+ }
return new HashSet<Object>(optimisticChildNodeMap.keySet());
}
+ @SuppressWarnings("unchecked")
+ private void initialiseChildMap()
+ {
+ Map<Object, Node<K, V>> childrenMap = node.getChildrenMapDirect();
+ this.optimisticChildNodeMap = childrenMap == null ? new HashMap() : new HashMap(childrenMap);
+ }
+
private void realPut(Map<K, V> data, boolean eraseData)
{
realPut(data, eraseData, true);
@@ -172,17 +182,17 @@
}
//see if we already have it
- NodeSPI<K, V> child = optimisticChildNodeMap.get(child_name);
+// NodeSPI<K, V> child = optimisticChildNodeMap.get(child_name);
// if not we need to create it
- if (child == null)
- {
+// if (child == null)
+// {
NodeFactory<K, V> factory = cache.getConfiguration().getRuntimeConfig().getNodeFactory();
- child = (NodeSPI<K, V>) factory.createNodeOfType(parent, child_name, parent, null);
- optimisticChildNodeMap.put(child_name, child);
+ NodeSPI<K, V> child = (NodeSPI<K, V>) factory.createNodeOfType(parent, child_name, parent, null);
+// optimisticChildNodeMap.put(child_name, child);
childrenAdded.add(child.getFqn());
childrenRemoved.remove(child.getFqn());
- }
+// }
childrenModified = true;
return child;
}
@@ -200,7 +210,8 @@
public NodeSPI<K, V> getChild(Object childName)
{
//see if in the the transaction map
- return optimisticChildNodeMap.get(childName);
+// return optimisticChildNodeMap.get(childName);
+ throw new UnsupportedOperationException("This call should be intercepted by the optimisticNodeInterceptor and the child node should be retrieved from the workspace.");
}
public NodeSPI<K, V> getNode()
@@ -302,7 +313,7 @@
public void addChild(WorkspaceNode<K,V> child)
{
- optimisticChildNodeMap.put(child.getFqn().getLastElement(), child.getNode());
+// optimisticChildNodeMap.put(child.getFqn().getLastElement(), child.getNode());
childrenAdded.add(child.getFqn());
childrenRemoved.remove(child.getFqn());
if (log.isTraceEnabled()) log.trace("Adding child " + child.getFqn());
@@ -387,18 +398,19 @@
public boolean removeChild(Object childName)
{
- NodeSPI n = optimisticChildNodeMap.remove(childName);
- if (n != null)
- {
- childrenRemoved.add(n.getFqn());
- childrenAdded.remove(n.getFqn());
+ //NodeSPI n = node.getChildDirect(childName);
+ Fqn childFqn = new Fqn(getFqn(), childName);
+ /*if (n != null)
+ {*/
+ childrenRemoved.add(childFqn);
+ childrenAdded.remove(childFqn);
childrenModified = true;
- return true;
- }
+ return node.getChildDirect(childName) != null;
+ /*}
else
{
return false;
- }
+ }*/
}
protected CacheSPI<K, V> getCache()
Added: core/trunk/src/test/java/org/jboss/cache/optimistic/ChildMapLazyLoadingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/ChildMapLazyLoadingTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ChildMapLazyLoadingTest.java 2007-10-17 15:56:21 UTC (rev 4633)
@@ -0,0 +1,214 @@
+package org.jboss.cache.optimistic;
+
+import org.jboss.cache.CacheImpl;
+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.transaction.DummyTransactionManagerLookup;
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.transaction.OptimisticTransactionEntry;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests that children maps in workspace nodes are only loaded lazily, when a move() or getChildrenNames()
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @since 2.1.0
+ */
+@Test(groups = {"functional"})
+public class ChildMapLazyLoadingTest
+{
+ private CacheSPI<Object, Object> cache;
+ private Fqn parent = Fqn.fromString("/parent");
+ private Fqn child = Fqn.fromString("/parent/child");
+
+ @BeforeMethod
+ public void setUp()
+ {
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+ cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache.start();
+ cache.put(parent, "k", "v");
+ cache.put(child, "k", "v");
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ if (cache != null)
+ {
+ try
+ {
+ cache.getTransactionManager().rollback();
+ }
+ catch (Exception e)
+ {
+
+ }
+ cache.stop();
+ }
+ }
+
+ public void testLazyLoadingOnCacheGet() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ assert cache.get(parent, "k").equals("v") : "Should retrieve value";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert !n.isChildrenLoaded() : "Should not have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnCachePut() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ cache.put(parent, "k2", "v2");
+ assert cache.get(parent, "k2").equals("v2") : "Should retrieve value";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert !n.isChildrenLoaded() : "Should not have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnCachePutData() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ Map<Object, Object> data = new HashMap<Object, Object>();
+ data.put("k2", "v2");
+ cache.put(parent, data);
+ assert cache.get(parent, "k2").equals("v2") : "Should retrieve value";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert !n.isChildrenLoaded() : "Should not have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnCacheRemove() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ cache.remove(parent, "k");
+ assert cache.get(parent, "k") == null : "Data should be removed";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert !n.isChildrenLoaded() : "Should not have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnCacheRemoveNode() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ cache.removeNode(parent);
+ assert !cache.getRoot().hasChild(parent) : "Node should be removed";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert !n.isChildrenLoaded() : "Should not have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnCacheMove() throws Exception
+ {
+ Fqn newparentToMoveTo = Fqn.fromString("/newparent");
+ Fqn newparent = Fqn.fromString("/newparent/parent");
+ Fqn newchild = Fqn.fromString("/newparent/parent/child");
+ cache.getTransactionManager().begin();
+ cache.move(parent, newparentToMoveTo);
+ assert !cache.getRoot().hasChild(parent) : "Node should be removed";
+ assert !cache.getRoot().hasChild(child) : "Node should be removed";
+ assert cache.getRoot().hasChild(newparent) : "Node should have moved";
+ assert cache.getRoot().hasChild(newchild) : "Node should have moved";
+ assert cache.get(newparent, "k").equals("v") : "Data should have moved too";
+
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert n.isChildrenLoaded() : "Should have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnNodeGet() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ Node node = cache.getRoot().getChild(parent);
+ assert node.getData().size() == 1 : "Node should have data";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert !n.isChildrenLoaded() : "Should not have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnNodeRemove() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ Node node = cache.getRoot().getChild(parent);
+ node.clearData();
+ assert node.getData().size() == 0 : "Node should have removed data";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert !n.isChildrenLoaded() : "Should not have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnNodePut() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ Node node = cache.getRoot().getChild(parent);
+ node.put("k2", "v2");
+ assert node.getData().size() == 2 : "Node should have added data";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert !n.isChildrenLoaded() : "Should not have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnNodeGetChildrenNames() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ Node node = cache.getRoot().getChild(parent);
+ assert node.getChildrenNames().size() == 1 : "Node should have 1 child";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert n.isChildrenLoaded() : "Should have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnNodeGetChildren() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ Node node = cache.getRoot().getChild(parent);
+ assert node.getChildren().size() == 1 : "Node should have 1 child";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert n.isChildrenLoaded() : "Should have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnNodeAddChild() throws Exception
+ {
+ Fqn newChild = Fqn.fromString("/newchild");
+ cache.getTransactionManager().begin();
+ Node node = cache.getRoot().getChild(parent);
+ node.addChild(newChild);
+ assert node.hasChild(newChild) : "Node should have added child";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert !n.isChildrenLoaded() : "Should not have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ public void testLazyLoadingOnNodeRemoveChild() throws Exception
+ {
+ cache.getTransactionManager().begin();
+ Node node = cache.getRoot().getChild(parent);
+ node.removeChild(child.getLastElement());
+ assert !node.hasChild(child.getLastElement()) : "Node should have removed child";
+ WorkspaceNode n = getWorkspaceNode(parent);
+ assert !n.isChildrenLoaded() : "Should not have loaded children";
+ cache.getTransactionManager().commit();
+ }
+
+ private WorkspaceNode getWorkspaceNode(Fqn fqn) throws Exception
+ {
+ CacheImpl ci = (CacheImpl) cache;
+ Transaction tx = ci.getTransactionManager().getTransaction();
+ GlobalTransaction gtx = ci.getTransactionTable().get(tx);
+ OptimisticTransactionEntry te = (OptimisticTransactionEntry) ci.getTransactionTable().get(gtx);
+ TransactionWorkspace tw = te.getTransactionWorkSpace();
+ return tw.getNode(fqn);
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java 2007-10-17 15:25:57 UTC (rev 4632)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java 2007-10-17 15:56:21 UTC (rev 4633)
@@ -5,18 +5,7 @@
*
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNotSame;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheImpl;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -27,12 +16,22 @@
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* @author xenephon
*/
+@Test (groups = {"functional"})
@SuppressWarnings("unchecked")
public class NodeInterceptorRemoveNodeTest extends AbstractOptimisticTestCase
{
@@ -135,8 +134,8 @@
assertEquals(true, workspace.getNode(Fqn.fromString("/one/two")).isDeleted());
assertNotNull(workspace.getNode(Fqn.fromString("/one")));
assertEquals(false, workspace.getNode(Fqn.fromString("/one")).isDeleted());
- assertEquals(1, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().get(1).size());
- assertEquals(null, workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("/two")));
+ List<Set<Fqn>> mergedChildren = workspace.getNode(Fqn.fromString("/one")).getMergedChildren();
+ assertEquals(1, mergedChildren.get(1).size());
System.out.println(entry.getModifications());
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
@@ -177,8 +176,6 @@
assertNotNull(workspace.getNode(Fqn.fromString("/one")));
assertEquals(true, workspace.getNode(Fqn.fromString("/one")).isDeleted());
assertEquals(1, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().get(0).size());
- assertNotNull(workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("two")));
- assertEquals(null, workspace.getNode(Fqn.fromString("/")).getChild(Fqn.fromString("/one")));
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
@@ -217,10 +214,6 @@
assertNotNull(workspace.getNode(Fqn.fromString("/one")));
assertEquals(true, workspace.getNode(Fqn.fromString("/one")).isDeleted());
- //will still have alink from one to two
- assertNotNull(workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("two")));
- assertEquals(null, workspace.getNode(Fqn.fromString("/")).getChild(Fqn.fromString("one")));
-
//now put /one/two back in
cache.remove("/one");
@@ -230,13 +223,8 @@
assertNotNull(workspace.getNode(Fqn.fromString("/one")));
assertEquals(true, workspace.getNode(Fqn.fromString("/one")).isDeleted());
- //will still have alink from one to two
- assertNotNull(workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("two")));
- assertEquals(null, workspace.getNode(Fqn.fromString("/")).getChild(Fqn.fromString("one")));
-
assertEquals(null, dummy.getCalled());
-
mgr.commit();
//assert what should be the results of our call
@@ -282,10 +270,6 @@
assertNotNull(workspace.getNode(Fqn.fromString("/one")));
assertEquals(true, workspace.getNode(Fqn.fromString("/one")).isDeleted());
- //will still have alink from one to two
- assertNotNull(workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("two")));
- assertEquals(null, workspace.getNode(Fqn.fromString("/")).getChild(Fqn.fromString("one")));
-
//now put /one/two back in
cache.put("/one/two", temp);
@@ -297,9 +281,6 @@
assertNotSame(two, twoAfter);
assertEquals(false, twoAfter.isDeleted());
- assertEquals(twoAfter.getNode(), workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("two")));
- assertEquals(oneAfter.getNode(), workspace.getNode(Fqn.fromString("/")).getChild(Fqn.fromString("one")));
-
assertEquals(null, dummy.getCalled());
@@ -348,10 +329,6 @@
assertNotNull(workspace.getNode(Fqn.fromString("/one")));
assertEquals(true, workspace.getNode(Fqn.fromString("/one")).isDeleted());
- //will still have alink from one to two
- assertNotNull(workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("two")));
- assertEquals(null, workspace.getNode(Fqn.fromString("/")).getChild(Fqn.fromString("one")));
-
//now put /one back in
SamplePojo pojo2 = new SamplePojo(21, "test");
cache.put(new Fqn("one"), "key1", pojo2);
@@ -364,12 +341,8 @@
assertEquals(two, twoAfter);
assertEquals(true, twoAfter.isDeleted());
- assertNull(workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("two")));
- assertEquals(oneAfter.getNode(), workspace.getNode(Fqn.fromString("/")).getChild(Fqn.fromString("one")));
-
assertEquals(null, dummy.getCalled());
-
mgr.commit();
assertEquals(pojo2, workspace.getNode(Fqn.fromString("/one")).get("key1"));
@@ -416,13 +389,8 @@
assertNotNull(workspace.getNode(Fqn.fromString("/one")));
assertEquals(false, workspace.getNode(Fqn.fromString("/one")).isDeleted());
- //will still have alink from one to two
- assertEquals(null, workspace.getNode(Fqn.fromString("/one")).getChild(Fqn.fromString("two")));
-
-
assertEquals(null, dummy.getCalled());
-
mgr.commit();
assertEquals(1, workspace.getNode(Fqn.fromString("/one")).getMergedChildren().get(1).size());
17 years
JBoss Cache SVN: r4632 - core/trunk/src/test/java/org/jboss/cache/invalidation.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-10-17 11:25:57 -0400 (Wed, 17 Oct 2007)
New Revision: 4632
Modified:
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
Log:
Add tests of node removal
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-10-17 14:58:56 UTC (rev 4631)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-10-17 15:25:57 UTC (rev 4632)
@@ -22,7 +22,11 @@
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.xml.XmlHelper;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
+
import org.testng.annotations.Test;
import org.w3c.dom.Element;
@@ -382,6 +386,89 @@
cache2 = null;
}
+ public void testPessimisticNodeRemoval() throws Exception
+ {
+ nodeRemovalTest(false);
+ }
+
+ public void testOptimisticNodeRemoval() throws Exception
+ {
+ nodeRemovalTest(true);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void nodeRemovalTest(boolean optimistic) throws Exception
+ {
+ CacheImpl<Object, Object> cache1 = null;
+ CacheImpl<Object, Object> cache2 = null;
+ try
+ {
+ cache1 = createCache(optimistic);
+ cache2 = createCache(optimistic);
+
+ Node root1 = cache1.getRoot();
+ Node root2 = cache2.getRoot();
+
+ // this fqn is relative, but since it is from the root it may as well be absolute
+ Fqn<String> fqn = Fqn.fromString("/test/fqn");
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root1.addChild(fqn);
+ assertTrue(root1.hasChild(fqn));
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root2.addChild(fqn);
+ assertTrue(root2.hasChild(fqn));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertFalse(root1.hasChild(fqn));
+ Node remoteNode = root2.getChild(fqn);
+ checkRemoteNodeIsRemoved(remoteNode);
+ assertEquals(false, cache1.removeNode(fqn));
+
+ Fqn<String> child = Fqn.fromString("/test/fqn/child");
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root1.addChild(child);
+ assertTrue(root1.hasChild(child));
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ root2.addChild(child);
+ assertTrue(root2.hasChild(child));
+
+ assertEquals(true, cache1.removeNode(fqn));
+ assertFalse(root1.hasChild(fqn));
+ remoteNode = root2.getChild(fqn);
+ checkRemoteNodeIsRemoved(remoteNode);
+ assertEquals(false, cache1.removeNode(fqn));
+ }
+ finally
+ {
+ if (cache1 != null)
+ {
+ cache1.stop();
+ cache1.destroy();
+ }
+ if (cache2 != null)
+ {
+ cache2.stop();
+ cache2.destroy();
+ }
+
+ }
+
+ }
+
+ private void checkRemoteNodeIsRemoved(Node<Object, Object> remoteNode) {
+
+ assertNotNull("remoteNode " + remoteNode.getFqn() +" is not null", remoteNode);
+ // FIXME A simple isValid() check should suffice,
+ // but that's not implemented
+ //assertFalse("remoteNode is not valid", remoteNode.isValid());
+ assertEquals("remoteNode " + remoteNode.getFqn() +" has no keys", 0, remoteNode.getKeys().size());
+ // Recursively check any children
+ for (Node<Object, Object> child : remoteNode.getChildren())
+ {
+ checkRemoteNodeIsRemoved(child);
+ }
+ }
+
private void dumpVersionInfo(CacheSPI c1, CacheSPI c2, Fqn fqn)
{
System.out.println("**** Versin Info for Fqn ["+fqn+"] ****");
17 years
JBoss Cache SVN: r4631 - core/trunk/src/test/java/org/jboss/cache/replicated.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-10-17 10:58:56 -0400 (Wed, 17 Oct 2007)
New Revision: 4631
Modified:
core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java
Log:
Add test of expected propagation of Cache.removeNode calls.
Modified: core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java 2007-10-17 14:56:50 UTC (rev 4630)
+++ core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTest.java 2007-10-17 14:58:56 UTC (rev 4631)
@@ -7,8 +7,10 @@
package org.jboss.cache.replicated;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
+import static org.testng.AssertJUnit.assertTrue;
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
@@ -96,6 +98,35 @@
assertEquals("Value should have replicated", 38, caches[1].get(fqn, "age"));
}
+ /**
+ * Checks for expected propagation of removeNode calls.
+ */
+ @SuppressWarnings("unchecked")
+ public void testNodeConvenienceNodeRemoval()
+ {
+ // this fqn is relative, but since it is from the root it may as well be absolute
+ Fqn<String> fqn = Fqn.fromString("/test/fqn");
+ caches[0].getRoot().addChild(fqn);
+ assertTrue(caches[0].getRoot().hasChild(fqn));
+ assertTrue(caches[1].getRoot().hasChild(fqn));
+
+ assertEquals(true, caches[0].removeNode(fqn));
+ assertFalse(caches[0].getRoot().hasChild(fqn));
+ assertFalse(caches[1].getRoot().hasChild(fqn));
+ assertEquals(false, caches[0].removeNode(fqn));
+
+ // Confirm it works as expected if the removed node has a child
+ Fqn<String> child = Fqn.fromString("/test/fqn/child");
+ caches[0].getRoot().addChild(child);
+ assertTrue(caches[0].getRoot().hasChild(child));
+ assertTrue(caches[1].getRoot().hasChild(child));
+
+ assertEquals(true, caches[0].removeNode(fqn));
+ assertFalse(caches[0].getRoot().hasChild(fqn));
+ assertFalse(caches[1].getRoot().hasChild(fqn));
+ assertEquals(false, caches[0].removeNode(fqn));
+ }
+
private void assertClusterSize(String message, int size)
{
for (Cache c : caches)
17 years
JBoss Cache SVN: r4630 - core/trunk/src/test/java/org/jboss/cache/api.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2007-10-17 10:56:50 -0400 (Wed, 17 Oct 2007)
New Revision: 4630
Modified:
core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java
Log:
Add minor assertion that Cache.removeNode removes nodes that have children
Modified: core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java 2007-10-17 03:33:42 UTC (rev 4629)
+++ core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java 2007-10-17 14:56:50 UTC (rev 4630)
@@ -184,7 +184,7 @@
/**
* Another convenience method that tests node removal
*/
- public void nodeConvenienceNodeRemoval()
+ public void testNodeConvenienceNodeRemoval()
{
// this fqn is relative, but since it is from the root it may as well be absolute
Fqn<String> fqn = Fqn.fromString("/test/fqn");
@@ -194,6 +194,15 @@
assertEquals(true, cache.removeNode(fqn));
assertFalse(cache.getRoot().hasChild(fqn));
assertEquals(false, cache.removeNode(fqn));
+
+ // Check that it's removed if it has a child
+ Fqn<String> child = Fqn.fromString("/test/fqn/child");
+ cache.getRoot().addChild(child);
+ assertTrue(cache.getRoot().hasChild(child));
+
+ assertEquals(true, cache.removeNode(fqn));
+ assertFalse(cache.getRoot().hasChild(fqn));
+ assertEquals(false, cache.removeNode(fqn));
}
/**
17 years
JBoss Cache SVN: r4629 - in core/trunk/src: test/java/org/jboss/cache/util and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: genman
Date: 2007-10-16 23:33:42 -0400 (Tue, 16 Oct 2007)
New Revision: 4629
Modified:
core/trunk/src/main/java/org/jboss/cache/util/DeltaMap.java
core/trunk/src/test/java/org/jboss/cache/util/DeltaMapTest.java
Log:
Add factory method for exclusion of keys
Modified: core/trunk/src/main/java/org/jboss/cache/util/DeltaMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/DeltaMap.java 2007-10-17 03:11:06 UTC (rev 4628)
+++ core/trunk/src/main/java/org/jboss/cache/util/DeltaMap.java 2007-10-17 03:33:42 UTC (rev 4629)
@@ -2,6 +2,7 @@
import java.util.AbstractMap;
import java.util.AbstractSet;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -41,10 +42,9 @@
private Map<K, V> original;
/**
- * Keys removed.
- * This should not exceed the size of the original map.
+ * Keys excluded.
*/
- private Set<K> removed = new HashSet<K>();
+ private Set<K> exclude;
/**
* Keys changed.
@@ -54,13 +54,15 @@
/**
* Constructs a new DeltaMap.
- * @param original will not be modified.
*/
- private DeltaMap(Map<K, V> original)
+ private DeltaMap(Map<K, V> original, Set<K> exclude)
{
if (original == null)
throw new NullPointerException("original");
+ if (exclude == null)
+ throw new NullPointerException("exclude");
this.original = original;
+ this.exclude = exclude;
}
/**
@@ -71,9 +73,29 @@
*/
public static <K, V> DeltaMap<K, V> create(Map<K, V> original)
{
- return new DeltaMap<K, V>(original);
+ return new DeltaMap<K, V>(original, new HashSet<K>());
}
+ /**
+ * Creates and returns a DeltaMap for an original map, excluding some key mappings.
+ *
+ * @param original will not be modified, except by {@link #commit()}
+ * @param excluded entries not to include
+ * @return a new instance
+ */
+ public static <K, V> DeltaMap<K, V> excludeKeys(Map<K, V> original, Set<K> exclude)
+ {
+ return new DeltaMap<K, V>(original, exclude);
+ }
+
+ /**
+ * Creates and returns a DeltaMap for an original map, excluding some key mappings.
+ */
+ public static <K, V> DeltaMap<K, V> excludeKeys(Map<K, V> original, K... exclude)
+ {
+ return excludeKeys(original, new HashSet<K>(Arrays.asList(exclude)));
+ }
+
@Override
public Set<java.util.Map.Entry<K, V>> entrySet()
{
@@ -89,7 +111,7 @@
@Override
public int size()
{
- int size = original.size() - removed.size();
+ int size = original.size() - exclude.size();
for (Object o : changed.keySet())
{
if (!original.containsKey(o))
@@ -103,7 +125,7 @@
@Override
public boolean containsKey(Object key)
{
- if (removed.contains(key))
+ if (exclude.contains(key))
return false;
if (changed.containsKey(key))
return true;
@@ -113,7 +135,7 @@
@Override
public V get(Object key)
{
- if (removed.contains(key))
+ if (exclude.contains(key))
return null;
if (changed.containsKey(key))
return changed.get(key);
@@ -129,9 +151,9 @@
else
old = original.get(key);
changed.put(key, value);
- if (removed.contains(key))
+ if (exclude.contains(key))
{
- removed.remove(key);
+ exclude.remove(key);
return null;
}
return old;
@@ -144,16 +166,16 @@
if (changed.containsKey(key))
{
if (original.containsKey(key))
- removed.add((K) key);
+ exclude.add((K) key);
return changed.remove(key);
}
- if (removed.contains(key))
+ if (exclude.contains(key))
{
return null;
}
if (original.containsKey(key))
{
- removed.add((K) key);
+ exclude.add((K) key);
return original.get(key);
}
return null;
@@ -165,9 +187,9 @@
*/
public void commit()
{
- original.keySet().removeAll(removed);
+ original.keySet().removeAll(exclude);
original.putAll(changed);
- removed.clear();
+ exclude.clear();
changed.clear();
}
@@ -186,7 +208,7 @@
private boolean redef(Entry<K, V> e)
{
K key = e.getKey();
- return removed.contains(key) || changed.containsKey(key);
+ return exclude.contains(key) || changed.containsKey(key);
}
public boolean hasNext()
@@ -239,13 +261,13 @@
* Returns a debug string.
*/
public String toDebugString() {
- return "DeltaMap original=" + original + " removed=" + removed + " changed=" + changed;
+ return "DeltaMap original=" + original + " exclude=" + exclude + " changed=" + changed;
}
@Override
public void clear()
{
- removed.addAll(original.keySet());
+ exclude.addAll(original.keySet());
changed.clear();
}
Modified: core/trunk/src/test/java/org/jboss/cache/util/DeltaMapTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/DeltaMapTest.java 2007-10-17 03:11:06 UTC (rev 4628)
+++ core/trunk/src/test/java/org/jboss/cache/util/DeltaMapTest.java 2007-10-17 03:33:42 UTC (rev 4629)
@@ -8,32 +8,39 @@
import java.util.NoSuchElementException;
import java.util.Map.Entry;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@Test(groups = {"functional", "transaction"})
public class DeltaMapTest
{
- public static String Y = "y";
+ static String Y = "y";
- public static String Z = "z";
+ static String Z = "z";
- public static String K = "k";
+ static String K = "k";
- HashMap<String, String> hm = new HashMap<String, String>();
+ HashMap<String, String> hm;
+
+ HashMap<String, String> backup;
+
+ DeltaMap<String, String> dm;
+
+ @BeforeMethod
+ public void setUp()
{
+ hm = new HashMap<String, String>();
hm.put(null, null);
hm.put(Y, Z);
hm.put(K, Y);
+ backup = new HashMap<String, String>(hm);
+ dm = DeltaMap.create(hm);
}
-
- HashMap<String, String> backup = new HashMap<String, String>(hm);
-
- DeltaMap<String, String> dm = DeltaMap.create(hm);
-
+
public void testChanges() throws Exception
{
- assertEquals(backup, dm);
+ assertEquals("" + dm.toDebugString(), backup, dm);
assertEquals(Z, dm.remove(Y));
assertEquals(null, dm.remove(Y));
assertEquals("changes not made to underlying map", backup, hm);
@@ -59,8 +66,20 @@
assertEquals(null, dm.remove(K));
}
- public void testClear() throws Exception
+ public void testExclude() throws Exception
{
+ dm = DeltaMap.excludeKeys(hm, Y);
+ assertEquals(false, dm.containsKey(Y));
+ }
+
+ public void testExclude2() throws Exception
+ {
+ dm = DeltaMap.excludeKeys(hm, hm.keySet());
+ assertEquals(0, dm.size());
+ }
+
+ public void testClearedMap() throws Exception
+ {
dm.clear();
assertEquals(0, dm.size());
assertEquals(backup, hm);
17 years