[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/marshall ...
Manik Surtani
msurtani at jboss.com
Thu Jan 11 20:12:49 EST 2007
User: msurtani
Date: 07/01/11 20:12:49
Modified: tests/functional/org/jboss/cache/marshall Tag:
Branch_JBossCache_1_4_0
TreeCacheMarshaller140Test.java
CustomCollectionTest.java
Added: tests/functional/org/jboss/cache/marshall Tag:
Branch_JBossCache_1_4_0 MySet.java MyList.java
MyMap.java
Log:
More marshalling tests
Revision Changes Path
No revision
No revision
1.1.2.5 +56 -0 JBossCache/tests/functional/org/jboss/cache/marshall/Attic/TreeCacheMarshaller140Test.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheMarshaller140Test.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/marshall/Attic/TreeCacheMarshaller140Test.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -b -r1.1.2.4 -r1.1.2.5
--- TreeCacheMarshaller140Test.java 11 Oct 2006 08:23:25 -0000 1.1.2.4
+++ TreeCacheMarshaller140Test.java 12 Jan 2007 01:12:49 -0000 1.1.2.5
@@ -6,6 +6,20 @@
*/
package org.jboss.cache.marshall;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.GlobalTransaction;
+import org.jgroups.stack.IpAddress;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.HashSet;
+import java.util.TreeSet;
+import java.util.HashMap;
+import java.util.TreeMap;
+import java.util.Collections;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+
/**
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
*/
@@ -17,4 +31,46 @@
currentVersionShort = 14;
expectedMarshallerClass = TreeCacheMarshaller140.class;
}
+
+ public void testKnownCollectionMagicNumbers() throws Exception
+ {
+ doMagicNumberTest(new ArrayList(), TreeCacheMarshaller140.MAGICNUMBER_ARRAY_LIST);
+ doMagicNumberTest(new LinkedList(), TreeCacheMarshaller140.MAGICNUMBER_LINKED_LIST);
+ doMagicNumberTest(new HashSet(), TreeCacheMarshaller140.MAGICNUMBER_HASH_SET);
+ doMagicNumberTest(new TreeSet(), TreeCacheMarshaller140.MAGICNUMBER_TREE_SET);
+ doMagicNumberTest(new HashMap(), TreeCacheMarshaller140.MAGICNUMBER_HASH_MAP);
+ doMagicNumberTest(new TreeMap(), TreeCacheMarshaller140.MAGICNUMBER_TREE_MAP);
+
+ // custom collections
+ doMagicNumberTest(new MyList(), TreeCacheMarshaller140.MAGICNUMBER_SERIALIZABLE);
+ doMagicNumberTest(new MySet(), TreeCacheMarshaller140.MAGICNUMBER_SERIALIZABLE);
+ doMagicNumberTest(new MyMap(), TreeCacheMarshaller140.MAGICNUMBER_SERIALIZABLE);
+
+ // empty collections
+ doMagicNumberTest(Collections.emptyList(), TreeCacheMarshaller140.MAGICNUMBER_SERIALIZABLE);
+ doMagicNumberTest(Collections.emptySet(), TreeCacheMarshaller140.MAGICNUMBER_SERIALIZABLE);
+ doMagicNumberTest(Collections.emptyMap(), TreeCacheMarshaller140.MAGICNUMBER_SERIALIZABLE);
+ }
+
+ public void testKnownTypeMagicNumbers() throws Exception
+ {
+ doMagicNumberTest(new Fqn(), TreeCacheMarshaller140.MAGICNUMBER_FQN);
+ doMagicNumberTest(new GlobalTransaction(), TreeCacheMarshaller140.MAGICNUMBER_GTX);
+ doMagicNumberTest(new IpAddress(), TreeCacheMarshaller140.MAGICNUMBER_IPADDRESS);
+ doMagicNumberTest(new Integer(10), TreeCacheMarshaller140.MAGICNUMBER_INTEGER);
+ doMagicNumberTest(new Long(10), TreeCacheMarshaller140.MAGICNUMBER_LONG);
+ doMagicNumberTest(Boolean.TRUE, TreeCacheMarshaller140.MAGICNUMBER_BOOLEAN);
+ doMagicNumberTest("HELLO", TreeCacheMarshaller140.MAGICNUMBER_STRING);
+ doMagicNumberTest(null, TreeCacheMarshaller140.MAGICNUMBER_NULL);
+ }
+
+ private void doMagicNumberTest(Object o, int magicNumber) throws Exception
+ {
+ byte[] bytes = marshaller.objectToByteBuffer(o);
+ ObjectInputStream is = ObjectSerializationFactory.createObjectInputStream(bytes);
+ short versionShort = is.readShort();
+ assertEquals(currentVersionShort, versionShort);
+ byte magicNumberFound = is.readByte();
+ assertEquals("Magic number mismatch", magicNumber, magicNumberFound);
+ }
}
1.1.2.2 +131 -50 JBossCache/tests/functional/org/jboss/cache/marshall/Attic/CustomCollectionTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CustomCollectionTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/marshall/Attic/CustomCollectionTest.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- CustomCollectionTest.java 11 Jan 2007 18:31:35 -0000 1.1.2.1
+++ CustomCollectionTest.java 12 Jan 2007 01:12:49 -0000 1.1.2.2
@@ -9,15 +9,16 @@
import java.util.Map;
import java.util.HashSet;
import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.TreeSet;
-import java.util.TreeMap;
+import java.util.List;
public class CustomCollectionTest extends TestCase
{
private TreeCache cache1 =null;
private TreeCache cache2 =null;
+ private String myListClass = MyList.class.getName();
+ private String mySetClass = MySet.class.getName();
+ private String myMapClass = MyMap.class.getName();
protected void setUp() throws Exception
{
@@ -45,81 +46,161 @@
cache2.stopService();
}
- public void testList() throws Exception
+ public void testMap() throws Exception
{
- cache1.put("/a", "key", new MyArrayList());
- Object o = cache2.get("/a", "key");
- assertTrue(o instanceof ArrayList);
- assertTrue(o instanceof MyArrayList);
+ doMapTest(false);
+ }
+
+ public void testMapWithRegions() throws Exception
+ {
+ doMapTest(true);
}
public void testSet() throws Exception
{
- cache1.put("/a", "key", new MySet());
- Object o = cache2.get("/a", "key");
- assertTrue(o instanceof Set);
- assertTrue(o instanceof MySet);
+ doSetTest(false);
}
- public void testMap() throws Exception
+ public void testSetWithRegions() throws Exception
+ {
+ doSetTest(true);
+ }
+
+ public void testList() throws Exception
+ {
+ doListTest(false);
+ }
+
+ public void testListWithRegions() throws Exception
{
- cache1.put("/a", "key", new MyMap());
+ doListTest(true);
+ }
+
+ private void doMapTest(boolean contextClassLoader) throws Exception
+ {
+
+ ClassLoader customClassloader = getClassLoader();
+ Class mapClass = customClassloader.loadClass(myMapClass);
+ Map map = (Map) (contextClassLoader ? mapClass.newInstance() : new MyMap());
+
+ map.put("k", "v");
+
+ if (contextClassLoader)
+ {
+ cache1.setUseRegionBasedMarshalling(true);
+ cache1.getRegionManager().createRegion("/a", customClassloader);
+ }
+
+ cache1.put("/a", "key", map);
Object o = cache2.get("/a", "key");
assertTrue(o instanceof Map);
- assertTrue(o instanceof MyMap);
+ if (contextClassLoader)
+ {
+ assertNotSame(MyMap.class, o.getClass());
+ assertSame(mapClass, o.getClass());
+ }
+ else
+ {
+ assertSame(MyMap.class, o.getClass());
+ assertNotSame(mapClass, o.getClass());
+ }
+ assertEquals("v", ((Map) o).get("k"));
}
- public void testControlList() throws Exception
+ private void doSetTest(boolean contextClassLoader) throws Exception
{
- cache1.put("/a", "key", new ArrayList());
- Object o = cache2.get("/a", "key");
- assertTrue(o instanceof ArrayList);
- cache1.put("/a", "key", new LinkedList());
- o = cache2.get("/a", "key");
- assertTrue(o instanceof LinkedList);
+ ClassLoader customClassloader = getClassLoader();
+ Class setClass = customClassloader.loadClass(mySetClass);
+ Set set = (Set) (contextClassLoader ? setClass.newInstance() : new MySet());
- }
+ set.add("k");
- public void testControlSet() throws Exception
+ if (contextClassLoader)
{
- cache1.put("/a", "key", new HashSet());
+ cache1.setUseRegionBasedMarshalling(true);
+ cache1.getRegionManager().createRegion("/a", customClassloader);
+ }
+
+ cache1.put("/a", "key", set);
Object o = cache2.get("/a", "key");
- assertTrue(o instanceof HashSet);
+ assertTrue(o instanceof Set);
+ if (contextClassLoader)
+ {
+ assertNotSame(MySet.class, o.getClass());
+ assertSame(setClass, o.getClass());
+ }
+ else
+ {
+ assertSame(MySet.class, o.getClass());
+ assertNotSame(setClass, o.getClass());
+ }
+ assertTrue(((Set) o).contains("k"));
+ }
- cache1.put("/a", "key", new TreeSet());
- o = cache2.get("/a", "key");
- assertTrue(o instanceof TreeSet);
+ private void doListTest(boolean contextClassLoader) throws Exception
+ {
- }
+ ClassLoader customClassloader = getClassLoader();
+ Class listClass = customClassloader.loadClass(myListClass);
+ List list = (List) (contextClassLoader ? listClass.newInstance() : new MyList());
- public void testControlMap() throws Exception
+ list.add("k");
+
+ if (contextClassLoader)
{
- cache1.put("/a", "key", new HashMap());
- Object o = cache2.get("/a", "key");
- assertTrue(o instanceof HashMap);
+ cache1.setUseRegionBasedMarshalling(true);
+ cache1.getRegionManager().createRegion("/a", customClassloader);
+ }
- cache1.put("/a", "key", new TreeMap());
- o = cache2.get("/a", "key");
- assertTrue(o instanceof TreeMap);
+ cache1.put("/a", "key", list);
+ Object o = cache2.get("/a", "key");
+ assertTrue(o instanceof List);
+ if (contextClassLoader)
+ {
+ assertNotSame(MyList.class, o.getClass());
+ assertSame(listClass, o.getClass());
+ }
+ else
+ {
+ assertSame(MyList.class, o.getClass());
+ assertNotSame(listClass, o.getClass());
+ }
+ assertTrue(((Set) o).contains("k"));
}
- // TODO add tests here to check region-based marshalling with custom collection types in a context class loader.
- public void log(Object o)
+ public void testHarnessClassLoader() throws Exception
{
- System.out.println(o);
- }
-}
+ Class myListFromCustomLoader = getClassLoader().loadClass(myListClass);
+ assertNotNull(myListFromCustomLoader);
+ assertFalse(MyList.class.equals(myListFromCustomLoader));
- class MyArrayList extends ArrayList
+ Object customLoaderMyList = myListFromCustomLoader.newInstance();
+ try
+ {
+ MyList m = (MyList) customLoaderMyList;
+ fail("Should have barfed");
+ }
+ catch (ClassCastException cce)
{
+ // expected
}
+ }
+
+
+
- class MySet extends HashSet
+ public void log(Object o)
{
+ System.out.println(o);
}
- class MyMap extends HashMap
+ protected ClassLoader getClassLoader() throws Exception
{
+ String[] includesClasses = { myListClass, mySetClass, myMapClass };
+ String [] excludesClasses = {};
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return new SelectedClassnameClassLoader(includesClasses, excludesClasses, cl);
}
+}
\ No newline at end of file
No revision
No revision
1.1.2.1 +7 -0 JBossCache/tests/functional/org/jboss/cache/marshall/Attic/MySet.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MySet.java
===================================================================
RCS file: MySet.java
diff -N MySet.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MySet.java 12 Jan 2007 01:12:49 -0000 1.1.2.1
@@ -0,0 +1,7 @@
+package org.jboss.cache.marshall;
+
+import java.util.HashSet;
+
+public class MySet extends HashSet
+{
+}
1.1.2.1 +7 -0 JBossCache/tests/functional/org/jboss/cache/marshall/Attic/MyList.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MyList.java
===================================================================
RCS file: MyList.java
diff -N MyList.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MyList.java 12 Jan 2007 01:12:49 -0000 1.1.2.1
@@ -0,0 +1,7 @@
+package org.jboss.cache.marshall;
+
+import java.util.ArrayList;
+
+public class MyList extends ArrayList
+{
+}
1.1.2.1 +7 -0 JBossCache/tests/functional/org/jboss/cache/marshall/Attic/MyMap.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MyMap.java
===================================================================
RCS file: MyMap.java
diff -N MyMap.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ MyMap.java 12 Jan 2007 01:12:49 -0000 1.1.2.1
@@ -0,0 +1,7 @@
+package org.jboss.cache.marshall;
+
+import java.util.HashMap;
+
+public class MyMap extends HashMap
+{
+}
More information about the jboss-cvs-commits
mailing list