[jbosscache-commits] JBoss Cache SVN: r4951 - core/trunk/src/test/java/org/jboss/cache/interceptors.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Jan 2 19:57:22 EST 2008


Author: manik.surtani at jboss.com
Date: 2008-01-02 19:57:22 -0500 (Wed, 02 Jan 2008)
New Revision: 4951

Modified:
   core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java
Log:
Fixed test

Modified: core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java	2008-01-03 00:31:30 UTC (rev 4950)
+++ core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java	2008-01-03 00:57:22 UTC (rev 4951)
@@ -11,6 +11,7 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
 import org.jboss.cache.Region;
 import org.jboss.cache.RegionManager;
 import org.jboss.cache.config.EvictionConfig;
@@ -83,9 +84,9 @@
    }
 
    @SuppressWarnings("unchecked")
-   private Node<Object, Object> cast(Node node)
+   private NodeSPI<Object, Object> cast(Node node)
    {
-      return node;
+      return (NodeSPI<Object, Object>) node;
    }
 
    public void testVisitNode() throws Throwable
@@ -98,17 +99,15 @@
       Region regionABC = regionManager.getRegion(fqn1, false);
       assertNull(regionABC.takeLastEventNode());
 
-      cache.put(fqn1, "key", "value");
-      assertEquals("value", cache.get(fqn1, "key"));
-      Node<Object, Object> node = cast(cache.getNode(fqn1));
+      putQuietly(fqn1, "key", "value");
+      NodeSPI<Object, Object> node = cast(cache.peek(Fqn.fromString(fqn1), false, false));
       assertNotNull(node);
-      assertEquals("value", node.get("key"));
+      assertEquals("value", node.getDirect("key"));
 
-      cache.put(fqn3, "key", "value");
-      assertEquals("value", cache.get(fqn3, "key"));
-      node = cast(cache.getNode(fqn3));
+      putQuietly(fqn3, "key", "value");
+      node = cast(cache.peek(Fqn.fromString(fqn3), false, false));
       assertNotNull(node);
-      assertEquals("value", node.get("key"));
+      assertEquals("value", node.getDirect("key"));
 
 
       mc = MethodCallFactory.create(MethodDeclarations.getNodeMethodLocal,
@@ -162,6 +161,39 @@
 
    }
 
+   /**
+    * Helper to quietly add something into the cache without generating eviction events
+    *
+    * @param fqn   fqn to add
+    * @param key   key
+    * @param value value
+    */
+   private void putQuietly(String fqn, Object key, Object value)
+   {
+      putQuietly(Fqn.fromString(fqn), key, value);
+   }
+
+   /**
+    * Helper to quietly add something into the cache without generating eviction events
+    *
+    * @param fqn   fqn to add
+    * @param key   key
+    * @param value value
+    */
+   private void putQuietly(Fqn fqn, Object key, Object value)
+   {
+      NodeSPI root = cache.getRoot();
+      NodeSPI child = root;
+      for (int i = 0; i < fqn.size(); i++)
+      {
+         child = child.addChildDirect(new Fqn(fqn.get(i)));
+      }
+
+      assert child.getFqn().equals(fqn);
+
+      child.putDirect(key, value);
+   }
+
    public void testVisitElement() throws Throwable
    {
       // make sure a get/visit on an empty node and empty element results in no cache events being added to event queue
@@ -173,8 +205,9 @@
       Region region = regionManager.getRegion(fqn.toString(), false);
       assertNull(region.takeLastEventNode());
 
-      // add the node but try to get on a null element should result in no cache events being added to MarshRegion.
-      cache.put(fqn, "wrongkey", "");
+      // add the node but try to get on a null element should result in no cache events being added to Region.
+      putQuietly(fqn, "wrongkey", "");
+
       mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, false);
       interceptor.invoke(InvocationContext.fromMethodCall(mc));
       assertNull(region.takeLastEventNode());
@@ -189,7 +222,8 @@
 
       assertNull(region.takeLastEventNode());
 
-      cache.put(fqn4, key, "value");
+      putQuietly(fqn4, key, "value");
+
       // test on element granularity configured node.
       fqn = Fqn.fromString(fqn4);
       mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, false);
