[jboss-cvs] JBossCache/tests/compat/org/jboss/cache/compat ...
Pavel Tsekov
ptsekov at jboss.org
Sat Dec 16 08:13:03 EST 2006
User: ptsekov
Date: 06/12/16 08:13:03
Added: tests/compat/org/jboss/cache/compat Tag:
Branch_JBossCache_1_4_0
SerialVersionUIDUnitTestCase.java
Log:
Add support for testing whether serialized objects remain compatible with older versions of JBossCache (JBQA-536).
Revision Changes Path
No revision
No revision
1.1.2.1 +120 -0 JBossCache/tests/compat/org/jboss/cache/compat/Attic/SerialVersionUIDUnitTestCase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SerialVersionUIDUnitTestCase.java
===================================================================
RCS file: SerialVersionUIDUnitTestCase.java
diff -N SerialVersionUIDUnitTestCase.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SerialVersionUIDUnitTestCase.java 16 Dec 2006 13:13:03 -0000 1.1.2.1
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.compat;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jboss.tools.ClassVersionInfo;
+import org.jboss.tools.SerialVersionUID;
+
+/**
+ * Tests of serial version uid compatibility across jboss versions. The
+ * testsuite/etc/serialVersionUID/xxx.ser is created using the
+ * org.jboss.tools.SerialVersionUID utility.
+ *
+ * @author Scott.Stark at jboss.org
+ */
+public class SerialVersionUIDUnitTestCase extends TestCase
+{
+ public SerialVersionUIDUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ Compare two sets of classes for serialVersionUID compatibility.
+
+ @param classInfoMap - the legacy version classes
+ @param currentClassInfoMap - the current build classes
+ @param versionName - the legacy version name
+ @param badPackages - a list of package prefixes to ignore for errors
+ @return the number of serial version mismatches
+ */
+ private int compare(Map classInfoMap, Map currentClassInfoMap,
+ String versionName, String[] badPackages, StringBuffer bufferMessages)
+ throws IOException
+ {
+ File out = new File(versionName+".errors");
+ System.out.println("Writing errors to: "+out.getAbsolutePath());
+ FileWriter errors = new FileWriter(out);
+ int mismatchCount = 0;
+ Iterator iter = currentClassInfoMap.values().iterator();
+ while( iter.hasNext() )
+ {
+ ClassVersionInfo cvi = (ClassVersionInfo) iter.next();
+ String name = cvi.getName();
+ ClassVersionInfo cviLegacy = (ClassVersionInfo) classInfoMap.get(name);
+ if( cviLegacy != null && cvi.getSerialVersion() != cviLegacy.getSerialVersion() )
+ {
+ String msg = "serialVersionUID error for "+name
+ +", " + versionName + ": " + cviLegacy.getSerialVersion()
+ +", current: "+cvi.getSerialVersion();
+
+ // Don't count classes from badPackages
+ boolean isInBadPkg = false;
+ for(int n = 0; n < badPackages.length; n ++)
+ {
+ String pkg = badPackages[n];
+ if( name.startsWith(pkg) )
+ {
+ isInBadPkg = true;
+ break;
+ }
+ }
+
+ if (isInBadPkg)
+ continue;
+
+ if (mismatchCount>0)
+ {
+ bufferMessages.append(",\n");
+ }
+ bufferMessages.append(name);
+ mismatchCount ++;
+ System.err.println(msg);
+ errors.write(msg);
+ errors.write('\n');
+ }
+ }
+ errors.close();
+ // If the mismatchCount is 0 remove the error file
+ if( mismatchCount == 0 )
+ out.delete();
+
+ return mismatchCount;
+ }
+
+ static Map calcClassInfoMap()
+ throws IOException
+ {
+ SerialVersionUID.processProperties();
+ Map classInfoMap = SerialVersionUID.processJars();
+ return classInfoMap;
+ }
+
+ public static Test suite() throws Exception
+ {
+ TestSuite suite = new TestSuite();
+
+ return suite;
+ }
+
+ public static void main(String[] args)
+ {
+ junit.textui.TestRunner.run(SerialVersionUIDUnitTestCase.class);
+ }
+}
More information about the jboss-cvs-commits
mailing list