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.lifecycle;
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;
31
import java.net.InetAddress;
32
import java.net.ServerSocket;
35
* @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
37
public class InvokerLifecycleTestCase extends TestCase
39
public InvokerLifecycleTestCase(String name)
44
public void testMultipleConnectors() throws Exception
46
InvokerLocator serverLocator = new InvokerLocator("socket://localhost:2222");
47
Connector connector1 = new Connector();
48
connector1.setInvokerLocator(serverLocator.getLocatorURI());
51
Connector connector2 = new Connector();
52
connector2.setInvokerLocator(serverLocator.getLocatorURI());
58
catch(InvalidConfigurationException ice)
60
assertTrue("Got InvalidConfigurationException as expected.", true);
69
assertTrue("Did not get InvalidConfiguration which was NOT expected.", false);
72
public void testNonConcurrentConnectors() throws Exception
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());
83
Connector connector2 = new Connector();
84
connector2.setInvokerLocator(serverLocator.getLocatorURI());
90
catch(InvalidConfigurationException ice)
92
assertTrue("Got InvalidConfigurationException which was unexpected.", false);
100
assertTrue("Did not get InvalidConfiguration which is as expected.", true);
104
public void testStopConnector() throws Exception
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);
110
String locatorURI = "socket://localhost:3333/?reuseAddress=false";
111
InvokerLocator serverLocator = new InvokerLocator(locatorURI);
112
Connector connector = new Connector(serverLocator);
116
assertTrue("Should not have been able to start connector. Should have gotten bind exception.", false);
120
System.out.println("Got exception as expected.");
124
// have stopped, so free up port and restart
127
// should not be able to start
130
// startup must have been ok, now need to take down
134
// start the whole process over
135
socket = new ServerSocket(3333, 0, inetAddress);
136
connector = new Connector(serverLocator);
140
assertTrue("Should not have been able to start connector. Should have gotten bind exception.", false);
144
System.out.println("Got exception as expected.");
147
// this time, are also going to explicitly call destroy
150
// now close socket to release hold on port
152
Connector connector2 = new Connector(serverLocator);
154
assertTrue("Able to start second connector.", true);
b'\\ No newline at end of file'