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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/util/PortUtilRangeOnServerTestCase.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 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.
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
 
package org.jboss.test.remoting.util;
23
 
 
24
 
 
25
 
import java.net.InetAddress;
26
 
import java.util.HashMap;
27
 
import java.util.Map;
28
 
 
29
 
import junit.framework.TestCase;
30
 
 
31
 
import org.apache.log4j.Logger;
32
 
import org.jboss.remoting.InvokerLocator;
33
 
import org.jboss.remoting.transport.Connector;
34
 
import org.jboss.remoting.transport.PortUtil;
35
 
 
36
 
/** 
37
 
 * Unit test for JBREM-1139.
38
 
 * 
39
 
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
40
 
 * @version $Revision: 2320 $
41
 
 * <p>
42
 
 * Copyright July 13, 2009.
43
 
 * </p>
44
 
 */
45
 
public class PortUtilRangeOnServerTestCase extends TestCase
46
 
{
47
 
   private static Logger log = Logger.getLogger(PortUtilRangeOnServerTestCase.class);
48
 
 
49
 
   
50
 
   
51
 
   public void testUpdateRangeOnServer() throws Exception
52
 
   {
53
 
      log.info("entering " + getName());
54
 
      
55
 
      // Test initial values.
56
 
      assertEquals(1024, PortUtil.getMinPort());
57
 
      assertEquals(65535, PortUtil.getMaxPort());
58
 
      
59
 
      // Set new values using configuration mapr.
60
 
      Map serverConfig = new HashMap();
61
 
      serverConfig.put(PortUtil.MIN_PORT, "2000");
62
 
      serverConfig.put(PortUtil.MAX_PORT, "60000");
63
 
      String host = InetAddress.getLocalHost().getHostAddress();
64
 
      InvokerLocator locator = new InvokerLocator("socket://" + host);
65
 
      Connector connector = new Connector(locator, serverConfig);
66
 
      connector.start();
67
 
      log.info("InvokerLocator: " + connector.getInvokerLocator());
68
 
      assertEquals(2000, PortUtil.getMinPort());
69
 
      assertEquals(60000, PortUtil.getMaxPort());
70
 
      connector.stop();
71
 
      
72
 
      // Set more restrictive values using configuration map.
73
 
      serverConfig.put(PortUtil.MIN_PORT, "3000");
74
 
      serverConfig.put(PortUtil.MAX_PORT, "50000");
75
 
      connector = new Connector(locator, serverConfig);
76
 
      connector.start();
77
 
      log.info("InvokerLocator: " + connector.getInvokerLocator());
78
 
      assertEquals(3000, PortUtil.getMinPort());
79
 
      assertEquals(50000, PortUtil.getMaxPort());
80
 
      connector.stop();
81
 
      
82
 
      // Set more restrictive values with InvokerLocator overriding configuration map.
83
 
      serverConfig.put(PortUtil.MIN_PORT, "3500");
84
 
      serverConfig.put(PortUtil.MAX_PORT, "45000");
85
 
      locator = new InvokerLocator("socket://" + host + "/?" + PortUtil.MIN_PORT + "=4000&" + PortUtil.MAX_PORT + "=40000");
86
 
      connector = new Connector(locator, serverConfig);
87
 
      connector.start();
88
 
      log.info("InvokerLocator: " + connector.getInvokerLocator());
89
 
      assertEquals(4000, PortUtil.getMinPort());
90
 
      assertEquals(40000, PortUtil.getMaxPort());
91
 
      connector.stop();
92
 
      
93
 
      // Try to set less restrictive values - should have no effect.
94
 
      serverConfig.put(PortUtil.MIN_PORT, "2000");
95
 
      serverConfig.put(PortUtil.MAX_PORT, "60000");
96
 
      locator = new InvokerLocator("socket://" + host);
97
 
      connector = new Connector(locator, serverConfig);
98
 
      connector.start();
99
 
      log.info("InvokerLocator: " + connector.getInvokerLocator());
100
 
      assertEquals(4000, PortUtil.getMinPort());
101
 
      assertEquals(40000, PortUtil.getMaxPort());
102
 
      connector.stop();
103
 
      
104
 
      // Try to set invalid minPort - should have no effect.
105
 
      serverConfig.put(PortUtil.MIN_PORT, "60000");
106
 
      serverConfig.remove(PortUtil.MAX_PORT);
107
 
      connector = new Connector(locator, serverConfig);
108
 
      try
109
 
      {
110
 
         log.info("=====================================");
111
 
         log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
112
 
         connector.start();
113
 
      }
114
 
      catch (Exception e)
115
 
      {
116
 
         log.info(e.getCause());
117
 
         if (e.getCause() instanceof IllegalStateException
118
 
               && e.getCause().getMessage() != null
119
 
               && e.getCause().getMessage().startsWith("trying to set minPort"))
120
 
         {
121
 
            log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
122
 
            log.info("=====================================");
123
 
         }
124
 
         else
125
 
         {
126
 
            fail("expected IllegalStateException");
127
 
         }
128
 
      }
129
 
      log.info("InvokerLocator: " + connector.getInvokerLocator());
130
 
      assertEquals(4000, PortUtil.getMinPort());
131
 
      assertEquals(40000, PortUtil.getMaxPort());
132
 
      connector.stop();
133
 
      
134
 
      // Try to set invalid maxPort - should have no effect.
135
 
      serverConfig.remove(PortUtil.MIN_PORT);
136
 
      serverConfig.put(PortUtil.MAX_PORT, "2000");
137
 
      connector = new Connector(locator, serverConfig);
138
 
      try
139
 
      {
140
 
         log.info("=====================================");
141
 
         log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
142
 
         connector.start();
143
 
      }
144
 
      catch (Exception e)
145
 
      {
146
 
         log.info(e.getCause());
147
 
         if (e.getCause() instanceof IllegalStateException
148
 
               && e.getCause().getMessage() != null
149
 
               && e.getCause().getMessage().startsWith("trying to set maxPort"))
150
 
         {
151
 
            log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
152
 
            log.info("=====================================");
153
 
         }
154
 
         else
155
 
         {
156
 
            fail("expected IllegalStateException");
157
 
         }
158
 
      }
159
 
      log.info("InvokerLocator: " + connector.getInvokerLocator());
160
 
      assertEquals(4000, PortUtil.getMinPort());
161
 
      assertEquals(40000, PortUtil.getMaxPort());
162
 
      connector.stop();
163
 
      
164
 
      log.info(getName()+ " PASSES");
165
 
   }
166
 
}
 
 
b'\\ No newline at end of file'