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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/util/PortUtilRangeOnClientTestCase.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.Client;
 
33
import org.jboss.remoting.InvokerLocator;
 
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 PortUtilRangeOnClientTestCase extends TestCase
 
46
{
 
47
   private static Logger log = Logger.getLogger(PortUtilRangeOnClientTestCase.class);
 
48
 
 
49
   
 
50
   public void testUpdateRangeOnClient() throws Exception
 
51
   {
 
52
      log.info("entering " + getName());
 
53
      
 
54
      // Test initial values.
 
55
      assertEquals(1024, PortUtil.getMinPort());
 
56
      assertEquals(65535, PortUtil.getMaxPort());
 
57
      
 
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());
 
67
      
 
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());
 
74
      
 
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());
 
82
      
 
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());
 
90
      
 
91
      // Try to set invalid minPort - should have no effect.
 
92
      clientConfig.put(PortUtil.MIN_PORT, "60000");
 
93
      clientConfig.remove(PortUtil.MAX_PORT);
 
94
      try
 
95
      {
 
96
         log.info("=====================================");
 
97
         log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
 
98
         client = new Client(locator, clientConfig);
 
99
      }
 
100
      catch (Exception e)
 
101
      {
 
102
         log.info(e.getMessage());
 
103
         if (e instanceof IllegalStateException
 
104
               && e.getMessage() != null
 
105
               && e.getMessage().startsWith("trying to set minPort"))
 
106
         {
 
107
            log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
 
108
            log.info("=====================================");
 
109
         }
 
110
         else
 
111
         {
 
112
            fail("expected IllegalStateException");
 
113
         }
 
114
      }
 
115
      assertEquals(4000, PortUtil.getMinPort());
 
116
      assertEquals(40000, PortUtil.getMaxPort());
 
117
      
 
118
      // Try to set invalid maxPort - should have no effect.
 
119
      clientConfig.remove(PortUtil.MIN_PORT);
 
120
      clientConfig.put(PortUtil.MAX_PORT, "2000");
 
121
      try
 
122
      {
 
123
         log.info("=====================================");
 
124
         log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
 
125
         client = new Client(locator, clientConfig);
 
126
      }
 
127
      catch (Exception e)
 
128
      {
 
129
         log.info(e.getMessage());
 
130
         if (e instanceof IllegalStateException
 
131
               && e.getMessage() != null
 
132
               && e.getMessage().startsWith("trying to set maxPort"))
 
133
         {
 
134
            log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
 
135
            log.info("=====================================");
 
136
         }
 
137
         else
 
138
         {
 
139
            fail("expected IllegalStateException");
 
140
         }
 
141
      }
 
142
      assertEquals(4000, PortUtil.getMinPort());
 
143
      assertEquals(40000, PortUtil.getMaxPort());
 
144
      
 
145
      log.info(getName()+ " PASSES");
 
146
   }
 
147
 
 
148
}
 
 
b'\\ No newline at end of file'