2
* JBoss, Home of Professional Open Source.
3
* Copyright 2008, 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.connection.deadlock;
25
import java.net.InetAddress;
26
import java.util.HashMap;
29
import javax.management.MBeanServer;
31
import org.apache.log4j.ConsoleAppender;
32
import org.apache.log4j.Level;
33
import org.apache.log4j.Logger;
34
import org.apache.log4j.PatternLayout;
35
import org.jboss.jrunit.extensions.ServerTestCase;
36
import org.jboss.remoting.Client;
37
import org.jboss.remoting.ConnectionListener;
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.socket.SocketServerInvoker;
47
* Unit test for JBREM-1070.
49
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
52
* Copyright Nov 29, 2008
55
public class DeadlockTestServer extends ServerTestCase
57
private static Logger log = Logger.getLogger(DeadlockTestServer.class);
59
private static boolean firstTime = true;
61
protected String host;
62
protected int port = 7777;
63
protected String locatorURI;
64
protected InvokerLocator serverLocator;
65
protected TestServerInvoker serverInvoker;
66
protected TestInvocationHandler invocationHandler;
69
public static void main(String[] args)
73
DeadlockTestServer server = new DeadlockTestServer();
76
server.shutdownServer();
80
log.error("error", t);
85
public void setUp() throws Exception
90
Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
91
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
92
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
93
PatternLayout layout = new PatternLayout(pattern);
94
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
95
Logger.getRootLogger().addAppender(consoleAppender);
102
public void tearDown() throws Exception
108
protected String getTransport()
114
protected void addExtraClientConfig(Map config) {}
115
protected void addExtraServerConfig(Map config) {}
118
protected void setupServer() throws Exception
120
host = InetAddress.getLocalHost().getHostAddress();
121
locatorURI = getTransport() + "://" + host + ":" + port;
122
String metadata = System.getProperty("remoting.metadata");
123
if (metadata != null)
125
locatorURI += "/?" + metadata;
127
serverLocator = new InvokerLocator(locatorURI);
128
log.info("Starting remoting server with locator uri of: " + locatorURI);
129
HashMap config = new HashMap();
130
config.put(InvokerLocator.FORCE_REMOTE, "true");
131
addExtraServerConfig(config);
133
serverInvoker = new TestServerInvoker(serverLocator, config);
134
serverInvoker.create();
135
invocationHandler = new TestInvocationHandler();
136
serverInvoker.addInvocationHandler("test", invocationHandler);
137
serverInvoker.start();
138
log.info("TestServerInvoker(" + locatorURI + ") started");
142
protected void shutdownServer() throws Exception
144
if (serverInvoker != null)
145
serverInvoker.stop();
149
static class TestInvocationHandler implements ServerInvocationHandler
151
public void addListener(InvokerCallbackHandler callbackHandler) {}
152
public Object invoke(final InvocationRequest invocation) throws Throwable
154
return invocation.getParameter();
156
public void removeListener(InvokerCallbackHandler callbackHandler) {}
157
public void setMBeanServer(MBeanServer server) {}
158
public void setInvoker(ServerInvoker invoker) {}
161
static class TestServerInvoker extends SocketServerInvoker
163
public TestServerInvoker(InvokerLocator locator, Map config)
165
super(locator, config);
166
log.info("TestServerInvoker: " + locator);
168
public Object invoke(InvocationRequest invocation) throws Throwable
170
if ("$PING$".equals(invocation.getParameter()))
172
log.info("TestServerInvoker received $PING$");
174
throw new Exception("got $PING$");
178
return super.invoke(invocation);
183
static class TestConnectionListener implements ConnectionListener
187
public void handleConnectionException(Throwable throwable, Client client)
190
log.info("handleConnectionException() called");
b'\\ No newline at end of file'