[jbosscache-commits] JBoss Cache SVN: r5581 - in core/trunk/src: main/java/org/jboss/cache/marshall and 2 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Apr 16 13:39:19 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-16 13:39:19 -0400 (Wed, 16 Apr 2008)
New Revision: 5581

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java
   core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java
   core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java
   core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
   core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
   core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
   core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java
   core/trunk/src/test/java/org/jboss/cache/marshall/io/ObjectStreamPoolTest.java
Log:
Marshaller fixes

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java	2008-04-16 16:39:46 UTC (rev 5580)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java	2008-04-16 17:39:19 UTC (rev 5581)
@@ -16,7 +16,6 @@
 import org.jboss.cache.commands.CacheCommand;
 import org.jboss.cache.commands.CommandsFactory;
 import org.jboss.cache.commands.cachedata.CacheDataCommand;
-import org.jboss.cache.commands.cachedata.ExistsNodeCommand;
 import org.jboss.cache.commands.cachedata.GetChildrenNamesCommand;
 import org.jboss.cache.commands.cachedata.GetDataMapCommand;
 import org.jboss.cache.commands.cachedata.GetKeyValueCommand;

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java	2008-04-16 16:39:46 UTC (rev 5580)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java	2008-04-16 17:39:19 UTC (rev 5581)
@@ -54,19 +54,7 @@
       {
          try
          {
-            CacheCommand cmd = (CacheCommand) req_marshaller.objectFromByteBuffer(req.getBuffer());
-            if (trace) log.trace("[sender=" + req.getSrc() + "], command: " + cmd);
-
-            //todo [mmarkus] this is very ugly and caused by the fact that in the previous version the call for these methods was not chained.
-            //todo re-thinking of these commands is necessary
-            if (cmd instanceof DirectCommand)
-            {
-               if (trace) log.trace("This is a direct command - so performing directlty and not via the invoker.");
-               DirectCommand dCmd = (DirectCommand) cmd;
-               return dCmd.performDirectly();
-            }
-
-            return cid.invoke(cmd);
+            return executeCommand((CacheCommand) req_marshaller.objectFromByteBuffer(req.getBuffer()), req);
          }
          catch (Throwable x)
          {
@@ -80,6 +68,20 @@
       }
    }
 
+   protected Object executeCommand(CacheCommand cmd, Message req) throws Throwable
+   {
+      if (trace) log.trace("Executing command: " + cmd + " [sender=" + req.getSrc() + "]");
+
+      if (cmd instanceof DirectCommand)
+      {
+         if (trace) log.trace("This is a direct command - so performing directlty and not via the invoker.");
+         DirectCommand dCmd = (DirectCommand) cmd;
+         return dCmd.performDirectly();
+      }
+
+      return cid.invoke(cmd);
+   }
+
    @Override
    public String toString()
    {

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java	2008-04-16 16:39:46 UTC (rev 5580)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java	2008-04-16 17:39:19 UTC (rev 5581)
@@ -65,9 +65,7 @@
 
          try
          {
-            if (trace) log.trace("[sender=" + req.getSrc() + "], method_call: " + command);
-
-            Object retVal = cid.invoke(command);
+            Object retVal = executeCommand(command, req);
             return new RegionalizedReturnValue(retVal, rmc);
          }
          catch (Throwable x)

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java	2008-04-16 16:39:46 UTC (rev 5580)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/AbstractVersionAwareMarshallerTest.java	2008-04-16 17:39:19 UTC (rev 5581)
@@ -1,6 +1,7 @@
 package org.jboss.cache.marshall;
 
 import org.jboss.cache.RegionManager;
+import org.jboss.cache.commands.CommandsFactory;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.factories.ComponentRegistry;
 
@@ -24,6 +25,11 @@
       cr.registerComponent(rm, RegionManager.class);
       VersionAwareMarshaller vam = (VersionAwareMarshaller) cr.getComponent(Marshaller.class);
       if (cr.getOverallState() == ComponentRegistry.State.STARTED) cr.stop();
+
+      CommandsFactory cf = cr.getComponent(CommandsFactory.class);
+      if (cf == null) cf = new CommandsFactory(null, cr);
+      cr.registerComponent(CommandsFactory.class.getName(), cf, CommandsFactory.class);
+
       cr.start();
       return vam;
    }

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java	2008-04-16 16:39:46 UTC (rev 5580)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java	2008-04-16 17:39:19 UTC (rev 5581)
@@ -13,7 +13,6 @@
 import org.jboss.cache.Region;
 import org.jboss.cache.RegionManager;
 import org.jboss.cache.commands.CacheCommand;