@@ -204,26 +238,28 @@
       assertNull(region.takeLastEventNode());
 
       fqn = Fqn.fromString("/d/e/g");
-      for (int i = 0; i < 1000; i++)
+      for (int i = 0; i < 100; i++)
       {
          key = i;
 
-         cache.put("/d/e/g", key, "");
+         putQuietly("/d/e/g", key, "");
 
          mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, true);
          interceptor.invoke(InvocationContext.fromMethodCall(mc));
       }
 
       region = regionManager.getRegion(fqn.toString(), false);
-      for (int i = 0; i < 1000; i++)
+
+      for (int i = 0; i < 100; i++)
       {
          event = region.takeLastEventNode();
          assertEquals(fqn, event.getFqn());
          assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
       }
 
-      cache.put("/a/b/c", key, "");
+      putQuietly("/a/b/c", key, "");
       fqn = Fqn.fromString("/a/b/c");
+
       mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, false);
       interceptor.invoke(InvocationContext.fromMethodCall(mc));
 
@@ -234,17 +270,17 @@
       assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
       assertEquals(fqn, event.getFqn());
 
-      for (int i = 0; i < 1000; i++)
+      for (int i = 0; i < 100; i++)
       {
          key = i;
 
-         cache.put(fqn, key, "");
+         putQuietly(fqn, key, "");
 
          mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, true);
          interceptor.invoke(InvocationContext.fromMethodCall(mc));
       }
 
-      for (int i = 0; i < 1000; i++)
+      for (int i = 0; i < 100; i++)
       {
          event = region.takeLastEventNode();
          assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
@@ -252,20 +288,6 @@
       }
 
       assertNull(region.takeLastEventNode());
-
-      // What exactly are we trying to test here?!?  
-      // check null handling
-//      mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, true);
-//      interceptor.invoke(InvocationContext.fromMethodCall(mc));
-//      assertNull(region.takeLastEventNode());
-//
-//      mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, null, true);
-//      interceptor.invoke(InvocationContext.fromMethodCall(mc));
-//      assertNull(region.takeLastEventNode());
-//
-//      mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, null, true);
-//      interceptor.invoke(InvocationContext.fromMethodCall(mc));
-//      assertNull(region.takeLastEventNode());
    }
 
    public void testCreateNode() throws Throwable
@@ -289,13 +311,13 @@
       assertEquals(fqn, event.getFqn());
       assertEquals(100, event.getElementDifference());
 
-      Node<Object, Object> node = cast(cache.getNode(fqn));
+      NodeSPI<Object, Object> node = cast(cache.peek(fqn, false, false));
       assertNotNull(node);
 
       for (int i = 0; i < 100; i++)
       {
-         assertTrue(node.getData().containsKey(i));
-         assertEquals(i, node.get(i));
+         assertTrue(node.getDataDirect().containsKey(i));
+         assertEquals(i, node.getDirect(i));
       }
 
       for (int i = 0; i < 100; i++)
@@ -304,7 +326,7 @@
                "value", false);
          interceptor.invoke(InvocationContext.fromMethodCall(mc));
 
-         assertEquals("value", cache.get(fqn, i));
+         assertEquals("value", cache.peek(fqn, false, false).getDirect(i));
       }
 
       for (int i = 0; i < 100; i++)
@@ -326,15 +348,15 @@
       assertEquals(fqn, event.getFqn());
       assertEquals(100, event.getElementDifference());
       assertNull(regionManager.getRegion(fqn.toString(), false).takeLastEventNode());
-      node = cast(cache.getNode(fqn));
-      assertEquals(100, node.getData().size());
+      node = cast(cache.peek(fqn, false, false));
+      assertEquals(100, node.getDataDirect().size());
 
       assertNotNull(node);
 
       for (int i = 0; i < 100; i++)
       {
-         assertTrue(node.getData().containsKey(i));
-         assertEquals(i, node.get(i));
+         assertTrue(node.getDataDirect().containsKey(i));
+         assertEquals(i, node.getDirect(i));
       }
 
       mc = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal, null, fqn, data, false, true);
