2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, 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.timeout;
24
import java.net.InetAddress;
25
import java.util.HashMap;
28
import javax.management.MBeanServer;
30
import org.apache.log4j.ConsoleAppender;
31
import org.apache.log4j.Logger;
32
import org.apache.log4j.PatternLayout;
33
import org.jboss.jrunit.extensions.ServerTestCase;
34
import org.jboss.logging.XLevel;
35
import org.jboss.remoting.Client;
36
import org.jboss.remoting.ConnectionListener;
37
import org.jboss.remoting.InvocationRequest;
38
import org.jboss.remoting.InvokerLocator;
39
import org.jboss.remoting.ServerInvocationHandler;
40
import org.jboss.remoting.ServerInvoker;
41
import org.jboss.remoting.callback.InvokerCallbackHandler;
42
import org.jboss.remoting.transport.Connector;
43
import org.jboss.remoting.transport.PortUtil;
47
* QuickDisconnectTestParent verifies that LeasePinger can set its
48
* own short timeout value when it is called during Client.disconnect(), so that,
49
* even if the server is unavailable, Client.disconnect() can finish quickly.
51
* It also tests that Client can set its own short timeout value when in
54
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
55
* @version $Revision: 2922 $
57
* Copyright Jan 24, 2007
60
public abstract class QuickDisconnectServerParent extends ServerTestCase
62
public static final String START_SERVER = "startServer";
63
public static final int port = 3999;
65
protected static Logger log = Logger.getLogger(QuickDisconnectServerParent.class);
66
protected static boolean firstTime = true;
68
protected Connector connector;
69
protected boolean receivedConnectionException;
71
public void setUp() throws Exception
73
String host = InetAddress.getLocalHost().getHostAddress();
74
String locatorURI = getTransport() + "://" + host + ":" + port;
75
InvokerLocator locator = new InvokerLocator(locatorURI);
76
HashMap serverConfig = new HashMap();
77
addServerConfig(serverConfig);
78
connector = new Connector(locator, serverConfig);
80
connector.addInvocationHandler("test", new TestHandler());
81
connector.addConnectionListener(new TestListener());
86
public void tearDown()
92
protected abstract String getTransport();
95
protected void addServerConfig(Map config)
100
public class TestHandler implements ServerInvocationHandler
102
public void setMBeanServer(MBeanServer server) {}
103
public void setInvoker(ServerInvoker invoker) {}
105
public Object invoke(InvocationRequest invocation) throws Throwable
107
if (START_SERVER.equals(invocation.getParameter()))
109
int port = PortUtil.findFreePort(InetAddress.getLocalHost().getHostName());
110
new ServerStarter(port).start();
111
return new Integer(port);
115
return invocation.getParameter();
119
public void addListener(InvokerCallbackHandler callbackHandler) {}
120
public void removeListener(InvokerCallbackHandler callbackHandler) {}
124
public class TestListener implements ConnectionListener
126
public void handleConnectionException(Throwable throwable, Client client)
128
log.info("received connection exception");
133
public class ServerStarter extends Thread
137
public ServerStarter(int port)
146
String host = InetAddress.getLocalHost().getHostAddress();
147
String locatorURI = getTransport() + "://" + host + ":" + port;
148
InvokerLocator locator = new InvokerLocator(locatorURI);
149
HashMap serverConfig = new HashMap();
150
addServerConfig(serverConfig);
151
final Connector connector = new Connector(locator, serverConfig);
153
connector.addInvocationHandler("test", new TestHandler());
154
connector.addConnectionListener(new TestListener());
156
log.info("Connector started: " + connector.getInvokerLocator());
159
log.info("Connector stopped: " + connector.getInvokerLocator());