From jbosscache-commits at lists.jboss.org Tue Sep 23 10:58:35 2008 Content-Type: multipart/mixed; boundary="===============5936947862563727957==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r6782 - in core/branches/1.4.X: tests/functional/org/jboss/cache/marshall and 1 other directory. Date: Tue, 23 Sep 2008 10:58:35 -0400 Message-ID: --===============5936947862563727957== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)jboss.com Date: 2008-09-23 10:58:35 -0400 (Tue, 23 Sep 2008) New Revision: 6782 Modified: core/branches/1.4.X/src/org/jboss/cache/marshall/TreeCacheMarshaller140.= java core/branches/1.4.X/tests/functional/org/jboss/cache/marshall/TreeCacheM= arshaller140Test.java Log: JBCACHE-1412: Marshaller uses equals() to test object equality instead of = identity when performing reference counting Modified: core/branches/1.4.X/src/org/jboss/cache/marshall/TreeCacheMarshal= ler140.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/branches/1.4.X/src/org/jboss/cache/marshall/TreeCacheMarshaller140= .java 2008-09-23 14:52:26 UTC (rev 6781) +++ core/branches/1.4.X/src/org/jboss/cache/marshall/TreeCacheMarshaller140= .java 2008-09-23 14:58:35 UTC (rev 6782) @@ -30,6 +30,7 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; +import java.util.IdentityHashMap; = /** * An enhanced marshaller for RPC calls between TreeCache instances. @@ -74,7 +75,7 @@ public void objectToStream(Object o, ObjectOutputStream out) throws Ex= ception { if (log.isTraceEnabled()) log.trace("Marshalling object " + o); - Map refMap =3D new HashMap(); + Map refMap =3D new IdentityHashMap(); = if (useRegionBasedMarshalling) { @@ -108,7 +109,7 @@ public Object objectFromStream(ObjectInputStream in) throws Exception { Object retValue; - Map refMap =3D new HashMap(); + Map refMap =3D new IdentityHashMap(); = if (useRegionBasedMarshalling) { Modified: core/branches/1.4.X/tests/functional/org/jboss/cache/marshall/Tre= eCacheMarshaller140Test.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/branches/1.4.X/tests/functional/org/jboss/cache/marshall/TreeCache= Marshaller140Test.java 2008-09-23 14:52:26 UTC (rev 6781) +++ core/branches/1.4.X/tests/functional/org/jboss/cache/marshall/TreeCache= Marshaller140Test.java 2008-09-23 14:58:35 UTC (rev 6782) @@ -11,6 +11,10 @@ import org.jgroups.stack.IpAddress; = import java.io.ObjectInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectOutputStream; +import java.io.ByteArrayInputStream; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -18,6 +22,7 @@ import java.util.LinkedList; import java.util.TreeMap; import java.util.TreeSet; +import java.util.List; = /** * @author Manik Surtani (manik(a)jbo= ss.org) @@ -31,6 +36,39 @@ expectedMarshallerClass =3D TreeCacheMarshaller140.class; } = + public void testBadEquals() throws Exception + { + // object1 and Object2 should NOT be equal, even though their equal= s() methods are broken. + Broken o1 =3D new Broken(); + Broken o2 =3D new Broken(); + + o1.name =3D "o1"; + o2.name =3D "o2"; + + assertNotSame(o1, o2); + assertEquals(o1, o2); + + List l =3D new ArrayList(2); // lists will allow "duplicate" entrie= s. + l.add(o1); + l.add(o2); + + TreeCacheMarshaller140 marsh =3D new TreeCacheMarshaller140(null, f= alse, false); + ByteArrayOutputStream bout =3D new ByteArrayOutputStream(); + ObjectOutputStream out =3D new ObjectOutputStream(bout); + marsh.objectToStream(l, out); + out.close(); + ObjectInputStream in =3D new ObjectInputStream(new ByteArrayInputSt= ream(bout.toByteArray())); + List l2 =3D (List) marsh.objectFromStream(in); + + assertEquals(l2.size(), 2); + assertEquals("o1", ((Broken) l2.get(0)).name); + assertEquals("o2", ((Broken) l2.get(1)).name); + + assertNotSame(l2.get(0), l2.get(1)); + assertEquals(l2.get(0), l2.get(1)); + } + + public void testKnownCollectionMagicNumbers() throws Exception { doMagicNumberTest(new ArrayList(), TreeCacheMarshaller140.MAGICNUMBE= R_ARRAY_LIST); @@ -73,3 +111,18 @@ assertEquals("Magic number mismatch", magicNumber, magicNumberFound); } } + +class Broken implements Serializable +{ + String name; + + public boolean equals(Object o) + { + return true; + } + + public int hashCode() + { + return 10; + } +} --===============5936947862563727957==--