2
* JBoss, Home of Professional Open Source
3
* Copyright 2009, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* 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.
22
package org.jboss.test.remoting.transport.socket.shutdown;
24
import java.io.IOException;
25
import java.net.InetAddress;
26
import java.security.AccessController;
27
import java.security.PrivilegedAction;
28
import java.util.HashMap;
31
import javax.management.MBeanServer;
33
import junit.framework.TestCase;
35
import org.apache.log4j.ConsoleAppender;
36
import org.apache.log4j.Level;
37
import org.apache.log4j.Logger;
38
import org.apache.log4j.PatternLayout;
39
import org.jboss.remoting.Client;
40
import org.jboss.remoting.InvocationRequest;
41
import org.jboss.remoting.InvokerLocator;
42
import org.jboss.remoting.InvokerRegistry;
43
import org.jboss.remoting.ServerInvocationHandler;
44
import org.jboss.remoting.ServerInvoker;
45
import org.jboss.remoting.callback.InvokerCallbackHandler;
46
import org.jboss.remoting.transport.Connector;
47
import org.jboss.remoting.transport.PortUtil;
48
import org.jboss.remoting.transport.ServerFactory;
49
import org.jboss.remoting.transport.socket.LRUPool;
50
import org.jboss.remoting.transport.socket.SocketServerInvoker;
51
import org.jboss.remoting.transport.socket.TransportClientFactory;
55
* Unit test for JBREM-1076.
57
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
60
* Copyright Apr 12, 2009
63
public class ProcessInvocationShutdownTestCase extends TestCase
65
private static Logger log = Logger.getLogger(ProcessInvocationShutdownTestCase.class);
67
private static boolean firstTime = true;
69
protected String host;
71
protected String locatorURI;
72
protected InvokerLocator serverLocator;
73
protected Connector connector;
74
protected TestInvocationHandler invocationHandler;
75
protected SocketServerInvoker socketServerInvoker;
78
public void setUp() throws Exception
83
Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
84
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
85
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
86
PatternLayout layout = new PatternLayout(pattern);
87
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
88
Logger.getRootLogger().addAppender(consoleAppender);
93
public void tearDown()
98
public void testShutdown() throws Throwable
100
log.info("entering " + getName());
104
assertTrue(connector.getServerInvoker() instanceof TestServerInvoker);
105
log.info("using a TestServerInvoker");
108
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
109
HashMap clientConfig = new HashMap();
110
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
111
addExtraClientConfig(clientConfig);
112
final Client client = new Client(clientLocator, clientConfig);
114
log.info("client is connected");
116
// Start SocketServerInvoker.processInvocation().
123
client.invoke("abc");
135
assertFalse(TestLRUPool.called);
136
log.info(getName() + " PASSES");
140
protected String getTransport()
146
protected void addExtraClientConfig(Map config) {}
147
protected void addExtraServerConfig(Map config) {}
150
protected void setupServer() throws Exception
152
AccessController.doPrivileged( new PrivilegedAction()
156
InvokerRegistry.registerInvokerFactories(getTransport(), TransportClientFactory.class, TestTransportServerFactory.class);
161
host = InetAddress.getLocalHost().getHostAddress();
162
port = PortUtil.findFreePort(host);
163
locatorURI = getTransport() + "://" + host + ":" + port;
164
String metadata = System.getProperty("remoting.metadata");
165
if (metadata != null)
167
locatorURI += "/?" + metadata;
169
serverLocator = new InvokerLocator(locatorURI);
170
log.info("Starting remoting server with locator uri of: " + locatorURI);
171
HashMap config = new HashMap();
172
config.put(InvokerLocator.FORCE_REMOTE, "true");
173
addExtraServerConfig(config);
174
connector = new Connector(serverLocator, config);
176
invocationHandler = new TestInvocationHandler();
177
connector.addInvocationHandler("test", invocationHandler);
179
socketServerInvoker = (SocketServerInvoker) connector.getServerInvoker();
180
socketServerInvoker.setMaxPoolSize(0);
184
protected void shutdownServer() throws Exception
186
if (connector != null)
191
static class TestInvocationHandler implements ServerInvocationHandler
193
public void addListener(InvokerCallbackHandler callbackHandler) {}
194
public Object invoke(final InvocationRequest invocation) throws Throwable
196
return invocation.getParameter();
198
public void removeListener(InvokerCallbackHandler callbackHandler) {}
199
public void setMBeanServer(MBeanServer server) {}
200
public void setInvoker(ServerInvoker invoker) {}
203
static class TestLRUPool extends LRUPool
205
static public boolean called;
207
public TestLRUPool(int min, int max)
211
public void insert(Object key, Object o)
213
log.info(this + ".insert() called");
218
static class TestServerInvoker extends SocketServerInvoker
220
public TestServerInvoker(InvokerLocator locator, Map configuration)
222
super(locator, configuration);
224
public TestServerInvoker(InvokerLocator locator)
228
public synchronized void start() throws IOException
231
clientpool = new TestLRUPool(2, maxPoolSize);
236
static public class TestTransportServerFactory implements ServerFactory
238
public boolean called;
240
public ServerInvoker createServerInvoker(InvokerLocator locator, Map config)
243
log.info(this + ".createServerInvoker() called");
244
return new TestServerInvoker(locator, config);
246
public boolean supportsSSL()
b'\\ No newline at end of file'