[jbosscache-commits] JBoss Cache SVN: r5551 - core/trunk/src/test/java/org/jboss/cache/marshall.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Apr 14 10:41:50 EDT 2008


Author: manik.surtani at 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
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/BackwardCompatTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/BackwardCompatTest.java	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 parameters between 2.1.0 and 2.2.0 (onwards).
+ * <p/>
+ * Sadly, this test cannot be automated easily.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.2.0
+ */
+ at Test(groups = "manual")
+public class BackwardCompatTest
+{
+   private SortedMap<Integer, Field> fieldMap = new TreeMap<Integer, Field>();
+   private List<Integer> unusedIds;
+   private SortedMap<Integer, Class<? extends MarshallableCommand>> commands = new TreeMap<Integer, Class<? extends MarshallableCommand>>();
+
+   @BeforeTest
+   public void setUp() throws Exception
+   {
+      Field[] fields = MethodDeclarations.class.getFields();
+      for (Field f : fields)
+      {
+         if (f.getName().endsWith("_id"))
+         {
+            // this is a method id.
+            Integer fieldValue = (Integer) f.get(MethodDeclarations.class);
+            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 = {0, 4, 15, 17, 19, 20, 21, 27, 32, 33};
+      unusedIds = Arrays.asList(unusedIdArray);
+
+      // initialise all commands
+      commands.put(ExistsNodeCommand.METHOD_ID, ExistsNodeCommand.class);
+      commands.put(GetChildrenNamesCommand.METHOD_ID, GetChildrenNamesCommand.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.class);
+      commands.put(PutDataMapCommand.METHOD_ID, PutDataMapCommand.class);
+      commands.put(PutDataMapCommand.ERASE_VERSIONED_METHOD_ID, PutDataMapCommand.class);
+      commands.put(PutDataMapCommand.VERSIONED_METHOD_ID, PutDataMapCommand.class);
+      commands.put(PutKeyValueCommand.METHOD_ID, PutKeyValueCommand.class);
+      commands.put(PutKeyValueCommand.PUT_FOR_EXT_READ_METHOD_ID, PutKeyValueCommand.class);
+      commands.put(PutKeyValueCommand.PUT_FOR_EXT_READ_VERSIONED_METHOD_ID, PutKeyValueCommand.class);
+      commands.put(PutKeyValueCommand.VERSIONED_METHOD_ID, PutKeyValueCommand.class);
+      commands.put(RemoveDataCommand.METHOD_ID, RemoveDataCommand.class);
+      commands.put(RemoveDataCommand.VERSIONED_METHOD_ID, RemoveDataCommand.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, RemoveNodeCommand.class);
+      commands.put(BlockChannelCommand.METHOD_ID, BlockChannelCommand.class);
+      commands.put(UnblockChannelCommand.METHOD_ID, UnblockChannelCommand.class);
+      commands.put(AnnounceBuddyPoolNameCommand.METHOD_ID, AnnounceBuddyPoolNameCommand.class);
+      commands.put(AssignToBuddyGroupCommand.METHOD_ID, AssignToBuddyGroupCommand.class);
+      commands.put(ClusteredGetCommand.METHOD_ID, ClusteredGetCommand.class);
+      commands.put(DataGravitationCleanupCommand.METHOD_ID, DataGravitationCleanupCommand.class);
+      commands.put(RemoveFromBuddyGroupCommand.METHOD_ID, RemoveFromBuddyGroupCommand.class);
+      commands.put(ReplicateCommand.SINGLE_METHOD_ID, ReplicateCommand.class);
+      commands.put(ReplicateCommand.MULTIPLE_METHOD_ID, ReplicateCommand.class);
+      commands.put(CommitCommand.METHOD_ID, CommitCommand.class);
+      commands.put(OptimisticPrepareCommand.METHOD_ID, OptimisticPrepareCommand.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.class);
+      commands.put(InvalidateCommand.METHOD_ID, InvalidateCommand.class);
+   }
+
+   public void testUnusedMethodIds()
+   {
+      // ensure that the unused method ids aren't used by any of the Commands.
+      for (Integer i : unusedIds)
+      {
+         assert !commands.containsKey(i) : "Id [" + i + "] is used by Command " + commands.get(i).getName();
+         assert !fieldMap.containsKey(i) : "Id [" + i + "] is used by MethodDeclarations class in field " + fieldMap.get(i).getName();
+      }
+   }
+
+   public void testMethodCalls() throws Exception
+   {
+      assert 47 == fieldMap.lastKey();
+      assert 47 == commands.lastKey() : "Expected commands last key to be 47; was " + commands.lastKey();
+      printMaps();
+      assert commands.size() == fieldMap.size() : "Was expecting commands and fieldMap sizes to be the same.  FieldMap size is " + fieldMap.size() + " and commands size is " + commands.size();
+   }
+
+   private void printMaps()
+   {
+      for (int i = 0; i < fieldMap.lastKey(); i++)
+      {
+         boolean unused = 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));
+         }
+      }
+   }
+}




More information about the jbosscache-commits mailing list