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.
23
package org.jboss.test.remoting.configuration;
25
import junit.framework.TestCase;
26
import org.jboss.remoting.Client;
27
import org.jboss.remoting.InvokerLocator;
28
import org.jboss.remoting.InvokerRegistry;
29
import org.jboss.remoting.ServerInvoker;
30
import org.jboss.remoting.transport.Connector;
31
import org.jboss.remoting.transport.PortUtil;
32
import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
33
import org.w3c.dom.Document;
35
import javax.xml.parsers.DocumentBuilderFactory;
36
import java.io.ByteArrayInputStream;
37
import java.net.InetAddress;
41
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
43
public class SocketClientConfigurationTestCase extends TestCase
45
private String transport = "socket";
46
private int serverPort = 6666;
47
private int clientPort = 7777;
48
private String hostName = null;
49
private String hostIP = null;
50
private Connector connector = null;
52
public void setUp() throws Exception
54
hostName = InetAddress.getLocalHost().getHostName();
55
hostIP = InetAddress.getLocalHost().getHostAddress();
57
connector = new Connector();
58
StringBuffer buf = new StringBuffer();
59
buf.append("<?xml version=\"1.0\"?>\n");
60
buf.append("<config>");
61
buf.append("<invoker transport=\"" + transport + "\">");
62
buf.append("<attribute name=\"numAcceptThreads\">1</attribute>");
63
buf.append("<attribute name=\"maxPoolSize\">303</attribute>");
64
buf.append("<attribute name=\"clientMaxPoolSize\" isParam=\"true\">304</attribute>");
65
buf.append("<attribute name=\"timeout\">60000</attribute>");
66
buf.append("<attribute name=\"serverBindAddress\">" + hostName + "</attribute>");
67
buf.append("<attribute name=\"serverBindPort\">" + serverPort + "</attribute>");
68
buf.append("<attribute name=\"clientConnectAddress\">" + hostIP + "</attribute>");
69
buf.append("<attribute name=\"clientConnectPort\">" + clientPort + "</attribute>");
70
buf.append("<attribute name=\"enableTcpNoDelay\" isParam=\"true\">false</attribute>");
71
buf.append("<attribute name=\"backlog\">200</attribute>");
72
buf.append("</invoker>");
73
buf.append("<handlers>");
74
buf.append(" <handler subsystem=\"mock\">" + MockServerInvocationHandler.class.getName() + "</handler>\n");
75
buf.append("</handlers>");
76
buf.append("</config>");
77
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(buf.toString().getBytes()));
78
//connector.setInvokerLocator(locator.getLocatorURI());
79
connector.setConfiguration(xml.getDocumentElement());
82
Thread.currentThread().sleep(2000);
86
public void testClientConfiguration() throws Exception
89
// make sure the client's view of the locator will be as configured
90
ServerInvoker[] serverInvokers = InvokerRegistry.getServerInvokers();
92
if(serverInvokers != null && serverInvokers.length > 0)
94
InvokerLocator locator = serverInvokers[0].getLocator();
95
String locatorHost = locator.getHost();
96
int locatorPort = locator.getPort();
98
System.out.println("locator host = " + locatorHost);
99
System.out.println("locator port = " + locatorPort);
100
assertEquals(hostIP, locatorHost);
101
assertEquals(clientPort, locatorPort);
104
// check for server bind port (assume is the server since no exception thrown before)
105
boolean portAvailable = PortUtil.checkPort(serverPort, hostName);
106
assertTrue(!portAvailable);
108
// make sure can call ont
109
Client client = new Client(new InvokerLocator(transport + "://" + hostName + ":" + serverPort));
111
String param = "foobar";
115
ret = client.invoke(param);
117
catch(Throwable throwable)
119
throw new Exception("Call on server failed.", throwable);
121
assertEquals(param, ret);
125
public void tearDown() throws Exception
127
if(connector != null)
134
public static void main(String[] args)
136
SocketClientConfigurationTestCase testCase = new SocketClientConfigurationTestCase();
140
testCase.testClientConfiguration();
b'\\ No newline at end of file'