~ubuntu-branches/ubuntu/wily/libjboss-remoting-java/wily

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/configuration/SocketClientConfigurationTestCase.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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.
6
 
*
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.
11
 
*
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.
16
 
*
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.
21
 
*/
22
 
 
23
 
package org.jboss.test.remoting.configuration;
24
 
 
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;
34
 
 
35
 
import javax.xml.parsers.DocumentBuilderFactory;
36
 
import java.io.ByteArrayInputStream;
37
 
import java.net.InetAddress;
38
 
 
39
 
 
40
 
/**
41
 
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
42
 
 */
43
 
public class SocketClientConfigurationTestCase extends TestCase
44
 
{
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;
51
 
 
52
 
   public void setUp() throws Exception
53
 
   {
54
 
      hostName = InetAddress.getLocalHost().getHostName();
55
 
      hostIP = InetAddress.getLocalHost().getHostAddress();
56
 
 
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());
80
 
      connector.create();
81
 
      connector.start();
82
 
      Thread.currentThread().sleep(2000);
83
 
 
84
 
   }
85
 
 
86
 
   public void testClientConfiguration() throws Exception
87
 
   {
88
 
 
89
 
      // make sure the client's view of the locator will be as configured
90
 
      ServerInvoker[] serverInvokers = InvokerRegistry.getServerInvokers();
91
 
 
92
 
      if(serverInvokers != null && serverInvokers.length > 0)
93
 
      {
94
 
         InvokerLocator locator = serverInvokers[0].getLocator();
95
 
         String locatorHost = locator.getHost();
96
 
         int locatorPort = locator.getPort();
97
 
 
98
 
         System.out.println("locator host = " + locatorHost);
99
 
         System.out.println("locator port = " + locatorPort);
100
 
         assertEquals(hostIP, locatorHost);
101
 
         assertEquals(clientPort, locatorPort);
102
 
      }
103
 
 
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);
107
 
 
108
 
      // make sure can call ont
109
 
      Client client = new Client(new InvokerLocator(transport + "://" + hostName + ":" + serverPort));
110
 
      client.connect();
111
 
      String param = "foobar";
112
 
      Object ret = null;
113
 
      try
114
 
      {
115
 
         ret = client.invoke(param);
116
 
      }
117
 
      catch(Throwable throwable)
118
 
      {
119
 
         throw new Exception("Call on server failed.", throwable);
120
 
      }
121
 
      assertEquals(param, ret);
122
 
 
123
 
   }
124
 
 
125
 
   public void tearDown() throws Exception
126
 
   {
127
 
      if(connector != null)
128
 
      {
129
 
         connector.stop();
130
 
         connector.destroy();
131
 
      }
132
 
   }
133
 
 
134
 
   public static void main(String[] args)
135
 
   {
136
 
      SocketClientConfigurationTestCase testCase = new SocketClientConfigurationTestCase();
137
 
      try
138
 
      {
139
 
         testCase.setUp();
140
 
         testCase.testClientConfiguration();
141
 
         testCase.tearDown();
142
 
      }
143
 
      catch(Exception e)
144
 
      {
145
 
         e.printStackTrace();
146
 
      }
147
 
   }
148
 
}
 
 
b'\\ No newline at end of file'