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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Sep 16 14:04:26 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-09-16 14:04:26 -0400 (Tue, 16 Sep 2008)
New Revision: 6741

Added:
   core/trunk/src/test/java/org/jboss/cache/profiling/MockAsyncReplTest.java
Modified:
   core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
Log:
Tests to isolate and profile rpc manager code

Added: core/trunk/src/test/java/org/jboss/cache/profiling/MockAsyncReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/MockAsyncReplTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/MockAsyncReplTest.java	2008-09-16 18:04:26 UTC (rev 6741)
@@ -0,0 +1,93 @@
+package org.jboss.cache.profiling;
+
+import org.jboss.cache.RPCManager;
+import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.factories.ComponentRegistry;
+import org.jboss.cache.marshall.CommandAwareRpcDispatcher;
+import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.reflect.ReflectionUtil;
+import org.jgroups.Address;
+import org.jgroups.blocks.RpcDispatcher;
+import org.jgroups.blocks.RspFilter;
+import org.jgroups.util.RspList;
+import org.testng.annotations.Test;
+
+import java.io.NotSerializableException;
+import java.util.Vector;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public class MockAsyncReplTest extends ProfileTest
+{
+   @Override
+   @Test(enabled = true)
+   public void testReplAsync() throws Exception
+   {
+      // same as superclass, except that we use a mock RpcDispatcher that does nothing.  Measure throughput to test speed of JBC stack.
+      super.testReplAsync();
+   }
+
+   @Override
+   protected void startup()
+   {
+      long startTime = System.currentTimeMillis();
+      log.warn("Starting cache");
+      cache.start();
+      // now remove the existing RpcDispatcher and replace with one that is a noop.
+      ComponentRegistry cr = TestingUtil.extractComponentRegistry(cache);
+      RPCManager rpcManager = cr.getComponent(RPCManager.class);
+      RpcDispatcher d = (RpcDispatcher) TestingUtil.extractField(rpcManager, "rpcDispatcher");
+      d.stop();
+      RpcDispatcher replacement = new NoopDispatcher();
+      replacement.setRequestMarshaller(d.getRequestMarshaller());
+      replacement.setResponseMarshaller(d.getResponseMarshaller());
+      ReflectionUtil.setValue(rpcManager, "rpcDispatcher", replacement);
+
+      long duration = System.currentTimeMillis() - startTime;
+      log.warn("Started cache.  " + printDuration(duration));
+   }
+
+   public static class NoopDispatcher extends CommandAwareRpcDispatcher
+   {
+      AtomicInteger ai = new AtomicInteger();
+      Marshaller m;
+      Marshaller2 m2;
+
+      @Override
+      public RspList invokeRemoteCommands(Vector<Address> dests, ReplicableCommand command, int mode, long timeout,
+                                          boolean anycasting, boolean oob, RspFilter filter) throws NotSerializableException
+      {
+         // make sure we do the marshalling though
+         if (m == null && m2 == null)
+         {
+            m = getRequestMarshaller();
+            if (m instanceof Marshaller2)
+            {
+               m2 = (Marshaller2) m;
+               m = null;
+            }
+         }
+
+         try
+         {
+            if (m2 == null) m.objectToByteBuffer(command);
+            else m2.objectToBuffer(command);
+         }
+         catch (Exception e)
+         {
+            e.printStackTrace();
+            throw new NotSerializableException(e.getMessage());
+         }
+
+         int i = ai.incrementAndGet();
+         if (i % 1000 == 0) log.warn("Dispatching operation #" + i);
+         // no-op
+         return null;
+      }
+   }
+}

Modified: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java	2008-09-16 18:04:06 UTC (rev 6740)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java	2008-09-16 18:04:26 UTC (rev 6741)
@@ -51,7 +51,7 @@
    private List<Fqn> fqns = new ArrayList<Fqn>(MAX_OVERALL_NODES);
    private Random r = new Random();
 
-   private Log log = LogFactory.getLog(ProfileTest.class);
+   Log log = LogFactory.getLog(ProfileTest.class);
 
    @Test(enabled = false)
    public void testLocalModePess() throws Exception
@@ -193,7 +193,7 @@
    }
 
 
-   private void startup()
+   protected void startup()
    {
       long startTime = System.currentTimeMillis();
       log.warn("Starting cache");
@@ -242,7 +242,8 @@
       log.warn("Finished warmup.  " + printDuration(duration));
       //cache.removeNode(Fqn.ROOT);
       cache.stop();
-      cache.start();
+
+      startup();
    }
 
    private void doTest() throws Exception
@@ -355,7 +356,7 @@
       return sb.toString();
    }
 
-   private String printDuration(long duration)
+   protected String printDuration(long duration)
    {
       if (duration > 2000)
       {




More information about the jbosscache-commits mailing list