From jbosscache-commits at lists.jboss.org Tue Sep 16 14:04:27 2008 Content-Type: multipart/mixed; boundary="===============8091225183669140199==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r6741 - core/trunk/src/test/java/org/jboss/cache/profiling. Date: Tue, 16 Sep 2008 14:04:26 -0400 Message-ID: --===============8091225183669140199== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)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 =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/profiling/MockAsyncReplTest.ja= va (rev 0) +++ core/trunk/src/test/java/org/jboss/cache/profiling/MockAsyncReplTest.ja= va 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 (manik(a)jbo= ss.org) + * @since 3.0 + */ +public class MockAsyncReplTest extends ProfileTest +{ + @Override + @Test(enabled =3D 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 =3D System.currentTimeMillis(); + log.warn("Starting cache"); + cache.start(); + // now remove the existing RpcDispatcher and replace with one that i= s a noop. + ComponentRegistry cr =3D TestingUtil.extractComponentRegistry(cache); + RPCManager rpcManager =3D cr.getComponent(RPCManager.class); + RpcDispatcher d =3D (RpcDispatcher) TestingUtil.extractField(rpcMana= ger, "rpcDispatcher"); + d.stop(); + RpcDispatcher replacement =3D new NoopDispatcher(); + replacement.setRequestMarshaller(d.getRequestMarshaller()); + replacement.setResponseMarshaller(d.getResponseMarshaller()); + ReflectionUtil.setValue(rpcManager, "rpcDispatcher", replacement); + + long duration =3D System.currentTimeMillis() - startTime; + log.warn("Started cache. " + printDuration(duration)); + } + + public static class NoopDispatcher extends CommandAwareRpcDispatcher + { + AtomicInteger ai =3D new AtomicInteger(); + Marshaller m; + Marshaller2 m2; + + @Override + public RspList invokeRemoteCommands(Vector
dests, Replicabl= eCommand command, int mode, long timeout, + boolean anycasting, boolean oob,= RspFilter filter) throws NotSerializableException + { + // make sure we do the marshalling though + if (m =3D=3D null && m2 =3D=3D null) + { + m =3D getRequestMarshaller(); + if (m instanceof Marshaller2) + { + m2 =3D (Marshaller2) m; + m =3D null; + } + } + + try + { + if (m2 =3D=3D null) m.objectToByteBuffer(command); + else m2.objectToBuffer(command); + } + catch (Exception e) + { + e.printStackTrace(); + throw new NotSerializableException(e.getMessage()); + } + + int i =3D ai.incrementAndGet(); + if (i % 1000 =3D=3D 0) log.warn("Dispatching operation #" + i); + // no-op + return null; + } + } +} Modified: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.ja= va =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/profiling/ProfileTest.java 200= 8-09-16 18:04:06 UTC (rev 6740) +++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java 200= 8-09-16 18:04:26 UTC (rev 6741) @@ -51,7 +51,7 @@ private List fqns =3D new ArrayList(MAX_OVERALL_NODES); private Random r =3D new Random(); = - private Log log =3D LogFactory.getLog(ProfileTest.class); + Log log =3D LogFactory.getLog(ProfileTest.class); = @Test(enabled =3D false) public void testLocalModePess() throws Exception @@ -193,7 +193,7 @@ } = = - private void startup() + protected void startup() { long startTime =3D 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) { --===============8091225183669140199==--