2
* JBoss, Home of Professional Open Source
3
* Copyright 2009, 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.util;
25
import java.net.InetAddress;
26
import java.util.HashMap;
29
import junit.framework.TestCase;
31
import org.apache.log4j.Logger;
32
import org.jboss.remoting.Client;
33
import org.jboss.remoting.InvokerLocator;
34
import org.jboss.remoting.transport.PortUtil;
37
* Unit test for JBREM-1139.
39
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
40
* @version $Revision: 2320 $
42
* Copyright July 13, 2009.
45
public class PortUtilRangeOnClientTestCase extends TestCase
47
private static Logger log = Logger.getLogger(PortUtilRangeOnClientTestCase.class);
50
public void testUpdateRangeOnClient() throws Exception
52
log.info("entering " + getName());
54
// Test initial values.
55
assertEquals(1024, PortUtil.getMinPort());
56
assertEquals(65535, PortUtil.getMaxPort());
58
// Set new values using configuration map.
59
Map clientConfig = new HashMap();
60
clientConfig.put(PortUtil.MIN_PORT, "2000");
61
clientConfig.put(PortUtil.MAX_PORT, "60000");
62
String host = InetAddress.getLocalHost().getHostAddress();
63
InvokerLocator locator = new InvokerLocator("socket://" + host);
64
Client client = new Client(locator, clientConfig);
65
assertEquals(2000, PortUtil.getMinPort());
66
assertEquals(60000, PortUtil.getMaxPort());
68
// Set more restrictive values using configuration map.
69
clientConfig.put(PortUtil.MIN_PORT, "3000");
70
clientConfig.put(PortUtil.MAX_PORT, "50000");
71
client = new Client(locator, clientConfig);
72
assertEquals(3000, PortUtil.getMinPort());
73
assertEquals(50000, PortUtil.getMaxPort());
75
// Set more restrictive values with InvokerLocator overriding configuration map.
76
clientConfig.put(PortUtil.MIN_PORT, "3500");
77
clientConfig.put(PortUtil.MAX_PORT, "45000");
78
locator = new InvokerLocator("socket://" + host + "/?" + PortUtil.MIN_PORT + "=4000&" + PortUtil.MAX_PORT + "=40000");
79
client = new Client(locator, clientConfig);
80
assertEquals(4000, PortUtil.getMinPort());
81
assertEquals(40000, PortUtil.getMaxPort());
83
// Try to set less restrictive values - should have no effect.
84
clientConfig.put(PortUtil.MIN_PORT, "2000");
85
clientConfig.put(PortUtil.MAX_PORT, "60000");
86
locator = new InvokerLocator("socket://" + host);
87
client = new Client(locator, clientConfig);
88
assertEquals(4000, PortUtil.getMinPort());
89
assertEquals(40000, PortUtil.getMaxPort());
91
// Try to set invalid minPort - should have no effect.
92
clientConfig.put(PortUtil.MIN_PORT, "60000");
93
clientConfig.remove(PortUtil.MAX_PORT);
96
log.info("=====================================");
97
log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
98
client = new Client(locator, clientConfig);
102
log.info(e.getMessage());
103
if (e instanceof IllegalStateException
104
&& e.getMessage() != null
105
&& e.getMessage().startsWith("trying to set minPort"))
107
log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
108
log.info("=====================================");
112
fail("expected IllegalStateException");
115
assertEquals(4000, PortUtil.getMinPort());
116
assertEquals(40000, PortUtil.getMaxPort());
118
// Try to set invalid maxPort - should have no effect.
119
clientConfig.remove(PortUtil.MIN_PORT);
120
clientConfig.put(PortUtil.MAX_PORT, "2000");
123
log.info("=====================================");
124
log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
125
client = new Client(locator, clientConfig);
129
log.info(e.getMessage());
130
if (e instanceof IllegalStateException
131
&& e.getMessage() != null
132
&& e.getMessage().startsWith("trying to set maxPort"))
134
log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
135
log.info("=====================================");
139
fail("expected IllegalStateException");
142
assertEquals(4000, PortUtil.getMinPort());
143
assertEquals(40000, PortUtil.getMaxPort());
145
log.info(getName()+ " PASSES");
b'\\ No newline at end of file'