[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/marshall ...
Manik Surtani
manik at jboss.org
Tue Mar 20 10:58:45 EDT 2007
User: msurtani
Date: 07/03/20 10:58:45
Modified: tests/functional/org/jboss/cache/marshall
JBossSerializationTest.java
Log:
Added more comprehensive speed testing
Revision Changes Path
1.8 +60 -16 JBossCache/tests/functional/org/jboss/cache/marshall/JBossSerializationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JBossSerializationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/marshall/JBossSerializationTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- JBossSerializationTest.java 1 Feb 2007 16:31:33 -0000 1.7
+++ JBossSerializationTest.java 20 Mar 2007 14:58:45 -0000 1.8
@@ -13,6 +13,9 @@
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Random;
/**
@@ -24,23 +27,51 @@
{
// you can change these variables to change behavior of this testsuite, for debug purposes:
-
public static boolean SAVE_FILE = false;
- public static boolean USE_STRING = false;
+ public static final int relatedObjectListSize = 5;
+ private static final Random random = new Random();
- static class DummyObject implements java.io.Serializable
+ static class DummyObject implements Serializable
{
private static final long serialVersionUID = -1374365296408936578L;
String stringName;
+ List<DummyRelatedObject> list = new ArrayList<DummyRelatedObject>(relatedObjectListSize);
public DummyObject()
{
- stringName = "Hello world, blah blah blah." + (new Random().nextInt());
+ stringName = "Hello world, blah blah blah." + random.nextInt();
+ for (int i = 0; i < relatedObjectListSize; i++) list.add(new DummyRelatedObject());
}
- public boolean equals(Object obj)
+ public boolean equals(Object o)
{
- return stringName.equals(((DummyObject) obj).stringName);
+ DummyObject obj = (DummyObject) o;
+ return stringName.equals(obj.stringName) && list.equals(obj.list);
+ }
+
+ public int hashCode()
+ {
+ return (stringName.hashCode() * 10 + list.hashCode());
+ }
+ }
+
+ static class DummyRelatedObject implements Serializable
+ {
+ String state;
+
+ public DummyRelatedObject()
+ {
+ state = "some random state " + random.nextInt();
+ }
+
+ public boolean equals(Object o)
+ {
+ return state.equals(((DummyRelatedObject) o).state);
+ }
+
+ public int hashCode()
+ {
+ return state.hashCode();
}
}
@@ -54,21 +85,22 @@
}
}
- public void testSpeedSizeAndDefaults() throws Exception
+ public void testSpeedAndSizeUsingStrings() throws Exception
{
+ doTest(true);
+ }
- assertTrue("JBoss Serialization should be enabled by default", ObjectSerializationFactory.useJBossSerialization);
- assertEquals("Should be using the JBossObjectStreamFactory", JBossObjectStreamFactory.class, ObjectSerializationFactory.factory.getClass());
- Object dummyObject = null;
-
- if (USE_STRING)
+ public void testSpeedAndSizeUsingComplexObjects() throws Exception
{
- dummyObject = "Hello world, blah blah blah.";
+ doTest(false);
}
- else
+
+ public void doTest(boolean useStrings) throws Exception
{
- dummyObject = new DummyObject();
- }
+
+ assertTrue("JBoss Serialization should be enabled by default", ObjectSerializationFactory.useJBossSerialization);
+ assertEquals("Should be using the JBossObjectStreamFactory", JBossObjectStreamFactory.class, ObjectSerializationFactory.factory.getClass());
+ Object dummyObject = null;
ObjectSerializationFactory.useJBossSerialization = false;
ObjectSerializationFactory.factory = new JavaObjectStreamFactory();
@@ -81,6 +113,7 @@
for (int i = 0; i < 500000; i++)
{
+ dummyObject = getDummyObject(useStrings);
out.reset();
if (i == 10000)
{
@@ -110,6 +143,7 @@
start = 0;
for (int i = 0; i < 500000; i++)
{
+ dummyObject = getDummyObject(useStrings);
out.reset();
if (i == 10000)
{
@@ -141,4 +175,14 @@
assertTrue("JBoss Serialization output should be SMALLER than Java Serialization. Java: " + javaSerializationSize + "; jboss: " + jbossSerializationSize, jbossSerializationSize < javaSerializationSize);
}
+ private Object getDummyObject(boolean useString)
+ {
+ if (useString)
+ return "This is a string based dummy object " + random.nextInt();
+ else
+ return new DummyObject();
+ }
+
}
+
+
More information about the jboss-cvs-commits
mailing list