From jbosscache-commits at lists.jboss.org Mon Apr 14 10:41:50 2008 Content-Type: multipart/mixed; boundary="===============7624315432782735120==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r5551 - core/trunk/src/test/java/org/jboss/cache/marshall. Date: Mon, 14 Apr 2008 10:41:50 -0400 Message-ID: --===============7624315432782735120== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)jboss.com Date: 2008-04-14 10:41:49 -0400 (Mon, 14 Apr 2008) New Revision: 5551 Added: core/trunk/src/test/java/org/jboss/cache/marshall/BackwardCompatTest.java Log: Added a manual test to dump command serialization info Added: core/trunk/src/test/java/org/jboss/cache/marshall/BackwardCompatTest= .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/BackwardCompatTest.ja= va (rev 0) +++ core/trunk/src/test/java/org/jboss/cache/marshall/BackwardCompatTest.ja= va 2008-04-14 14:41:49 UTC (rev 5551) @@ -0,0 +1,140 @@ +package org.jboss.cache.marshall; + +import org.jboss.cache.commands.EvictNodeCommand; +import org.jboss.cache.commands.GravitateDataCommand; +import org.jboss.cache.commands.InvalidateCommand; +import org.jboss.cache.commands.MarshallableCommand; +import org.jboss.cache.commands.cachedata.*; +import org.jboss.cache.commands.channel.BlockChannelCommand; +import org.jboss.cache.commands.channel.UnblockChannelCommand; +import org.jboss.cache.commands.remote.AnnounceBuddyPoolNameCommand; +import org.jboss.cache.commands.remote.AssignToBuddyGroupCommand; +import org.jboss.cache.commands.remote.ClusteredGetCommand; +import org.jboss.cache.commands.remote.DataGravitationCleanupCommand; +import org.jboss.cache.commands.remote.RemoveFromBuddyGroupCommand; +import org.jboss.cache.commands.remote.ReplicateCommand; +import org.jboss.cache.commands.tx.CommitCommand; +import org.jboss.cache.commands.tx.OptimisticPrepareCommand; +import org.jboss.cache.commands.tx.PrepareCommand; +import org.jboss.cache.commands.tx.RollbackCommand; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.List; +import java.util.SortedMap; +import java.util.TreeMap; + +/** + * A simple test that ensures wire level compatibility of method ids and p= arameters between 2.1.0 and 2.2.0 (onwards). + *

