From jboss-remoting-commits at lists.jboss.org Mon Feb 28 16:44:13 2011 Content-Type: multipart/mixed; boundary="===============6897037885505817525==" MIME-Version: 1.0 From: jboss-remoting-commits at lists.jboss.org To: jboss-remoting-commits at lists.jboss.org Subject: [jboss-remoting-commits] JBoss Remoting SVN: r6260 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/dos. Date: Mon, 28 Feb 2011 16:44:13 -0500 Message-ID: <201102282144.p1SLiD0G025284@svn01.web.mwc.hst.phx2.redhat.com> --===============6897037885505817525== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2011-02-28 16:44:13 -0500 (Mon, 28 Feb 2011) New Revision: 6260 Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisoc= ket/dos/DosTestCase.java Log: JBREM-1275: Added three tests. Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transpor= t/bisocket/dos/DosTestCase.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 --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/dos/DosTestCase.java 2011-02-28 21:42:51 UTC (rev 6259) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/biso= cket/dos/DosTestCase.java 2011-02-28 21:44:13 UTC (rev 6260) @@ -22,6 +22,7 @@ package org.jboss.test.remoting.transport.bisocket.dos; = import java.io.IOException; +import java.lang.reflect.Field; import java.net.InetAddress; import java.net.Socket; import java.util.HashMap; @@ -49,7 +50,10 @@ import org.jboss.remoting.transport.Connector; import org.jboss.remoting.transport.PortUtil; import org.jboss.remoting.transport.bisocket.Bisocket; +import org.jboss.remoting.transport.bisocket.BisocketServerInvoker; = +import EDU.oswego.cs.dl.util.concurrent.Semaphore; + /** * @author Ron Sigal * @version $Rev$ @@ -61,6 +65,8 @@ { private static final Logger log =3D Logger.getLogger(DosTestCase.class); private static final String CALLBACK_TEST =3D "callbackTest"; + private static final int dosMaxThreadsValue =3D 49; + private static final int dosTimeoutValue =3D 59; = private static boolean firstTime =3D true; = @@ -100,7 +106,7 @@ log.info("entering " + getName()); = // Start server. - setupServer(); + setupServer(false, false); = // Create client. HashMap clientConfig =3D new HashMap(); @@ -205,6 +211,92 @@ connector.stop(); } = + = + public void testConfigurationDefault() throws Throwable + { + log.info("entering " + getName()); + doConfigurationTest(false, false, Integer.valueOf(Bisocket.DOS_MAX_T= HREADS_DEFAULT).intValue(), Integer.valueOf(Bisocket.DOS_TIMEOUT_DEFAULT).i= ntValue()); + log.info(getName() + " PASSES"); + } + + = + public void testConfigurationMap() throws Throwable + { + log.info("entering " + getName()); + doConfigurationTest(true, false, dosMaxThreadsValue, dosTimeoutValue= ); + log.info(getName() + " PASSES"); + } + = + = + public void testConfigurationInvokerLocater() throws Throwable + { + log.info("entering " + getName()); + doConfigurationTest(true, true, dosMaxThreadsValue, dosTimeoutValue); + log.info(getName() + " PASSES"); + } + = + = + protected void doConfigurationTest(boolean setParameters, boolean useIn= vokerLocator, int threadCount, int timeout) throws Throwable + { + // Start server. + setupServer(setParameters, useInvokerLocator); + = + // Create client. + HashMap clientConfig =3D new HashMap(); + clientConfig.put(InvokerLocator.FORCE_REMOTE, "true"); + addExtraClientConfig(clientConfig); + final Client client =3D new Client(serverLocator, clientConfig); + client.connect(); + assertEquals("abc", client.invoke("abc")); + log.info("client is connected"); + = + // Add callback handler. + TestCallbackHandler callbackHandler =3D new TestCallbackHandler(); + HashMap metadata =3D new HashMap(); + metadata.put(Bisocket.IS_CALLBACK_SERVER, "true"); + client.addListener(callbackHandler, metadata); + client.invoke(CALLBACK_TEST); + assertEquals(1, callbackHandler.counter); + log.info("callback handler is installed"); + = + BisocketServerInvoker invoker =3D (BisocketServerInvoker) connector.= getServerInvoker(); + assertEquals(threadCount, invoker.getDosMaxThreads()); + assertEquals(timeout, invoker.getDosTimeout()); + verifyThreadValues(invoker, threadCount, timeout); + + client.removeListener(callbackHandler); + client.disconnect(); + connector.stop(); + } + = + = + protected boolean verifyThreadValues(ServerInvoker invoker, int threadC= ount, int timeout) throws Exception + { + Class[] classes =3D BisocketServerInvoker.class.getDeclaredClasses(); + Class threadClass =3D null; + for (int i =3D 0; i < classes.length; i++) + { + if (classes[i].getName().indexOf("SecondaryServerSocketThread") >= -1) + { + threadClass =3D classes[i]; + break; + } + } + log.info("threadClass: " + threadClass); + Field secondaryServerSocketThreads =3D BisocketServerInvoker.class.g= etDeclaredField("secondaryServerSocketThreads"); + secondaryServerSocketThreads.setAccessible(true); + Thread secondaryServerSocketThread =3D (Thread) ((Set)secondaryServe= rSocketThreads.get(invoker)).iterator().next(); + Field maxThreads =3D threadClass.getDeclaredField("maxThreads"); + maxThreads.setAccessible(true); + Field localDosTimeout =3D threadClass.getDeclaredField("localDosTime= out"); + localDosTimeout.setAccessible(true); + = + assertEquals(threadCount, ((Semaphore)maxThreads.get(secondaryServer= SocketThread)).permits()); + assertEquals(timeout, ((Integer)localDosTimeout.get(secondaryServerS= ocketThread)).intValue()); + return true; + } + = + = protected String getTransport() { return "bisocket"; @@ -215,7 +307,7 @@ protected void addExtraServerConfig(Map config) {} = = - protected void setupServer() throws Exception + protected void setupServer(boolean setParameters, boolean useInvokerLoc= ator) throws Exception { host =3D InetAddress.getLocalHost().getHostAddress(); port =3D PortUtil.findFreePort(host); @@ -226,11 +318,24 @@ { locatorURI +=3D "&" + metadata; } - serverLocator =3D new InvokerLocator(locatorURI); - log.info("Starting remoting server with locator uri of: " + locatorU= RI); HashMap config =3D new HashMap(); config.put(InvokerLocator.FORCE_REMOTE, "true"); addExtraServerConfig(config); + if (setParameters) + { + if (useInvokerLocator) + { + locatorURI +=3D "&" + Bisocket.DOS_MAX_THREADS + "=3D" + Integ= er.toString(dosMaxThreadsValue); + locatorURI +=3D "&" + Bisocket.DOS_TIMEOUT + "=3D" + Integer.t= oString(dosTimeoutValue); + } + else + { + config.put(Bisocket.DOS_MAX_THREADS, Integer.toString(dosMaxTh= readsValue)); + config.put(Bisocket.DOS_TIMEOUT, Integer.toString(dosTimeoutVa= lue)); + } + } + serverLocator =3D new InvokerLocator(locatorURI); + log.info("Starting remoting server with locator uri of: " + locatorU= RI); connector =3D new Connector(serverLocator, config); connector.create(); invocationHandler =3D new TestInvocationHandler(); --===============6897037885505817525==--