1
package org.jboss.test.remoting.invoker;
4
import java.net.InetAddress;
5
import java.util.HashMap;
8
import javax.management.MBeanServer;
10
import junit.framework.TestCase;
12
import org.apache.log4j.ConsoleAppender;
13
import org.apache.log4j.Level;
14
import org.apache.log4j.Logger;
15
import org.apache.log4j.PatternLayout;
16
import org.jboss.logging.XLevel;
17
import org.jboss.remoting.Client;
18
import org.jboss.remoting.InvocationRequest;
19
import org.jboss.remoting.InvokerLocator;
20
import org.jboss.remoting.ServerInvocationHandler;
21
import org.jboss.remoting.ServerInvoker;
22
import org.jboss.remoting.callback.InvokerCallbackHandler;
23
import org.jboss.remoting.transport.Connector;
24
import org.jboss.remoting.transport.PortUtil;
28
* Demonstrates the cost of recreating a client invoker with each invocation.
31
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
32
* @version $Revision: 1.1 $
34
* Copyright Feb 23, 2008
37
public class InvokerDestructionTest extends TestCase
39
private static Logger log = Logger.getLogger(InvokerDestructionTest.class);
41
private static boolean firstTime = true;
42
protected static String metadata;
44
protected String host;
46
protected String locatorURI;
47
protected InvokerLocator serverLocator;
48
protected Connector connector;
49
protected TestInvocationHandler invocationHandler;
52
public void setUp() throws Exception
57
Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
58
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
59
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
60
PatternLayout layout = new PatternLayout(pattern);
61
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
62
Logger.getRootLogger().addAppender(consoleAppender);
63
metadata = System.getProperty("remoting.metadata", "serializationtype=java");
68
public void tearDown()
74
public void testNoDelay() throws Throwable
76
log.info("entering " + getName());
82
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
83
HashMap clientConfig = new HashMap();
84
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
85
addExtraClientConfig(clientConfig);
87
long l1 = doTest(clientLocator, clientConfig, 10000);
88
log.info("delay 0: " + l1);
91
log.info(getName() + " PASSES");
95
public void testDelay() throws Throwable
97
log.info("entering " + getName());
103
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
104
HashMap clientConfig = new HashMap();
105
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
106
addExtraClientConfig(clientConfig);
108
long l1 = doTest(clientLocator, clientConfig, 10000);
109
log.info("delay 5000: " + l1);
112
log.info(getName() + " PASSES");
116
protected long doTest(InvokerLocator locator, Map config, int count) throws Throwable
118
long start = System.currentTimeMillis();
119
for (int i = 0; i < count; i++)
121
Client client = new Client(locator, config);
123
client.invoke("abc");
126
return System.currentTimeMillis() - start;
129
protected String getTransport()
135
protected void addExtraClientConfig(Map config) {}
136
protected void addExtraServerConfig(Map config) {}
139
protected void setupServer(int delay) throws Exception
141
host = InetAddress.getLocalHost().getHostAddress();
142
port = PortUtil.findFreePort(host);
143
locatorURI = getTransport() + "://" + host + ":" + port;
144
locatorURI += "/?" + Client.INVOKER_DESTRUCTION_DELAY + "=" + delay;
145
serverLocator = new InvokerLocator(locatorURI);
146
log.info("Starting remoting server with locator uri of: " + locatorURI);
147
HashMap config = new HashMap();
148
config.put(InvokerLocator.FORCE_REMOTE, "true");
149
addExtraServerConfig(config);
150
connector = new Connector(serverLocator, config);
152
invocationHandler = new TestInvocationHandler();
153
connector.addInvocationHandler("test", invocationHandler);
158
protected void shutdownServer() throws Exception
160
if (connector != null)
165
static class TestInvocationHandler implements ServerInvocationHandler
167
public void addListener(InvokerCallbackHandler callbackHandler) {}
168
public Object invoke(final InvocationRequest invocation) throws Throwable
170
return invocation.getParameter();
172
public void removeListener(InvokerCallbackHandler callbackHandler) {}
173
public void setMBeanServer(MBeanServer server) {}
174
public void setInvoker(ServerInvoker invoker) {}
b'\\ No newline at end of file'