+ * Sadly, this test cannot be automated easily. + * + * @author Manik Surtani (manik(a)jbo= ss.org) + * @since 2.2.0 + */ +(a)Test(groups =3D "manual") +public class BackwardCompatTest +{ + private SortedMap fieldMap =3D new TreeMap(); + private List unusedIds; + private SortedMap> comman= ds =3D new TreeMap>(); + + @BeforeTest + public void setUp() throws Exception + { + Field[] fields =3D MethodDeclarations.class.getFields(); + for (Field f : fields) + { + if (f.getName().endsWith("_id")) + { + // this is a method id. + Integer fieldValue =3D (Integer) f.get(MethodDeclarations.clas= s); + fieldMap.put(fieldValue, f); + } + } + + System.out.println("Map size: " + fieldMap.size()); + + // unused IDs. For some reason or the other these were not used in = JBoss Cache 2.1.0, but may have been used in prior versions. + // as such they should never be used in this or future versions. + Integer[] unusedIdArray =3D {0, 4, 15, 17, 19, 20, 21, 27, 32, 33}; + unusedIds =3D Arrays.asList(unusedIdArray); + + // initialise all commands + commands.put(ExistsNodeCommand.METHOD_ID, ExistsNodeCommand.class); + commands.put(GetChildrenNamesCommand.METHOD_ID, GetChildrenNamesComm= and.class); + commands.put(GetDataMapCommand.METHOD_ID, GetDataMapCommand.class); + commands.put(GetKeysCommand.METHOD_ID, GetKeysCommand.class); + commands.put(GetKeyValueCommand.METHOD_ID, GetKeyValueCommand.class); + commands.put(GetNodeCommand.METHOD_ID, GetNodeCommand.class); + commands.put(MoveCommand.METHOD_ID, MoveCommand.class); + commands.put(PutDataMapCommand.ERASE_METHOD_ID, PutDataMapCommand.cl= ass); + commands.put(PutDataMapCommand.METHOD_ID, PutDataMapCommand.class); + commands.put(PutDataMapCommand.ERASE_VERSIONED_METHOD_ID, PutDataMap= Command.class); + commands.put(PutDataMapCommand.VERSIONED_METHOD_ID, PutDataMapComman= d.class); + commands.put(PutKeyValueCommand.METHOD_ID, PutKeyValueCommand.class); + commands.put(PutKeyValueCommand.PUT_FOR_EXT_READ_METHOD_ID, PutKeyVa= lueCommand.class); + commands.put(PutKeyValueCommand.PUT_FOR_EXT_READ_VERSIONED_METHOD_ID= , PutKeyValueCommand.class); + commands.put(PutKeyValueCommand.VERSIONED_METHOD_ID, PutKeyValueComm= and.class); + commands.put(RemoveDataCommand.METHOD_ID, RemoveDataCommand.class); + commands.put(RemoveDataCommand.VERSIONED_METHOD_ID, RemoveDataComman= d.class); + commands.put(RemoveKeyCommand.METHOD_ID, RemoveKeyCommand.class); + commands.put(RemoveKeyCommand.VERSIONED_METHOD_ID, RemoveKeyCommand.= class); + commands.put(RemoveNodeCommand.METHOD_ID, RemoveNodeCommand.class); + commands.put(RemoveNodeCommand.VERSIONED_METHOD_ID, RemoveNodeComman= d.class); + commands.put(BlockChannelCommand.METHOD_ID, BlockChannelCommand.clas= s); + commands.put(UnblockChannelCommand.METHOD_ID, UnblockChannelCommand.= class); + commands.put(AnnounceBuddyPoolNameCommand.METHOD_ID, AnnounceBuddyPo= olNameCommand.class); + commands.put(AssignToBuddyGroupCommand.METHOD_ID, AssignToBuddyGroup= Command.class); + commands.put(ClusteredGetCommand.METHOD_ID, ClusteredGetCommand.clas= s); + commands.put(DataGravitationCleanupCommand.METHOD_ID, DataGravitatio= nCleanupCommand.class); + commands.put(RemoveFromBuddyGroupCommand.METHOD_ID, RemoveFromBuddyG= roupCommand.class); + commands.put(ReplicateCommand.SINGLE_METHOD_ID, ReplicateCommand.cla= ss); + commands.put(ReplicateCommand.MULTIPLE_METHOD_ID, ReplicateCommand.c= lass); + commands.put(CommitCommand.METHOD_ID, CommitCommand.class); + commands.put(OptimisticPrepareCommand.METHOD_ID, OptimisticPrepareCo= mmand.class); + commands.put(PrepareCommand.METHOD_ID, PrepareCommand.class); + commands.put(RollbackCommand.METHOD_ID, RollbackCommand.class); + commands.put(EvictNodeCommand.METHOD_ID, EvictNodeCommand.class); + commands.put(EvictNodeCommand.VERSIONED_METHOD_ID, EvictNodeCommand.= class); + commands.put(GravitateDataCommand.METHOD_ID, GravitateDataCommand.cl= ass); + commands.put(InvalidateCommand.METHOD_ID, InvalidateCommand.class); + } + + public void testUnusedMethodIds() + { + // ensure that the unused method ids aren't used by any of the Comma= nds. + for (Integer i : unusedIds) + { + assert !commands.containsKey(i) : "Id [" + i + "] is used by Comm= and " + commands.get(i).getName(); + assert !fieldMap.containsKey(i) : "Id [" + i + "] is used by Meth= odDeclarations class in field " + fieldMap.get(i).getName(); + } + } + + public void testMethodCalls() throws Exception + { + assert 47 =3D=3D fieldMap.lastKey(); + assert 47 =3D=3D commands.lastKey() : "Expected commands last key to= be 47; was " + commands.lastKey(); + printMaps(); + assert commands.size() =3D=3D fieldMap.size() : "Was expecting comma= nds and fieldMap sizes to be the same. FieldMap size is " + fieldMap.size(= ) + " and commands size is " + commands.size(); + } + + private void printMaps() + { + for (int i =3D 0; i < fieldMap.lastKey(); i++) + { + boolean unused =3D unusedIds.contains(i); + System.out.print("ID: " + i); + if (unused) + { + System.out.println(" *** UNUSED"); + } + else + { + System.out.println(" Field: " + fieldMap.get(i).getName() + " = Command: " + commands.get(i)); + } + } + } +} --===============7624315432782735120==--