From jbosscache-commits at lists.jboss.org Wed Mar 5 19:45:19 2008 Content-Type: multipart/mixed; boundary="===============7214864708117899747==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r5390 - in core/trunk/src: test/java/org/jboss/cache/marshall and 1 other directory. Date: Wed, 05 Mar 2008 19:45:19 -0500 Message-ID: --===============7214864708117899747== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/UnmarshalledReferences= Test.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 un= it tests to guard the problem Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller= 200.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.ja= va 2008-03-05 17:19:14 UTC (rev 5389) +++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.ja= va 2008-03-06 00:45:19 UTC (rev 5390) @@ -843,47 +843,3 @@ } } = -/** - * An efficient array-based list of referenced objects, using the referenc= e id as a subscript for the array. - */ -class UnmarshalledReferences -{ - private ArrayList referencedObjects =3D new ArrayList(); - - /** - * Retrieves an object referenced by an id - * - * @param ref reference - * @return object - */ - public Object getReferencedObject(int ref) - { - if (ref >=3D 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 =3D 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 =3D sz; i < ref; i++) referencedObjects.add(null); - } - referencedObjects.add(o); - } -} Added: core/trunk/src/main/java/org/jboss/cache/marshall/UnmarshalledRefere= nces.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/main/java/org/jboss/cache/marshall/UnmarshalledReference= s.java (rev 0) +++ core/trunk/src/main/java/org/jboss/cache/marshall/UnmarshalledReference= s.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 referenc= e id as a subscript for the array. + * + * @author Manik Surtani (manik(a)jbo= ss.org) + */ +public class UnmarshalledReferences +{ + private ArrayList referencedObjects =3D new ArrayList(); + + /** + * Retrieves an object referenced by an id + * + * @param ref reference + * @return object + */ + public Object getReferencedObject(int ref) + { + if (ref >=3D 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 =3D 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 =3D sz; i < ref; i++) referencedObjects.add(null); + } + referencedObjects.add(o); + } +} Added: core/trunk/src/test/java/org/jboss/cache/marshall/UnmarshalledRefere= ncesTest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/test/java/org/jboss/cache/marshall/UnmarshalledReference= sTest.java (rev 0) +++ core/trunk/src/test/java/org/jboss/cache/marshall/UnmarshalledReference= sTest.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 UnmarshalledReferences. = + * + * @author Mircea.Markus(a)jboss.com + */ +(a)Test(groups =3D {"functional"}) +public class UnmarshalledReferencesTest +{ + public void testSimpleGetPut() + { + UnmarshalledReferences refs =3D new UnmarshalledReferences(); + for (int i =3D 0; i < 100; i++) + { + refs.putReferencedObject(i, String.valueOf(i)); + } + for (int i =3D 0; i < 100; i++) + { + assertEquals(refs.getReferencedObject(i), String.valueOf(i)); + } + } + + public void testPutWithGap() + { + UnmarshalledReferences refs =3D 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 =3D 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)); + } +} --===============7214864708117899747==--