From jboss-remoting-commits at lists.jboss.org Tue Jul 28 16:50:59 2009 Content-Type: multipart/mixed; boundary="===============4538314605835293154==" MIME-Version: 1.0 From: jboss-remoting-commits at lists.jboss.org To: jboss-remoting-commits at lists.jboss.org Subject: [jboss-remoting-commits] JBoss Remoting SVN: r5315 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util. Date: Tue, 28 Jul 2009 16:50:59 -0400 Message-ID: <200907282050.n6SKoxVY017143@svn01.web.mwc.hst.phx2.redhat.com> --===============4538314605835293154== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2009-07-28 16:50:59 -0400 (Tue, 28 Jul 2009) New Revision: 5315 Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRa= ngeOnClientTestCase.java remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRa= ngeOnServerTestCase.java remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRa= ngeOnServerWithXMLTestCase.java Log: JBREM-1139: new unit tests. Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUt= ilRangeOnClientTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilR= angeOnClientTestCase.java (rev 0) +++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilR= angeOnClientTestCase.java 2009-07-28 20:50:59 UTC (rev 5315) @@ -0,0 +1,148 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2009, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +package org.jboss.test.remoting.util; + + +import java.net.InetAddress; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.log4j.Logger; +import org.jboss.remoting.Client; +import org.jboss.remoting.InvokerLocator; +import org.jboss.remoting.transport.PortUtil; + +/** = + * Unit test for JBREM-1139. + * = + * @author Ron Sigal + * @version $Revision: 2320 $ + *
+ * Copyright July 13, 2009. + *
+ */ +public class PortUtilRangeOnClientTestCase extends TestCase +{ + private static Logger log =3D Logger.getLogger(PortUtilRangeOnClientTes= tCase.class); + + = + public void testUpdateRangeOnClient() throws Exception + { + log.info("entering " + getName()); + = + // Test initial values. + assertEquals(1024, PortUtil.getMinPort()); + assertEquals(65535, PortUtil.getMaxPort()); + = + // Set new values using configuration map. + Map clientConfig =3D new HashMap(); + clientConfig.put(PortUtil.MIN_PORT, "2000"); + clientConfig.put(PortUtil.MAX_PORT, "60000"); + String host =3D InetAddress.getLocalHost().getHostAddress(); + InvokerLocator locator =3D new InvokerLocator("socket://" + host); + Client client =3D new Client(locator, clientConfig); + assertEquals(2000, PortUtil.getMinPort()); + assertEquals(60000, PortUtil.getMaxPort()); + = + // Set more restrictive values using configuration map. + clientConfig.put(PortUtil.MIN_PORT, "3000"); + clientConfig.put(PortUtil.MAX_PORT, "50000"); + client =3D new Client(locator, clientConfig); + assertEquals(3000, PortUtil.getMinPort()); + assertEquals(50000, PortUtil.getMaxPort()); + = + // Set more restrictive values with InvokerLocator overriding config= uration map. + clientConfig.put(PortUtil.MIN_PORT, "3500"); + clientConfig.put(PortUtil.MAX_PORT, "45000"); + locator =3D new InvokerLocator("socket://" + host + "/?" + PortUtil= .MIN_PORT + "=3D4000&" + PortUtil.MAX_PORT + "=3D40000"); + client =3D new Client(locator, clientConfig); + assertEquals(4000, PortUtil.getMinPort()); + assertEquals(40000, PortUtil.getMaxPort()); + = + // Try to set less restrictive values - should have no effect. + clientConfig.put(PortUtil.MIN_PORT, "2000"); + clientConfig.put(PortUtil.MAX_PORT, "60000"); + locator =3D new InvokerLocator("socket://" + host); + client =3D new Client(locator, clientConfig); + assertEquals(4000, PortUtil.getMinPort()); + assertEquals(40000, PortUtil.getMaxPort()); + = + // Try to set invalid minPort - should have no effect. + clientConfig.put(PortUtil.MIN_PORT, "60000"); + clientConfig.remove(PortUtil.MAX_PORT); + try + { + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + log.info("EXPECT ILLEGAL_STATE_EXCEPTION"); + client =3D new Client(locator, clientConfig); + } + catch (Exception e) + { + log.info(e.getMessage()); + if (e instanceof IllegalStateException + && e.getMessage() !=3D null + && e.getMessage().startsWith("trying to set minPort")) + { + log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION"); + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + } + else + { + fail("expected IllegalStateException"); + } + } + assertEquals(4000, PortUtil.getMinPort()); + assertEquals(40000, PortUtil.getMaxPort()); + = + // Try to set invalid maxPort - should have no effect. + clientConfig.remove(PortUtil.MIN_PORT); + clientConfig.put(PortUtil.MAX_PORT, "2000"); + try + { + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + log.info("EXPECT ILLEGAL_STATE_EXCEPTION"); + client =3D new Client(locator, clientConfig); + } + catch (Exception e) + { + log.info(e.getMessage()); + if (e instanceof IllegalStateException + && e.getMessage() !=3D null + && e.getMessage().startsWith("trying to set maxPort")) + { + log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION"); + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + } + else + { + fail("expected IllegalStateException"); + } + } + assertEquals(4000, PortUtil.getMinPort()); + assertEquals(40000, PortUtil.getMaxPort()); + = + log.info(getName()+ " PASSES"); + } + +} \ No newline at end of file Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUt= ilRangeOnServerTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilR= angeOnServerTestCase.java (rev 0) +++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilR= angeOnServerTestCase.java 2009-07-28 20:50:59 UTC (rev 5315) @@ -0,0 +1,166 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2009, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +package org.jboss.test.remoting.util; + + +import java.net.InetAddress; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.log4j.Logger; +import org.jboss.remoting.InvokerLocator; +import org.jboss.remoting.transport.Connector; +import org.jboss.remoting.transport.PortUtil; + +/** = + * Unit test for JBREM-1139. + * = + * @author Ron Sigal + * @version $Revision: 2320 $ + *+ * Copyright July 13, 2009. + *
+ */ +public class PortUtilRangeOnServerTestCase extends TestCase +{ + private static Logger log =3D Logger.getLogger(PortUtilRangeOnServerTes= tCase.class); + + = + = + public void testUpdateRangeOnServer() throws Exception + { + log.info("entering " + getName()); + = + // Test initial values. + assertEquals(1024, PortUtil.getMinPort()); + assertEquals(65535, PortUtil.getMaxPort()); + = + // Set new values using configuration mapr. + Map serverConfig =3D new HashMap(); + serverConfig.put(PortUtil.MIN_PORT, "2000"); + serverConfig.put(PortUtil.MAX_PORT, "60000"); + String host =3D InetAddress.getLocalHost().getHostAddress(); + InvokerLocator locator =3D new InvokerLocator("socket://" + host); + Connector connector =3D new Connector(locator, serverConfig); + connector.start(); + log.info("InvokerLocator: " + connector.getInvokerLocator()); + assertEquals(2000, PortUtil.getMinPort()); + assertEquals(60000, PortUtil.getMaxPort()); + connector.stop(); + = + // Set more restrictive values using configuration map. + serverConfig.put(PortUtil.MIN_PORT, "3000"); + serverConfig.put(PortUtil.MAX_PORT, "50000"); + connector =3D new Connector(locator, serverConfig); + connector.start(); + log.info("InvokerLocator: " + connector.getInvokerLocator()); + assertEquals(3000, PortUtil.getMinPort()); + assertEquals(50000, PortUtil.getMaxPort()); + connector.stop(); + = + // Set more restrictive values with InvokerLocator overriding config= uration map. + serverConfig.put(PortUtil.MIN_PORT, "3500"); + serverConfig.put(PortUtil.MAX_PORT, "45000"); + locator =3D new InvokerLocator("socket://" + host + "/?" + PortUtil.= MIN_PORT + "=3D4000&" + PortUtil.MAX_PORT + "=3D40000"); + connector =3D new Connector(locator, serverConfig); + connector.start(); + log.info("InvokerLocator: " + connector.getInvokerLocator()); + assertEquals(4000, PortUtil.getMinPort()); + assertEquals(40000, PortUtil.getMaxPort()); + connector.stop(); + = + // Try to set less restrictive values - should have no effect. + serverConfig.put(PortUtil.MIN_PORT, "2000"); + serverConfig.put(PortUtil.MAX_PORT, "60000"); + locator =3D new InvokerLocator("socket://" + host); + connector =3D new Connector(locator, serverConfig); + connector.start(); + log.info("InvokerLocator: " + connector.getInvokerLocator()); + assertEquals(4000, PortUtil.getMinPort()); + assertEquals(40000, PortUtil.getMaxPort()); + connector.stop(); + = + // Try to set invalid minPort - should have no effect. + serverConfig.put(PortUtil.MIN_PORT, "60000"); + serverConfig.remove(PortUtil.MAX_PORT); + connector =3D new Connector(locator, serverConfig); + try + { + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + log.info("EXPECT ILLEGAL_STATE_EXCEPTION"); + connector.start(); + } + catch (Exception e) + { + log.info(e.getCause()); + if (e.getCause() instanceof IllegalStateException + && e.getCause().getMessage() !=3D null + && e.getCause().getMessage().startsWith("trying to set minP= ort")) + { + log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION"); + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + } + else + { + fail("expected IllegalStateException"); + } + } + log.info("InvokerLocator: " + connector.getInvokerLocator()); + assertEquals(4000, PortUtil.getMinPort()); + assertEquals(40000, PortUtil.getMaxPort()); + connector.stop(); + = + // Try to set invalid maxPort - should have no effect. + serverConfig.remove(PortUtil.MIN_PORT); + serverConfig.put(PortUtil.MAX_PORT, "2000"); + connector =3D new Connector(locator, serverConfig); + try + { + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + log.info("EXPECT ILLEGAL_STATE_EXCEPTION"); + connector.start(); + } + catch (Exception e) + { + log.info(e.getCause()); + if (e.getCause() instanceof IllegalStateException + && e.getCause().getMessage() !=3D null + && e.getCause().getMessage().startsWith("trying to set maxP= ort")) + { + log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION"); + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + } + else + { + fail("expected IllegalStateException"); + } + } + log.info("InvokerLocator: " + connector.getInvokerLocator()); + assertEquals(4000, PortUtil.getMinPort()); + assertEquals(40000, PortUtil.getMaxPort()); + connector.stop(); + = + log.info(getName()+ " PASSES"); + } +} \ No newline at end of file Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUt= ilRangeOnServerWithXMLTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilR= angeOnServerWithXMLTestCase.java (rev 0) +++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilR= angeOnServerWithXMLTestCase.java 2009-07-28 20:50:59 UTC (rev 5315) @@ -0,0 +1,192 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2009, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +package org.jboss.test.remoting.util; + + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.InetAddress; + +import javax.management.MBeanServer; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import junit.framework.TestCase; + +import org.apache.log4j.Logger; +import org.jboss.remoting.InvocationRequest; +import org.jboss.remoting.ServerInvocationHandler; +import org.jboss.remoting.ServerInvoker; +import org.jboss.remoting.callback.InvokerCallbackHandler; +import org.jboss.remoting.transport.Connector; +import org.jboss.remoting.transport.PortUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +/** = + * Unit test for JBREM-1139. + * = + * @author Ron Sigal + * @version $Revision: 2320 $ + *+ * Copyright July 13, 2009. + *
+ */ +public class PortUtilRangeOnServerWithXMLTestCase extends TestCase +{ + private static Logger log =3D Logger.getLogger(PortUtilRangeOnServerWit= hXMLTestCase.class); + + = + = + public void testUpdateRangeOnServer() throws Exception + { + log.info("entering " + getName()); + = + // Test initial values. + assertEquals(1024, PortUtil.getMinPort()); + assertEquals(65535, PortUtil.getMaxPort()); + = + // Set new values. + Connector connector =3D new Connector(); + connector.setConfiguration(getXML(2000, 60000)); + connector.start(); + assertEquals(2000, PortUtil.getMinPort()); + assertEquals(60000, PortUtil.getMaxPort()); + connector.stop(); + = + // Set more restrictive values. + connector =3D new Connector(); + connector.setConfiguration(getXML(3000, 50000)); + connector.start(); + assertEquals(3000, PortUtil.getMinPort()); + assertEquals(50000, PortUtil.getMaxPort()); + connector.stop(); + = + // Try to set less restrictive values - should have no effect. + connector =3D new Connector(); + connector.setConfiguration(getXML(2000, 60000)); + connector.start(); + assertEquals(3000, PortUtil.getMinPort()); + assertEquals(50000, PortUtil.getMaxPort()); + connector.stop(); + = + // Try to set invalid minPort - should have no effect. + connector =3D new Connector(); + connector.setConfiguration(getXML(60000, -1)); + try + { + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + log.info("EXPECT ILLEGAL_STATE_EXCEPTION"); + connector.start(); + } + catch (Exception e) + { + log.info(e.getMessage()); + if (e instanceof IllegalStateException + && e.getMessage() !=3D null + && e.getMessage().startsWith("Error configuring invoker for= connector.")) + { + log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION"); + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + } + else + { + fail("expected IllegalStateException"); + } + } + assertEquals(3000, PortUtil.getMinPort()); + assertEquals(50000, PortUtil.getMaxPort()); + connector.stop(); + = + // Try to set invalid maxPort - should have no effect. + connector =3D new Connector(); + connector.setConfiguration(getXML(-1, 2000)); + try + { + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + log.info("EXPECT ILLEGAL_STATE_EXCEPTION"); + connector.start(); + } + catch (Exception e) + { + log.info(e.getMessage()); + if (e instanceof IllegalStateException + && e.getMessage() !=3D null + && e.getMessage().startsWith("Error configuring invoker for= connector.")) + { + log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION"); + log.info("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D"); + } + else + { + fail("expected IllegalStateException"); + } + } + assertEquals(3000, PortUtil.getMinPort()); + assertEquals(50000, PortUtil.getMaxPort()); + connector.stop(); + = + log.info(getName()+ " PASSES"); + } + = + = + Element getXML(int minPort, int maxPort) throws SAXException, IOExcepti= on, ParserConfigurationException + { + String host =3D InetAddress.getLocalHost().getHostAddress(); + StringBuffer buf =3D new StringBuffer(); + buf.append("\n"); + buf.append("