@@ -353,8 +375,8 @@
 
       for (int i = 0; i < 100; i++)
       {
-         assertTrue(node.getData().containsKey(i));
-         assertEquals(i, node.get(i));
+         assertTrue(node.getDataDirect().containsKey(i));
+         assertEquals(i, node.getDirect(i));
       }
 
    }
@@ -369,23 +391,23 @@
       MethodCall mc = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal,
             null, fqn, key, value, false);
       interceptor.invoke(InvocationContext.fromMethodCall(mc));
-      assertEquals("value", cache.get(fqn, key));
+      assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
       EvictedEventNode event = region.takeLastEventNode();
       assertEquals(NodeEventType.ADD_ELEMENT_EVENT, event.getEventType());
       assertEquals(1, event.getElementDifference());
       assertEquals(fqn, event.getFqn());
-      assertEquals("value", cache.get(fqn, key));
+      assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
       assertNull(region.takeLastEventNode());
 
       mc = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal,
             null, fqn, key, value, false);
       interceptor.invoke(InvocationContext.fromMethodCall(mc));
-      assertEquals("value", cache.get(fqn, key));
+      assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
       event = region.takeLastEventNode();
       assertEquals(NodeEventType.ADD_ELEMENT_EVENT, event.getEventType());
       assertEquals(1, event.getElementDifference());
       assertEquals(fqn, event.getFqn());
-      assertEquals("value", cache.get(fqn, key));
+      assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
       assertNull(region.takeLastEventNode());
 
    }
@@ -393,13 +415,13 @@
    public void testRemoveNode() throws Throwable
    {
       Fqn fqn = Fqn.fromString("/a/b/c");
-      cache.put(fqn, "a", "b");
-      cache.put(fqn, "b", "c");
+      putQuietly(fqn, "a", "b");
+      putQuietly(fqn, "b", "c");
 
       MethodCall mc = MethodCallFactory.create(MethodDeclarations.removeDataMethodLocal, null, fqn, false);
       interceptor.invoke(InvocationContext.fromMethodCall(mc));
 
-      assertEquals(0, cache.getNode(fqn).getData().size());
+      assertEquals(0, cache.peek(fqn, false, false).getDataDirect().size());
       Region region = regionManager.getRegion(fqn.toString(), false);
       EvictedEventNode event = region.takeLastEventNode();
       assertEquals(NodeEventType.REMOVE_NODE_EVENT, event.getEventType());
@@ -409,7 +431,7 @@
       mc = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, null, fqn, false);
       interceptor.invoke(InvocationContext.fromMethodCall(mc));
 
-      assertNull(cache.getNode(fqn));
+      assertNull(cache.peek(fqn, false, false));
       event = region.takeLastEventNode();
       assertEquals(NodeEventType.REMOVE_NODE_EVENT, event.getEventType());
       assertEquals(fqn, event.getFqn());
@@ -419,8 +441,8 @@
    public void testRemoveElement() throws Throwable
    {
       Fqn fqn = Fqn.fromString("/a/b/c");
-      cache.put(fqn, "a", "b");
-      cache.put(fqn, "b", "c");
+      putQuietly(fqn, "a", "b");
+      putQuietly(fqn, "b", "c");
 
       MethodCall mc = MethodCallFactory.create(MethodDeclarations.removeKeyMethodLocal,
             null, fqn, "a", false);
@@ -496,12 +518,12 @@
       mc = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal,
             null, fqn, key, value, false);
       interceptor.invoke(InvocationContext.fromMethodCall(mc));
-      assertEquals("value", cache.get(fqn, key));
+      assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
       event = region.takeLastEventNode();
       assertEquals(NodeEventType.ADD_ELEMENT_EVENT, event.getEventType());
       assertEquals(1, event.getElementDifference());
       assertEquals(fqn, event.getFqn());
-      assertEquals("value", cache.get(fqn, key));
+      assertEquals("value", cache.peek(fqn, false, false).getDirect(key));
       assertNull(region.takeLastEventNode());
 
       mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, false);




More information about the jbosscache-commits mailing list