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.shutdown;
24
import java.net.InetAddress;
25
import java.util.HashMap;
28
import junit.framework.TestCase;
30
import org.apache.log4j.Logger;
31
import org.jboss.remoting.Client;
32
import org.jboss.remoting.InvokerLocator;
35
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
36
* @version $Revision: 3011 $
38
* Copyright Jan 19, 2007
41
public class OpenClient extends TestCase
43
private static Logger log = Logger.getLogger(OpenClient.class);
44
private String transport;
45
private Map extraConfig;
46
private Client client;
49
public OpenClient(String transport, Map config)
51
this.transport = transport;
52
this.extraConfig = new HashMap(config);
53
log.info("client transport: " + transport);
54
Runtime.getRuntime().traceMethodCalls(true);
59
* This test is used to verify that a server can shut down even if a client does not.
61
public void testShutdown() throws Throwable
65
String host = InetAddress.getLocalHost().getHostAddress();
66
String portString = System.getProperty("port");
67
int port = Integer.parseInt(portString);
68
String locatorURI = transport + "://" + host + ":" + port;
69
InvokerLocator locator = new InvokerLocator(locatorURI);
70
HashMap clientConfig = new HashMap(extraConfig);
71
client = new Client(locator, clientConfig);
73
log.info("client connected");
76
for (int i = 0; i < 5; i++)
78
new InvokerThread(i).start();
81
log.info("going to sleep");
82
log.info("*******************************************************");
83
log.info("**************** EXPECT EXCEPTIONS ****************");
84
log.info("*******************************************************");
86
log.info("calling disconnect()");
88
log.info("client disconnected");
92
log.info("exception in client: " + e);
98
protected void addCallbackArgs(Map map)
104
protected static void getConfig(Map config, String configs)
107
int ampersand = configs.indexOf('&');
108
while (ampersand > 0)
110
String s = configs.substring(start, ampersand);
111
int equals = s.indexOf('=');
112
String param = s.substring(0, equals);
113
String value = s.substring(equals + 1);
114
config.put(param, value);
115
start = ampersand + 1;
116
ampersand = configs.indexOf('&', start);
121
public static void main(String[] args)
125
if (args.length == 0)
126
throw new RuntimeException();
128
String transport = args[0];
130
HashMap config = new HashMap();
131
System.out.println("args.length: " + args.length);
133
getConfig(config, args[1]);
135
OpenClient client = new OpenClient(transport, config);
136
client.testShutdown();
145
public class InvokerThread extends Thread
149
public InvokerThread(int id)
152
setName("InvokerThread:" + id);
159
log.info("client " + id + " making invocation");
160
client.invoke(new Integer(id));
161
log.info("client " + id + " made invocation");