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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/lifecycle/InvokerLifecycleTestCase.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.lifecycle;
 
24
 
 
25
import junit.framework.TestCase;
 
26
import org.jboss.remoting.InvalidConfigurationException;
 
27
import org.jboss.remoting.InvokerLocator;
 
28
import org.jboss.remoting.transport.Connector;
 
29
import org.jboss.remoting.transport.PortUtil;
 
30
 
 
31
import java.net.InetAddress;
 
32
import java.net.ServerSocket;
 
33
 
 
34
/**
 
35
 * @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
 
36
 */
 
37
public class InvokerLifecycleTestCase extends TestCase
 
38
{
 
39
   public InvokerLifecycleTestCase(String name)
 
40
   {
 
41
      super(name);
 
42
   }
 
43
 
 
44
   public void testMultipleConnectors() throws Exception
 
45
   {
 
46
      InvokerLocator serverLocator = new InvokerLocator("socket://localhost:2222");
 
47
      Connector connector1 = new Connector();
 
48
      connector1.setInvokerLocator(serverLocator.getLocatorURI());
 
49
      connector1.start();
 
50
 
 
51
      Connector connector2 = new Connector();
 
52
      connector2.setInvokerLocator(serverLocator.getLocatorURI());
 
53
 
 
54
      try
 
55
      {
 
56
         connector2.start();
 
57
      }
 
58
      catch(InvalidConfigurationException ice)
 
59
      {
 
60
         assertTrue("Got InvalidConfigurationException as expected.", true);
 
61
         return;
 
62
      }
 
63
      finally
 
64
      {
 
65
         connector1.stop();
 
66
         connector2.stop();
 
67
      }
 
68
 
 
69
      assertTrue("Did not get InvalidConfiguration which was NOT expected.", false);
 
70
   }
 
71
 
 
72
   public void testNonConcurrentConnectors() throws Exception
 
73
   {
 
74
      String defaultHost = InetAddress.getLocalHost().getHostName();
 
75
      String host = System.getProperty("jrunit.bind_addr", defaultHost);
 
76
      int port = PortUtil.findFreePort(host);
 
77
      InvokerLocator serverLocator = new InvokerLocator("socket://" + host + ":" + port);
 
78
      Connector connector1 = new Connector();
 
79
      connector1.setInvokerLocator(serverLocator.getLocatorURI());
 
80
      connector1.start();
 
81
      connector1.stop();
 
82
 
 
83
      Connector connector2 = new Connector();
 
84
      connector2.setInvokerLocator(serverLocator.getLocatorURI());
 
85
 
 
86
      try
 
87
      {
 
88
         connector2.start();
 
89
      }
 
90
      catch(InvalidConfigurationException ice)
 
91
      {
 
92
         assertTrue("Got InvalidConfigurationException which was unexpected.", false);
 
93
         return;
 
94
      }
 
95
      finally
 
96
      {
 
97
         connector2.stop();
 
98
      }
 
99
 
 
100
      assertTrue("Did not get InvalidConfiguration which is as expected.", true);
 
101
 
 
102
   }
 
103
 
 
104
   public void testStopConnector() throws Exception
 
105
   {
 
106
      // secure a server port to ensure is not available to connector
 
107
      InetAddress inetAddress = InetAddress.getByName("localhost");
 
108
      ServerSocket socket = new ServerSocket(3333, 0, inetAddress);
 
109
 
 
110
      String locatorURI = "socket://localhost:3333/?reuseAddress=false";
 
111
      InvokerLocator serverLocator = new InvokerLocator(locatorURI);
 
112
      Connector connector = new Connector(serverLocator);
 
113
      try
 
114
      {
 
115
         connector.start();
 
116
         assertTrue("Should not have been able to start connector.  Should have gotten bind exception.", false);
 
117
      }
 
118
      catch (Exception e)
 
119
      {
 
120
         System.out.println("Got exception as expected.");
 
121
      }
 
122
      connector.stop();
 
123
 
 
124
      // have stopped, so free up port and restart
 
125
      socket.close();
 
126
 
 
127
      // should not be able to start
 
128
      connector.start();
 
129
 
 
130
      // startup must have been ok, now need to take down
 
131
      connector.stop();
 
132
      connector.destroy();
 
133
 
 
134
      // start the whole process over
 
135
      socket = new ServerSocket(3333, 0, inetAddress);
 
136
      connector = new Connector(serverLocator);
 
137
      try
 
138
      {
 
139
         connector.start();
 
140
         assertTrue("Should not have been able to start connector.  Should have gotten bind exception.", false);
 
141
      }
 
142
      catch (Exception e)
 
143
      {
 
144
         System.out.println("Got exception as expected.");
 
145
      }
 
146
      connector.stop();
 
147
      // this time, are also going to explicitly call destroy
 
148
      connector.destroy();
 
149
 
 
150
      // now close socket to release hold on port
 
151
      socket.close();
 
152
      Connector connector2 = new Connector(serverLocator);
 
153
      connector2.start();
 
154
      assertTrue("Able to start second connector.", true);
 
155
 
 
156
 
 
157
   }
 
158
}
 
 
b'\\ No newline at end of file'