2
* JBoss, Home of Professional Open Source.
3
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
4
* as indicated by the @author tags. See the copyright.txt file in the
5
* distribution for a full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.test.remoting.transport.socket.timeout.idle;
25
import java.net.InetAddress;
26
import java.util.HashMap;
29
import javax.management.MBeanServer;
31
import junit.framework.TestCase;
33
import org.apache.log4j.ConsoleAppender;
34
import org.apache.log4j.Level;
35
import org.apache.log4j.Logger;
36
import org.apache.log4j.PatternLayout;
37
import org.jboss.remoting.Client;
38
import org.jboss.remoting.InvocationRequest;
39
import org.jboss.remoting.InvokerLocator;
40
import org.jboss.remoting.ServerInvocationHandler;
41
import org.jboss.remoting.ServerInvoker;
42
import org.jboss.remoting.callback.InvokerCallbackHandler;
43
import org.jboss.remoting.transport.Connector;
44
import org.jboss.remoting.transport.PortUtil;
45
import org.jboss.remoting.transport.socket.SocketServerInvoker;
49
* Unit test for JBREM-1107.
51
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
54
* Copyright Sep 2, 2009
57
public class SafeIdleTimeoutTestCase extends TestCase
59
private static Logger log = Logger.getLogger(SafeIdleTimeoutTestCase.class);
61
private static boolean firstTime = true;
63
protected String host;
65
protected String locatorURI;
66
protected InvokerLocator serverLocator;
67
protected Connector connector;
68
protected TestInvocationHandler invocationHandler;
71
public void setUp() throws Exception
76
Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
77
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
78
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
79
PatternLayout layout = new PatternLayout(pattern);
80
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
81
Logger.getRootLogger().addAppender(consoleAppender);
86
public void tearDown()
91
public void testSafeIdleTimeout() throws Throwable
93
log.info("entering " + getName());
99
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
100
HashMap clientConfig = new HashMap();
101
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
102
clientConfig.put("numberOfCallRetries", "1");
103
addExtraClientConfig(clientConfig);
104
Client client = new Client(clientLocator, clientConfig);
106
log.info("client is connected");
108
// Verify invocation can complete.
109
assertEquals("abc", client.invoke("abc"));
111
// Verify ServerThread was discarded.
112
SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
113
assertEquals(0, serverInvoker.getCurrentClientPoolSize());
114
assertEquals(0, serverInvoker.getCurrentThreadPoolSize());
118
log.info(getName() + " PASSES");
122
protected String getTransport()
128
protected void addExtraClientConfig(Map config) {}
129
protected void addExtraServerConfig(Map config) {}
132
protected void setupServer() throws Exception
134
host = InetAddress.getLocalHost().getHostAddress();
135
port = PortUtil.findFreePort(host);
136
locatorURI = getTransport() + "://" + host + ":" + port + "/?&idleTimeout=2";
137
String metadata = System.getProperty("remoting.metadata");
138
if (metadata != null)
140
locatorURI += "&" + metadata;
142
serverLocator = new InvokerLocator(locatorURI);
143
log.info("Starting remoting server with locator uri of: " + locatorURI);
144
HashMap config = new HashMap();
145
config.put(InvokerLocator.FORCE_REMOTE, "true");
146
addExtraServerConfig(config);
147
connector = new Connector(serverLocator, config);
149
invocationHandler = new TestInvocationHandler();
150
connector.addInvocationHandler("test", invocationHandler);
155
protected void shutdownServer() throws Exception
157
if (connector != null)
162
static class TestInvocationHandler implements ServerInvocationHandler
164
public void addListener(InvokerCallbackHandler callbackHandler) {}
165
public Object invoke(final InvocationRequest invocation) throws Throwable
167
log.info(this + " going to sleep");
169
log.info(this + " has woken up");
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'