Author: ron.sigal(a)jboss.com
Date: 2011-02-28 17:01:15 -0500 (Mon, 28 Feb 2011)
New Revision: 6262
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java
Log:
JBREM-1275: Added three tests.
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java
===================================================================
---
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java 2011-02-28
22:00:42 UTC (rev 6261)
+++
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/dos/DosTestCase.java 2011-02-28
22:01:15 UTC (rev 6262)
@@ -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 <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
* @version $Rev$
@@ -61,6 +65,8 @@
{
private static final Logger log = Logger.getLogger(DosTestCase.class);
private static final String CALLBACK_TEST = "callbackTest";
+ private static final int dosMaxThreadsValue = 49;
+ private static final int dosTimeoutValue = 59;
private static boolean firstTime = true;
@@ -100,7 +106,7 @@
log.info("entering " + getName());
// Start server.
- setupServer();
+ setupServer(false, false);
// Create client.
HashMap clientConfig = 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_THREADS_DEFAULT).intValue(),
Integer.valueOf(Bisocket.DOS_TIMEOUT_DEFAULT).intValue());
+ 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 useInvokerLocator,
int threadCount, int timeout) throws Throwable
+ {
+ // Start server.
+ setupServer(setParameters, useInvokerLocator);
+
+ // Create client.
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ final Client client = new Client(serverLocator, clientConfig);
+ client.connect();
+ assertEquals("abc", client.invoke("abc"));
+ log.info("client is connected");
+
+ // Add callback handler.
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ HashMap metadata = 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 = (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 threadCount, int
timeout) throws Exception
+ {
+ Class[] classes = BisocketServerInvoker.class.getDeclaredClasses();
+ Class threadClass = null;
+ for (int i = 0; i < classes.length; i++)
+ {
+ if (classes[i].getName().indexOf("SecondaryServerSocketThread") >
-1)
+ {
+ threadClass = classes[i];
+ break;
+ }
+ }
+ log.info("threadClass: " + threadClass);
+ Field field =
BisocketServerInvoker.class.getDeclaredField("secondaryServerSocketThread");
+ field.setAccessible(true);
+ Thread secondaryServerSocketThread = (Thread) field.get(invoker);
+ Field maxThreads = threadClass.getDeclaredField("maxThreads");
+ maxThreads.setAccessible(true);
+ Field localDosTimeout = threadClass.getDeclaredField("localDosTimeout");
+ localDosTimeout.setAccessible(true);
+
+ assertEquals(threadCount,
((Semaphore)maxThreads.get(secondaryServerSocketThread)).permits());
+ assertEquals(timeout,
((Integer)localDosTimeout.get(secondaryServerSocketThread)).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 useInvokerLocator) throws
Exception
{
host = InetAddress.getLocalHost().getHostAddress();
port = PortUtil.findFreePort(host);
@@ -226,11 +318,24 @@
{
locatorURI += "&" + metadata;
}
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
HashMap config = new HashMap();
config.put(InvokerLocator.FORCE_REMOTE, "true");
addExtraServerConfig(config);
+ if (setParameters)
+ {
+ if (useInvokerLocator)
+ {
+ locatorURI += "&" + Bisocket.DOS_MAX_THREADS + "=" +
Integer.toString(dosMaxThreadsValue);
+ locatorURI += "&" + Bisocket.DOS_TIMEOUT + "=" +
Integer.toString(dosTimeoutValue);
+ }
+ else
+ {
+ config.put(Bisocket.DOS_MAX_THREADS, Integer.toString(dosMaxThreadsValue));
+ config.put(Bisocket.DOS_TIMEOUT, Integer.toString(dosTimeoutValue));
+ }
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
connector = new Connector(serverLocator, config);
connector.create();
invocationHandler = new TestInvocationHandler();