[jbosscache-commits] JBoss Cache SVN: r5390 - in core/trunk/src: test/java/org/jboss/cache/marshall and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Mar 5 19:45:19 EST 2008


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 at jboss.org">Manik Surtani (manik at 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 at jboss.com
+ */
+ at 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));
+   }
+}




More information about the jbosscache-commits mailing list