-import org.jboss.cache.commands.CommandsFactory;
 import org.jboss.cache.commands.cachedata.PutKeyValueCommand;
 import org.jboss.cache.commands.remote.ReplicateCommand;
 import org.jboss.cache.config.Configuration;
@@ -32,7 +31,6 @@
 @Test(groups = "functional")
 public class ActiveInactiveTest extends AbstractVersionAwareMarshallerTest
 {
-   CommandsFactory commandsFactory = new CommandsFactory();
    RegionManager rman;
    CacheSPI cache;
    Configuration c;
@@ -154,8 +152,8 @@
 
    public void testObjectFromByteBuffer() throws Exception
    {
-      PutKeyValueCommand put = commandsFactory.buildPutKeyValueCommand(null, A_B, "name", "Joe", false, false);
-      ReplicateCommand replicate = commandsFactory.buildReplicateCommand(put);
+      PutKeyValueCommand put = new PutKeyValueCommand(null, A_B, "name", "Joe", false, false);
+      ReplicateCommand replicate = new ReplicateCommand(put);
 
       rman.setDefaultInactive(true);
       // register A as an inactive marshalling region

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java	2008-04-16 16:39:46 UTC (rev 5580)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java	2008-04-16 17:39:19 UTC (rev 5581)
@@ -9,6 +9,7 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Region;
 import org.jboss.cache.RegionManager;
+import org.jboss.cache.commands.remote.ClusteredGetCommand;
 import org.jboss.cache.factories.ComponentRegistry;
 import org.testng.annotations.Test;
 
@@ -96,7 +97,7 @@
       final Fqn region = Fqn.fromString("/hello");
       Region r = rm.getRegion(region, true);
       r.registerContextClassLoader(this.getClass().getClassLoader());
-      cm200.objectToObjectStream(commandsFactory.buildClusteredGetCommand(null, null), oos, region);
+      cm200.objectToObjectStream(new ClusteredGetCommand(null, null), oos, region);
       oos.close();
 
       final byte[] stream = baos.toByteArray();

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java	2008-04-16 16:39:46 UTC (rev 5580)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java	2008-04-16 17:39:19 UTC (rev 5581)
@@ -118,7 +118,7 @@
       byte[] asBytes = marshaller.objectToByteBuffer(cmd);
       Object o2 = marshaller.objectFromByteBuffer(asBytes);
 
-      assertTrue("Unmarshalled object should be a method call", o2 instanceof MethodCall);
+      assertTrue("Unmarshalled object should be a method call", o2 instanceof CacheCommand);
       CacheCommand cmd2 = (CacheCommand) o2;
 
       assertEquals(cmd, cmd2);

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java	2008-04-16 16:39:46 UTC (rev 5580)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java	2008-04-16 17:39:19 UTC (rev 5581)
@@ -1,9 +1,12 @@
 package org.jboss.cache.marshall;
 
 import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.CacheCommand;
 import org.jboss.cache.commands.CommandsFactory;
-import org.jboss.cache.commands.CacheCommand;
+import org.jboss.cache.commands.cachedata.PutDataMapCommand;
 import org.jboss.cache.commands.tx.PrepareCommand;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.ComponentRegistry;
 import static org.testng.AssertJUnit.assertEquals;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -22,26 +25,32 @@
 @Test(groups = {"functional"})
 public class MethodIdPreservationTest
 {
-   private Marshaller m = new CacheMarshaller210();
+   private Marshaller m;
    private ObjectOutputStream stream;
    private ByteArrayOutputStream byteStream;
    private CacheCommand command1;
-   private CacheCommand command2;
    private List<CacheCommand> list = new ArrayList<CacheCommand>(2);
    private PrepareCommand prepareComand;
-   private CommandsFactory commandsFactory;
 
    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception
    {
+
       byteStream = new ByteArrayOutputStream();
       stream = new ObjectOutputStream(byteStream);
-      command1 = commandsFactory.buildPutDataMapCommand(null, Fqn.ROOT, null, false, true);
-      command2 = commandsFactory.buildPutDataMapCommand(null, Fqn.ROOT, null, false, true);
+      command1 = new PutDataMapCommand(null, Fqn.ROOT, null, false, true);
+
       list.clear();
       list.add(command1);
-      list.add(command2);
-      prepareComand = commandsFactory.buildPrepareCommand(null, list, null, true);
+      list.add(new PutDataMapCommand(null, Fqn.ROOT, null, false, true));
+      prepareComand = new PrepareCommand(null, list, null, true);
+
+      CacheMarshaller210 cm210 = new CacheMarshaller210();
+      ComponentRegistry registry = new ComponentRegistry(new Configuration());
+      CommandsFactory factory = new CommandsFactory(null, registry);
+      cm210.injectCommandsFactory(factory);
+
+      m = cm210;
    }
 
    public void testSingleMethodCall() throws Exception
@@ -51,9 +60,6 @@
       ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
       Object result = m.objectFromObjectStream(in);
       assertEquals(command1.getClass(), result.getClass());
-
-      MethodCall resultMethod = (MethodCall) result;
-//      assertEquals(command1.getMethodId(), resultMethod.getMethodId());
    }
 
    public void testListOfMethodCalls() throws Exception
@@ -64,11 +70,8 @@
       Object result = m.objectFromObjectStream(in);
       assertEquals(list.getClass(), result.getClass());
       assertEquals(list.size(), ((List) result).size());
-      MethodCall result1 = (MethodCall) ((List) result).get(0);
-      MethodCall result2 = (MethodCall) ((List) result).get(1);
-
-//      assertEquals(command1.getMethodId(), result1.getMethodId());
-//      assertEquals(command2.getMethodId(), result2.getMethodId());
+      assert ((List) result).get(0) instanceof PutDataMapCommand;
+      assert ((List) result).get(1) instanceof PutDataMapCommand;
    }
 
    public void testMethodCallsInPrepare() throws Exception
@@ -79,14 +82,12 @@
       Object result = m.objectFromObjectStream(in);
 
       assertEquals(prepareComand.getClass(), result.getClass());
-      MethodCall prepareCallRes = (MethodCall) result;
-      List listResult = (List) prepareCallRes.getArgs()[1];
+      PrepareCommand prepareCallRes = (PrepareCommand) result;
+      List listResult = prepareCallRes.getModifications();
 
       assertEquals(list.size(), listResult.size());
-      MethodCall result1 = (MethodCall) listResult.get(0);
-      MethodCall result2 = (MethodCall) listResult.get(1);
 
-//      assertEquals(command1.getMethodId(), result1.getMethodId());
-//      assertEquals(command2.getMethodId(), result2.getMethodId());
+      assert listResult.get(0) instanceof PutDataMapCommand;
+      assert listResult.get(1) instanceof PutDataMapCommand;
    }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/marshall/io/ObjectStreamPoolTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/io/ObjectStreamPoolTest.java	2008-04-16 16:39:46 UTC (rev 5580)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/io/ObjectStreamPoolTest.java	2008-04-16 17:39:19 UTC (rev 5581)
@@ -14,7 +14,7 @@
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 2.1.0
  */
- at Test(groups = "functional")
+ at Test(groups = "functional", enabled = false)
 public class ObjectStreamPoolTest implements Serializable
 {
    transient ObjectStreamPool pool;




More information about the jbosscache-commits mailing list