JBoss Remoting SVN: r6050 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 22:16:33 -0400 (Wed, 04 Aug 2010)
New Revision: 6050
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnClientTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithXMLTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnClientTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnClientTestCase.java 2010-08-05 02:15:41 UTC (rev 6049)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnClientTestCase.java 2010-08-05 02:16:33 UTC (rev 6050)
@@ -1,148 +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 <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 2320 $
- * <p>
- * Copyright July 13, 2009.
- * </p>
- */
-public class PortUtilRangeOnClientTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(PortUtilRangeOnClientTestCase.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 = new HashMap();
- clientConfig.put(PortUtil.MIN_PORT, "2000");
- clientConfig.put(PortUtil.MAX_PORT, "60000");
- String host = InetAddress.getLocalHost().getHostAddress();
- InvokerLocator locator = new InvokerLocator("socket://" + host);
- Client client = 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 = new Client(locator, clientConfig);
- assertEquals(3000, PortUtil.getMinPort());
- assertEquals(50000, PortUtil.getMaxPort());
-
- // Set more restrictive values with InvokerLocator overriding configuration map.
- clientConfig.put(PortUtil.MIN_PORT, "3500");
- clientConfig.put(PortUtil.MAX_PORT, "45000");
- locator = new InvokerLocator("socket://" + host + "/?" + PortUtil.MIN_PORT + "=4000&" + PortUtil.MAX_PORT + "=40000");
- client = 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 = new InvokerLocator("socket://" + host);
- client = 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("=====================================");
- log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
- client = new Client(locator, clientConfig);
- }
- catch (Exception e)
- {
- log.info(e.getMessage());
- if (e instanceof IllegalStateException
- && e.getMessage() != null
- && e.getMessage().startsWith("trying to set minPort"))
- {
- log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
- log.info("=====================================");
- }
- 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("=====================================");
- log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
- client = new Client(locator, clientConfig);
- }
- catch (Exception e)
- {
- log.info(e.getMessage());
- if (e instanceof IllegalStateException
- && e.getMessage() != null
- && e.getMessage().startsWith("trying to set maxPort"))
- {
- log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
- log.info("=====================================");
- }
- else
- {
- fail("expected IllegalStateException");
- }
- }
- assertEquals(4000, PortUtil.getMinPort());
- assertEquals(40000, PortUtil.getMaxPort());
-
- log.info(getName()+ " PASSES");
- }
-
+/*
+* 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 <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 2320 $
+ * <p>
+ * Copyright July 13, 2009.
+ * </p>
+ */
+public class PortUtilRangeOnClientTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(PortUtilRangeOnClientTestCase.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 = new HashMap();
+ clientConfig.put(PortUtil.MIN_PORT, "2000");
+ clientConfig.put(PortUtil.MAX_PORT, "60000");
+ String host = InetAddress.getLocalHost().getHostAddress();
+ InvokerLocator locator = new InvokerLocator("socket://" + host);
+ Client client = 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 = new Client(locator, clientConfig);
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+
+ // Set more restrictive values with InvokerLocator overriding configuration map.
+ clientConfig.put(PortUtil.MIN_PORT, "3500");
+ clientConfig.put(PortUtil.MAX_PORT, "45000");
+ locator = new InvokerLocator("socket://" + host + "/?" + PortUtil.MIN_PORT + "=4000&" + PortUtil.MAX_PORT + "=40000");
+ client = 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 = new InvokerLocator("socket://" + host);
+ client = 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("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ client = new Client(locator, clientConfig);
+ }
+ catch (Exception e)
+ {
+ log.info(e.getMessage());
+ if (e instanceof IllegalStateException
+ && e.getMessage() != null
+ && e.getMessage().startsWith("trying to set minPort"))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ 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("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ client = new Client(locator, clientConfig);
+ }
+ catch (Exception e)
+ {
+ log.info(e.getMessage());
+ if (e instanceof IllegalStateException
+ && e.getMessage() != null
+ && e.getMessage().startsWith("trying to set maxPort"))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ else
+ {
+ fail("expected IllegalStateException");
+ }
+ }
+ assertEquals(4000, PortUtil.getMinPort());
+ assertEquals(40000, PortUtil.getMaxPort());
+
+ log.info(getName()+ " PASSES");
+ }
+
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnClientTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerTestCase.java 2010-08-05 02:15:41 UTC (rev 6049)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerTestCase.java 2010-08-05 02:16:33 UTC (rev 6050)
@@ -1,166 +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 <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 2320 $
- * <p>
- * Copyright July 13, 2009.
- * </p>
- */
-public class PortUtilRangeOnServerTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(PortUtilRangeOnServerTestCase.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 = new HashMap();
- serverConfig.put(PortUtil.MIN_PORT, "2000");
- serverConfig.put(PortUtil.MAX_PORT, "60000");
- String host = InetAddress.getLocalHost().getHostAddress();
- InvokerLocator locator = new InvokerLocator("socket://" + host);
- Connector connector = 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 = 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 configuration map.
- serverConfig.put(PortUtil.MIN_PORT, "3500");
- serverConfig.put(PortUtil.MAX_PORT, "45000");
- locator = new InvokerLocator("socket://" + host + "/?" + PortUtil.MIN_PORT + "=4000&" + PortUtil.MAX_PORT + "=40000");
- connector = 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 = new InvokerLocator("socket://" + host);
- connector = 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 = new Connector(locator, serverConfig);
- try
- {
- log.info("=====================================");
- log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
- connector.start();
- }
- catch (Exception e)
- {
- log.info(e.getCause());
- if (e.getCause() instanceof IllegalStateException
- && e.getCause().getMessage() != null
- && e.getCause().getMessage().startsWith("trying to set minPort"))
- {
- log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
- log.info("=====================================");
- }
- 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 = new Connector(locator, serverConfig);
- try
- {
- log.info("=====================================");
- log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
- connector.start();
- }
- catch (Exception e)
- {
- log.info(e.getCause());
- if (e.getCause() instanceof IllegalStateException
- && e.getCause().getMessage() != null
- && e.getCause().getMessage().startsWith("trying to set maxPort"))
- {
- log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
- log.info("=====================================");
- }
- else
- {
- fail("expected IllegalStateException");
- }
- }
- log.info("InvokerLocator: " + connector.getInvokerLocator());
- assertEquals(4000, PortUtil.getMinPort());
- assertEquals(40000, PortUtil.getMaxPort());
- connector.stop();
-
- log.info(getName()+ " PASSES");
- }
+/*
+* 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 <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 2320 $
+ * <p>
+ * Copyright July 13, 2009.
+ * </p>
+ */
+public class PortUtilRangeOnServerTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(PortUtilRangeOnServerTestCase.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 = new HashMap();
+ serverConfig.put(PortUtil.MIN_PORT, "2000");
+ serverConfig.put(PortUtil.MAX_PORT, "60000");
+ String host = InetAddress.getLocalHost().getHostAddress();
+ InvokerLocator locator = new InvokerLocator("socket://" + host);
+ Connector connector = 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 = 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 configuration map.
+ serverConfig.put(PortUtil.MIN_PORT, "3500");
+ serverConfig.put(PortUtil.MAX_PORT, "45000");
+ locator = new InvokerLocator("socket://" + host + "/?" + PortUtil.MIN_PORT + "=4000&" + PortUtil.MAX_PORT + "=40000");
+ connector = 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 = new InvokerLocator("socket://" + host);
+ connector = 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 = new Connector(locator, serverConfig);
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.info(e.getCause());
+ if (e.getCause() instanceof IllegalStateException
+ && e.getCause().getMessage() != null
+ && e.getCause().getMessage().startsWith("trying to set minPort"))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ 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 = new Connector(locator, serverConfig);
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.info(e.getCause());
+ if (e.getCause() instanceof IllegalStateException
+ && e.getCause().getMessage() != null
+ && e.getCause().getMessage().startsWith("trying to set maxPort"))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ 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
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithXMLTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithXMLTestCase.java 2010-08-05 02:15:41 UTC (rev 6049)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithXMLTestCase.java 2010-08-05 02:16:33 UTC (rev 6050)
@@ -1,192 +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 <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 2320 $
- * <p>
- * Copyright July 13, 2009.
- * </p>
- */
-public class PortUtilRangeOnServerWithXMLTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(PortUtilRangeOnServerWithXMLTestCase.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 = new Connector();
- connector.setConfiguration(getXML(2000, 60000));
- connector.start();
- assertEquals(2000, PortUtil.getMinPort());
- assertEquals(60000, PortUtil.getMaxPort());
- connector.stop();
-
- // Set more restrictive values.
- connector = 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 = 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 = new Connector();
- connector.setConfiguration(getXML(60000, -1));
- try
- {
- log.info("=====================================");
- log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
- connector.start();
- }
- catch (Exception e)
- {
- log.info(e.getMessage());
- if (e instanceof IllegalStateException
- && e.getMessage() != null
- && e.getMessage().startsWith("Error configuring invoker for connector."))
- {
- log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
- log.info("=====================================");
- }
- else
- {
- fail("expected IllegalStateException");
- }
- }
- assertEquals(3000, PortUtil.getMinPort());
- assertEquals(50000, PortUtil.getMaxPort());
- connector.stop();
-
- // Try to set invalid maxPort - should have no effect.
- connector = new Connector();
- connector.setConfiguration(getXML(-1, 2000));
- try
- {
- log.info("=====================================");
- log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
- connector.start();
- }
- catch (Exception e)
- {
- log.info(e.getMessage());
- if (e instanceof IllegalStateException
- && e.getMessage() != null
- && e.getMessage().startsWith("Error configuring invoker for connector."))
- {
- log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
- log.info("=====================================");
- }
- 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, IOException, ParserConfigurationException
- {
- String host = InetAddress.getLocalHost().getHostAddress();
- StringBuffer buf = new StringBuffer();
- buf.append("<?xml version=\"1.0\"?>\n");
- buf.append("<config>\n");
- buf.append(" <invoker transport=\"socket\">\n");
- buf.append(" <attribute name=\"serverBindAddress\">" + host + "</attribute>\n");
- if (minPort > -1)
- {
- buf.append(" <attribute name=\"" + PortUtil.MIN_PORT + "\">" + minPort + "</attribute>\n");
- }
- if (maxPort > -1)
- {
- buf.append(" <attribute name=\"" + PortUtil.MAX_PORT + "\">" + maxPort + "</attribute>\n");
- }
- buf.append(" </invoker>\n");
- buf.append(" <handlers>\n");
- buf.append(" <handler subsystem=\"test\">" + TestInvocationHandler.class.getName() + "</handler>\n");
- buf.append(" </handlers>\n");
- buf.append("</config>\n");
- log.info("\n\n" + buf.toString());
- ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
- Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
- return xml.getDocumentElement();
- }
-
-
- public static class TestInvocationHandler implements ServerInvocationHandler
- {
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- return invocation.getParameter();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
+/*
+* 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 <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 2320 $
+ * <p>
+ * Copyright July 13, 2009.
+ * </p>
+ */
+public class PortUtilRangeOnServerWithXMLTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(PortUtilRangeOnServerWithXMLTestCase.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 = new Connector();
+ connector.setConfiguration(getXML(2000, 60000));
+ connector.start();
+ assertEquals(2000, PortUtil.getMinPort());
+ assertEquals(60000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Set more restrictive values.
+ connector = 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 = 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 = new Connector();
+ connector.setConfiguration(getXML(60000, -1));
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.info(e.getMessage());
+ if (e instanceof IllegalStateException
+ && e.getMessage() != null
+ && e.getMessage().startsWith("Error configuring invoker for connector."))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ else
+ {
+ fail("expected IllegalStateException");
+ }
+ }
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Try to set invalid maxPort - should have no effect.
+ connector = new Connector();
+ connector.setConfiguration(getXML(-1, 2000));
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.info(e.getMessage());
+ if (e instanceof IllegalStateException
+ && e.getMessage() != null
+ && e.getMessage().startsWith("Error configuring invoker for connector."))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ 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, IOException, ParserConfigurationException
+ {
+ String host = InetAddress.getLocalHost().getHostAddress();
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\"?>\n");
+ buf.append("<config>\n");
+ buf.append(" <invoker transport=\"socket\">\n");
+ buf.append(" <attribute name=\"serverBindAddress\">" + host + "</attribute>\n");
+ if (minPort > -1)
+ {
+ buf.append(" <attribute name=\"" + PortUtil.MIN_PORT + "\">" + minPort + "</attribute>\n");
+ }
+ if (maxPort > -1)
+ {
+ buf.append(" <attribute name=\"" + PortUtil.MAX_PORT + "\">" + maxPort + "</attribute>\n");
+ }
+ buf.append(" </invoker>\n");
+ buf.append(" <handlers>\n");
+ buf.append(" <handler subsystem=\"test\">" + TestInvocationHandler.class.getName() + "</handler>\n");
+ buf.append(" </handlers>\n");
+ buf.append("</config>\n");
+ log.info("\n\n" + buf.toString());
+ ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
+ Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
+ return xml.getDocumentElement();
+ }
+
+
+ public static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithXMLTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 7 months
JBoss Remoting SVN: r6049 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 22:15:41 -0400 (Wed, 04 Aug 2010)
New Revision: 6049
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/SafeIdleTimeoutTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/SafeIdleTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/SafeIdleTimeoutTestCase.java 2010-08-05 02:15:19 UTC (rev 6048)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/SafeIdleTimeoutTestCase.java 2010-08-05 02:15:41 UTC (rev 6049)
@@ -1,177 +1,177 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.transport.socket.timeout.idle;
-
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-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.jboss.remoting.transport.socket.SocketServerInvoker;
-
-
-/**
- * Unit test for JBREM-1107.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright Sep 2, 2009
- * </p>
- */
-public class SafeIdleTimeoutTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(SafeIdleTimeoutTestCase.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testSafeIdleTimeout() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("numberOfCallRetries", "1");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Verify invocation can complete.
- assertEquals("abc", client.invoke("abc"));
-
- // Verify ServerThread was discarded.
- SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
- assertEquals(0, serverInvoker.getCurrentClientPoolSize());
- assertEquals(0, serverInvoker.getCurrentThreadPoolSize());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port + "/?&idleTimeout=2";
- String metadata = System.getProperty("remoting.metadata");
- if (metadata != null)
- {
- locatorURI += "&" + metadata;
- }
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- log.info(this + " going to sleep");
- Thread.sleep(10000);
- log.info(this + " has woken up");
- return invocation.getParameter();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.transport.socket.timeout.idle;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+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.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+/**
+ * Unit test for JBREM-1107.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Sep 2, 2009
+ * </p>
+ */
+public class SafeIdleTimeoutTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(SafeIdleTimeoutTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testSafeIdleTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("numberOfCallRetries", "1");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Verify invocation can complete.
+ assertEquals("abc", client.invoke("abc"));
+
+ // Verify ServerThread was discarded.
+ SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
+ assertEquals(0, serverInvoker.getCurrentClientPoolSize());
+ assertEquals(0, serverInvoker.getCurrentThreadPoolSize());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?&idleTimeout=2";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ log.info(this + " going to sleep");
+ Thread.sleep(10000);
+ log.info(this + " has woken up");
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/SafeIdleTimeoutTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 7 months
JBoss Remoting SVN: r6048 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 22:15:19 -0400 (Wed, 04 Aug 2010)
New Revision: 6048
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketDefaultTimeoutTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java 2010-08-05 02:14:13 UTC (rev 6047)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java 2010-08-05 02:15:19 UTC (rev 6048)
@@ -1,580 +1,580 @@
-/*
-* 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.transport.socket.timeout;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.reflect.Constructor;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.net.UnknownHostException;
-import java.util.Map;
-
-import javax.net.ServerSocketFactory;
-import javax.net.SocketFactory;
-import javax.net.ssl.HandshakeCompletedListener;
-import javax.net.ssl.SSLServerSocket;
-import javax.net.ssl.SSLServerSocketFactory;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
-
-import org.apache.log4j.Logger;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.security.SSLSocketBuilder;
-import org.jboss.remoting.transport.Connector;
-
-
-/**
- * Unit tests for JBREM-1120.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Rev$
- * <p>
- * Copyright Apr 22, 2009
- * </p>
- */
-public abstract class SSLWriteTimeoutTestParent extends WriteTimeoutTestParent
-{
- private static Logger log = Logger.getLogger(SSLWriteTimeoutTestParent.class);
-
- private static boolean firstTime = true;
-
- protected static int SECONDARY_SERVER_SOCKET_PORT = 8765;
- protected static String SECONDARY_SERVER_SOCKET_PORT_STRING = "8765";
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- String keyStoreFilePath = getClass().getResource("../.keystore").getFile();
- System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath);
- System.setProperty("javax.net.ssl.keyStorePassword", "unit-tests-server");
- String trustStoreFilePath = getClass().getResource("../.truststore").getFile();
- System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
- System.setProperty("javax.net.ssl.trustStorePassword", "unit-tests-client");
- }
- super.setUp();
- }
-
-
- protected String getServerSocketFactoryClassName()
- {
- return SSLTestServerSocketFactory.class.getName();
- }
-
- protected Constructor getServerSocketFactoryConstructor() throws NoSuchMethodException
- {
- return SSLTestServerSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
- }
-
- protected String getSocketFactoryClassName()
- {
- return SSLTestSocketFactory.class.getName();
- }
-
- protected Constructor getSocketFactoryConstructor() throws NoSuchMethodException
- {
- return SSLTestSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
- }
-
- static public class SSLTestServerSocketFactory extends ServerSocketFactory
- {
- int timeout;
- ServerSocketFactory factory;
- int initialWrites;
-
- public SSLTestServerSocketFactory() throws IOException
- {
- this.timeout = 5000;
- this.initialWrites = -1;
- setupFactory();
- }
- public SSLTestServerSocketFactory(int timeout, int initialWrites) throws IOException
- {
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- setupFactory();
- }
- public ServerSocket createServerSocket() throws IOException
- {
- ServerSocket ss = null;
- if (callbackTest)
- {
- ss = SSLServerSocketFactory.getDefault().createServerSocket();
- }
- else
- {
- ss = new SSLTestServerSocket(timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
- }
- log.info("returning: " + ss);
- return ss;
- }
- public ServerSocket createServerSocket(int port) throws IOException
- {
- ServerSocket ss = null;
- if (callbackTest && port != secondaryServerSocketPort)
- {
- ss = SSLServerSocketFactory.getDefault().createServerSocket(port);
- }
- else
- {
- ss = new SSLTestServerSocket(port, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
- }
- log.info("returning: " + ss);
- return ss;
- }
-
- public ServerSocket createServerSocket(int port, int backlog) throws IOException
- {
- ServerSocket ss = null;
- if (callbackTest && port != secondaryServerSocketPort)
- {
- ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog);
- }
- else
- {
- ss = new SSLTestServerSocket(port, backlog, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
- }
- log.info("returning: " + ss);
- return ss;
- }
-
- public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
- {
- ServerSocket ss = null;
- if (callbackTest && port != secondaryServerSocketPort)
- {
- ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
- }
- else
- {
- ss = new SSLTestServerSocket(port, backlog, ifAddress, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
- }
- log.info("returning: " + ss);
- return ss;
- }
-
- protected void setupFactory() throws IOException
- {
- SSLSocketBuilder sslSocketBuilder = new SSLSocketBuilder();
- sslSocketBuilder.setUseSSLServerSocketFactory(false);
- factory = sslSocketBuilder.createSSLServerSocketFactory();
- }
- }
-
-
- static class SSLTestServerSocket extends SSLServerSocket
- {
- int timeout;
- int initialWrites;
- SSLServerSocket serverSocket;
-
- public SSLTestServerSocket(int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
- {
- super();
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- this.serverSocket = serverSocket;
- }
- public SSLTestServerSocket(int port, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
- {
- super(port);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- this.serverSocket = serverSocket;
- bind(new InetSocketAddress(port), 50);
- }
- public SSLTestServerSocket(int port, int backlog, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
- {
- super(port, backlog);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- this.serverSocket = serverSocket;
- bind(new InetSocketAddress(port), backlog);
- }
- public SSLTestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
- {
- super(port, backlog, bindAddr);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- this.serverSocket = serverSocket;
- bind(new InetSocketAddress(bindAddr, port), 50);
- }
- public Socket accept() throws IOException
- {
- SSLSocket s1 = (SSLSocket) serverSocket.accept();
- Socket s2 = new SSLTestSocket(timeout, initialWrites, s1);
- return s2;
- }
- public void bind(SocketAddress endpoint, int backlog) throws IOException
- {
- log.info("serverSocket: " + serverSocket);
- if (serverSocket != null) log.info("bound: " + serverSocket.isBound());
- if (serverSocket != null && !serverSocket.isBound())
- {
- log.info("binding " + serverSocket);
- serverSocket.bind(endpoint, backlog);
- }
- }
- public String toString()
- {
- return "SSLTestServerSocket[" + serverSocket.toString() + "]";
- }
- public boolean getEnableSessionCreation()
- {
- return serverSocket.getEnableSessionCreation();
- }
- public String[] getEnabledCipherSuites()
- {
- return serverSocket.getEnabledCipherSuites();
- }
- public String[] getEnabledProtocols()
- {
- return serverSocket.getEnabledProtocols();
- }
- public InetAddress getInetAddress()
- {
- return serverSocket.getInetAddress();
- }
- public boolean getNeedClientAuth()
- {
- return serverSocket.getNeedClientAuth();
- }
- public String[] getSupportedCipherSuites()
- {
- return serverSocket.getSupportedCipherSuites();
- }
- public String[] getSupportedProtocols()
- {
- return serverSocket.getSupportedProtocols();
- }
- public boolean getUseClientMode()
- {
- return serverSocket.getUseClientMode();
- }
- public boolean getWantClientAuth()
- {
- return serverSocket.getWantClientAuth();
- }
- public void setEnableSessionCreation(boolean arg0)
- {
- serverSocket.setEnableSessionCreation(arg0);
- }
- public void setEnabledCipherSuites(String[] arg0)
- {
- serverSocket.setEnabledCipherSuites(arg0);
- }
- public void setEnabledProtocols(String[] arg0)
- {
- serverSocket.setEnabledProtocols(arg0);
- }
- public void setNeedClientAuth(boolean arg0)
- {
- serverSocket.setNeedClientAuth(arg0);
- }
- public void setUseClientMode(boolean arg0)
- {
- serverSocket.setUseClientMode(arg0);
- }
- public void setWantClientAuth(boolean arg0)
- {
- serverSocket.setWantClientAuth(arg0);
- }
- }
-
-
- public static class SSLTestSocketFactory extends SocketFactory
- {
- int timeout;
- int initialWrites;
- SocketFactory factory;
-
- public SSLTestSocketFactory() throws IOException
- {
- timeout = 5000;
- initialWrites = -1;
- setupFactory();
- }
- public SSLTestSocketFactory(int timeout, int initialWrites) throws IOException
- {
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- setupFactory();
- }
- public Socket createSocket() throws IOException
- {
- log.info("callbackTest: " + callbackTest);
- Socket s = null;
- if (callbackTest)
- {
- s = factory.createSocket();
- }
- else
- {
- s = new TestSocket(timeout, initialWrites);
- s = new SSLTestSocket(timeout, initialWrites, ((SSLSocket) factory.createSocket()));
- }
- log.info(this + " returning " + s);
- return s;
- }
- public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
- {
- log.info("callbackTest: " + callbackTest);
- Socket s = null;
- if (callbackTest && arg1 != secondaryServerSocketPort)
- {
- s = factory.createSocket(arg0, arg1);
- }
- else
- {
- s = new TestSocket(timeout, initialWrites);
- s = new SSLTestSocket(arg0, arg1, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
- }
- log.info(this + " returning " + s);
- return s;
- }
-
- public Socket createSocket(InetAddress arg0, int arg1) throws IOException
- {
- log.info("callbackTest: " + callbackTest);
- Socket s = null;
- if (callbackTest && arg1 != secondaryServerSocketPort)
- {
- s = factory.createSocket(arg0, arg1);
- }
- else
- {
- s = new TestSocket(timeout, initialWrites);
- s = new SSLTestSocket(arg0, arg1, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
- }
- log.info(this + " returning " + s);
- return s;
- }
-
- public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
- {
- log.info("callbackTest: " + callbackTest);
- Socket s = null;
- if (callbackTest && arg1 != secondaryServerSocketPort)
- {
- s = factory.createSocket(arg0, arg1);
- }
- else
- {
- s = new TestSocket(timeout, initialWrites);
- s = new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
- }
- log.info(this + " returning " + s);
- return s;
- }
-
- public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
- {
- log.info("callbackTest: " + callbackTest);
- Socket s = null;
- if (callbackTest && arg1 != secondaryServerSocketPort)
- {
- s = factory.createSocket(arg0, arg1);
- }
- else
- {
- s = new TestSocket(timeout, initialWrites);
- s = new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
- }
- log.info(this + " returning " + s);
- return s;
- }
-
- protected void setupFactory() throws IOException
- {
- SSLSocketBuilder sslSocketBuilder = new SSLSocketBuilder();
- sslSocketBuilder.setUseSSLServerSocketFactory(false);
- factory = sslSocketBuilder.createSSLSocketFactory();
- }
- }
-
- static class SSLTestSocket extends SSLSocket
- {
- int timeout;
- int initialWrites;
- SSLSocket socket;
- SocketAddress endpoint;
-
- public SSLTestSocket(int timeout, int initialWrites, SSLSocket socket)
- {
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- this.socket = socket;
- }
- public SSLTestSocket(String host, int port, int timeout, int initialWrites, SSLSocket socket) throws UnknownHostException, IOException
- {
- super(host, port);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- this.socket = socket;
- connect(new InetSocketAddress(host, port), timeout);
- }
- public SSLTestSocket(InetAddress address, int port, int timeout, int initialWrites, SSLSocket socket) throws IOException
- {
- super(address, port);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- this.socket = socket;
- connect(new InetSocketAddress(address, port), timeout);
- }
- public SSLTestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) throws IOException
- {
- super(host, port, localAddr, localPort);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- this.socket = socket;
- bind(new InetSocketAddress(localAddr, localPort));
- connect(new InetSocketAddress(host, port), timeout);
- }
- public SSLTestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) throws IOException
- {
- super(address, port, localAddr, localPort);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- this.socket = socket;
- bind(new InetSocketAddress(localAddr, localPort));
- connect(new InetSocketAddress(address, port), timeout);
- }
- public String toString()
- {
- return "SSLTestSocket[" + socket.toString() + "]";
- }
- public InputStream getInputStream() throws IOException
- {
- return socket.getInputStream();
- }
- public OutputStream getOutputStream() throws IOException
- {
- return new TestOutputStream(socket.getOutputStream(), timeout, initialWrites);
- }
- public void addHandshakeCompletedListener(HandshakeCompletedListener listener)
- {
- socket.addHandshakeCompletedListener(listener);
- }
- public void bind(SocketAddress bindpoint) throws IOException
- {
- if (socket != null)
- socket.bind(bindpoint);
- }
- public void connect(SocketAddress endpoint) throws IOException
- {
- if (socket != null)
- socket.connect(endpoint);
- }
- public void connect(SocketAddress endpoint, int timeout) throws IOException
- {
- socket.connect(endpoint, timeout);
- }
- public boolean getEnableSessionCreation()
- {
- return socket.getEnableSessionCreation();
- }
- public String[] getEnabledCipherSuites()
- {
- return socket.getEnabledCipherSuites();
- }
- public String[] getEnabledProtocols()
- {
- return socket.getEnabledProtocols();
- }
- public InetAddress getInetAddress()
- {
- return socket.getInetAddress();
- }
- public boolean getNeedClientAuth()
- {
- return socket.getNeedClientAuth();
- }
- public SSLSession getSession()
- {
- return socket.getSession();
- }
- public String[] getSupportedCipherSuites()
- {
- return socket.getSupportedCipherSuites();
- }
- public String[] getSupportedProtocols()
- {
- return socket.getSupportedProtocols();
- }
- public boolean getUseClientMode()
- {
- return socket.getUseClientMode();
- }
- public boolean getWantClientAuth()
- {
- return socket.getWantClientAuth();
- }
- public void removeHandshakeCompletedListener(HandshakeCompletedListener listener)
- {
- socket.removeHandshakeCompletedListener(listener);
- }
- public void setEnableSessionCreation(boolean flag)
- {
- socket.setEnableSessionCreation(flag);
- }
- public void setEnabledCipherSuites(String[] suites)
- {
- socket.setEnabledCipherSuites(suites);
- }
- public void setEnabledProtocols(String[] protocols)
- {
- socket.setEnabledProtocols(protocols);
- }
- public void setNeedClientAuth(boolean need)
- {
- socket.setNeedClientAuth(need);
- }
- public void setUseClientMode(boolean mode)
- {
- socket.setUseClientMode(mode);
- }
- public void setWantClientAuth(boolean want)
- {
- socket.setWantClientAuth(want);
- }
- public void startHandshake() throws IOException
- {
- socket.startHandshake();
- }
- }
+/*
+* 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.transport.socket.timeout;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+import javax.net.ssl.HandshakeCompletedListener;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.security.SSLSocketBuilder;
+import org.jboss.remoting.transport.Connector;
+
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public abstract class SSLWriteTimeoutTestParent extends WriteTimeoutTestParent
+{
+ private static Logger log = Logger.getLogger(SSLWriteTimeoutTestParent.class);
+
+ private static boolean firstTime = true;
+
+ protected static int SECONDARY_SERVER_SOCKET_PORT = 8765;
+ protected static String SECONDARY_SERVER_SOCKET_PORT_STRING = "8765";
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ String keyStoreFilePath = getClass().getResource("../.keystore").getFile();
+ System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath);
+ System.setProperty("javax.net.ssl.keyStorePassword", "unit-tests-server");
+ String trustStoreFilePath = getClass().getResource("../.truststore").getFile();
+ System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", "unit-tests-client");
+ }
+ super.setUp();
+ }
+
+
+ protected String getServerSocketFactoryClassName()
+ {
+ return SSLTestServerSocketFactory.class.getName();
+ }
+
+ protected Constructor getServerSocketFactoryConstructor() throws NoSuchMethodException
+ {
+ return SSLTestServerSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
+ }
+
+ protected String getSocketFactoryClassName()
+ {
+ return SSLTestSocketFactory.class.getName();
+ }
+
+ protected Constructor getSocketFactoryConstructor() throws NoSuchMethodException
+ {
+ return SSLTestSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
+ }
+
+ static public class SSLTestServerSocketFactory extends ServerSocketFactory
+ {
+ int timeout;
+ ServerSocketFactory factory;
+ int initialWrites;
+
+ public SSLTestServerSocketFactory() throws IOException
+ {
+ this.timeout = 5000;
+ this.initialWrites = -1;
+ setupFactory();
+ }
+ public SSLTestServerSocketFactory(int timeout, int initialWrites) throws IOException
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ setupFactory();
+ }
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket();
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, backlog, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, backlog, ifAddress, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ protected void setupFactory() throws IOException
+ {
+ SSLSocketBuilder sslSocketBuilder = new SSLSocketBuilder();
+ sslSocketBuilder.setUseSSLServerSocketFactory(false);
+ factory = sslSocketBuilder.createSSLServerSocketFactory();
+ }
+ }
+
+
+ static class SSLTestServerSocket extends SSLServerSocket
+ {
+ int timeout;
+ int initialWrites;
+ SSLServerSocket serverSocket;
+
+ public SSLTestServerSocket(int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super();
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ }
+ public SSLTestServerSocket(int port, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(port), 50);
+ }
+ public SSLTestServerSocket(int port, int backlog, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port, backlog);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(port), backlog);
+ }
+ public SSLTestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port, backlog, bindAddr);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(bindAddr, port), 50);
+ }
+ public Socket accept() throws IOException
+ {
+ SSLSocket s1 = (SSLSocket) serverSocket.accept();
+ Socket s2 = new SSLTestSocket(timeout, initialWrites, s1);
+ return s2;
+ }
+ public void bind(SocketAddress endpoint, int backlog) throws IOException
+ {
+ log.info("serverSocket: " + serverSocket);
+ if (serverSocket != null) log.info("bound: " + serverSocket.isBound());
+ if (serverSocket != null && !serverSocket.isBound())
+ {
+ log.info("binding " + serverSocket);
+ serverSocket.bind(endpoint, backlog);
+ }
+ }
+ public String toString()
+ {
+ return "SSLTestServerSocket[" + serverSocket.toString() + "]";
+ }
+ public boolean getEnableSessionCreation()
+ {
+ return serverSocket.getEnableSessionCreation();
+ }
+ public String[] getEnabledCipherSuites()
+ {
+ return serverSocket.getEnabledCipherSuites();
+ }
+ public String[] getEnabledProtocols()
+ {
+ return serverSocket.getEnabledProtocols();
+ }
+ public InetAddress getInetAddress()
+ {
+ return serverSocket.getInetAddress();
+ }
+ public boolean getNeedClientAuth()
+ {
+ return serverSocket.getNeedClientAuth();
+ }
+ public String[] getSupportedCipherSuites()
+ {
+ return serverSocket.getSupportedCipherSuites();
+ }
+ public String[] getSupportedProtocols()
+ {
+ return serverSocket.getSupportedProtocols();
+ }
+ public boolean getUseClientMode()
+ {
+ return serverSocket.getUseClientMode();
+ }
+ public boolean getWantClientAuth()
+ {
+ return serverSocket.getWantClientAuth();
+ }
+ public void setEnableSessionCreation(boolean arg0)
+ {
+ serverSocket.setEnableSessionCreation(arg0);
+ }
+ public void setEnabledCipherSuites(String[] arg0)
+ {
+ serverSocket.setEnabledCipherSuites(arg0);
+ }
+ public void setEnabledProtocols(String[] arg0)
+ {
+ serverSocket.setEnabledProtocols(arg0);
+ }
+ public void setNeedClientAuth(boolean arg0)
+ {
+ serverSocket.setNeedClientAuth(arg0);
+ }
+ public void setUseClientMode(boolean arg0)
+ {
+ serverSocket.setUseClientMode(arg0);
+ }
+ public void setWantClientAuth(boolean arg0)
+ {
+ serverSocket.setWantClientAuth(arg0);
+ }
+ }
+
+
+ public static class SSLTestSocketFactory extends SocketFactory
+ {
+ int timeout;
+ int initialWrites;
+ SocketFactory factory;
+
+ public SSLTestSocketFactory() throws IOException
+ {
+ timeout = 5000;
+ initialWrites = -1;
+ setupFactory();
+ }
+ public SSLTestSocketFactory(int timeout, int initialWrites) throws IOException
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ setupFactory();
+ }
+ public Socket createSocket() throws IOException
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest)
+ {
+ s = factory.createSocket();
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ protected void setupFactory() throws IOException
+ {
+ SSLSocketBuilder sslSocketBuilder = new SSLSocketBuilder();
+ sslSocketBuilder.setUseSSLServerSocketFactory(false);
+ factory = sslSocketBuilder.createSSLSocketFactory();
+ }
+ }
+
+ static class SSLTestSocket extends SSLSocket
+ {
+ int timeout;
+ int initialWrites;
+ SSLSocket socket;
+ SocketAddress endpoint;
+
+ public SSLTestSocket(int timeout, int initialWrites, SSLSocket socket)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ }
+ public SSLTestSocket(String host, int port, int timeout, int initialWrites, SSLSocket socket) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ connect(new InetSocketAddress(host, port), timeout);
+ }
+ public SSLTestSocket(InetAddress address, int port, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(address, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ connect(new InetSocketAddress(address, port), timeout);
+ }
+ public SSLTestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ bind(new InetSocketAddress(localAddr, localPort));
+ connect(new InetSocketAddress(host, port), timeout);
+ }
+ public SSLTestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ bind(new InetSocketAddress(localAddr, localPort));
+ connect(new InetSocketAddress(address, port), timeout);
+ }
+ public String toString()
+ {
+ return "SSLTestSocket[" + socket.toString() + "]";
+ }
+ public InputStream getInputStream() throws IOException
+ {
+ return socket.getInputStream();
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(socket.getOutputStream(), timeout, initialWrites);
+ }
+ public void addHandshakeCompletedListener(HandshakeCompletedListener listener)
+ {
+ socket.addHandshakeCompletedListener(listener);
+ }
+ public void bind(SocketAddress bindpoint) throws IOException
+ {
+ if (socket != null)
+ socket.bind(bindpoint);
+ }
+ public void connect(SocketAddress endpoint) throws IOException
+ {
+ if (socket != null)
+ socket.connect(endpoint);
+ }
+ public void connect(SocketAddress endpoint, int timeout) throws IOException
+ {
+ socket.connect(endpoint, timeout);
+ }
+ public boolean getEnableSessionCreation()
+ {
+ return socket.getEnableSessionCreation();
+ }
+ public String[] getEnabledCipherSuites()
+ {
+ return socket.getEnabledCipherSuites();
+ }
+ public String[] getEnabledProtocols()
+ {
+ return socket.getEnabledProtocols();
+ }
+ public InetAddress getInetAddress()
+ {
+ return socket.getInetAddress();
+ }
+ public boolean getNeedClientAuth()
+ {
+ return socket.getNeedClientAuth();
+ }
+ public SSLSession getSession()
+ {
+ return socket.getSession();
+ }
+ public String[] getSupportedCipherSuites()
+ {
+ return socket.getSupportedCipherSuites();
+ }
+ public String[] getSupportedProtocols()
+ {
+ return socket.getSupportedProtocols();
+ }
+ public boolean getUseClientMode()
+ {
+ return socket.getUseClientMode();
+ }
+ public boolean getWantClientAuth()
+ {
+ return socket.getWantClientAuth();
+ }
+ public void removeHandshakeCompletedListener(HandshakeCompletedListener listener)
+ {
+ socket.removeHandshakeCompletedListener(listener);
+ }
+ public void setEnableSessionCreation(boolean flag)
+ {
+ socket.setEnableSessionCreation(flag);
+ }
+ public void setEnabledCipherSuites(String[] suites)
+ {
+ socket.setEnabledCipherSuites(suites);
+ }
+ public void setEnabledProtocols(String[] protocols)
+ {
+ socket.setEnabledProtocols(protocols);
+ }
+ public void setNeedClientAuth(boolean need)
+ {
+ socket.setNeedClientAuth(need);
+ }
+ public void setUseClientMode(boolean mode)
+ {
+ socket.setUseClientMode(mode);
+ }
+ public void setWantClientAuth(boolean want)
+ {
+ socket.setWantClientAuth(want);
+ }
+ public void startHandshake() throws IOException
+ {
+ socket.startHandshake();
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java 2010-08-05 02:14:13 UTC (rev 6047)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java 2010-08-05 02:15:19 UTC (rev 6048)
@@ -1,315 +1,315 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, 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.transport.socket.timeout;
-
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.Callback;
-import org.jboss.remoting.callback.HandleCallbackException;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-import org.jboss.remoting.transport.socket.LRUPool;
-import org.jboss.remoting.transport.socket.ServerThread;
-import org.jboss.remoting.transport.socket.SocketServerInvoker;
-
-
-/**
- *
- * Unit test for JBREM-1002.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Jun 22, 2008
- * </p>
- */
-public class ServerThreadReuseAfterTimeoutTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ServerThreadReuseAfterTimeoutTestCase.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testJavaSerializationDefault() throws Throwable
- {
- log.info("entering " + getName());
- Map config = new HashMap();
- doJavaSerializationTest(config);
- log.info(getName() + " PASSES");
- }
-
-
- public void testJavaSerializationConfigured() throws Throwable
- {
- log.info("entering " + getName());
- Map config = new HashMap();
- config.put(ServerThread.CONTINUE_AFTER_TIMEOUT, "false");
- doJavaSerializationTest(config);
- log.info(getName() + " PASSES");
- }
-
-
- public void testJBossSerializationDefault() throws Throwable
- {
- log.info("entering " + getName());
- Map config = new HashMap();
- doJBossSerializationTest(config);
- log.info(getName() + " PASSES");
- }
-
-
- public void testJBossSerializationConfigured() throws Throwable
- {
- log.info("entering " + getName());
- Map config = new HashMap();
- config.put(ServerThread.CONTINUE_AFTER_TIMEOUT, "true");
- doJBossSerializationTest(config);
- log.info(getName() + " PASSES");
- }
-
-
- public void doJavaSerializationTest(Map clientConfig) throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer("java");
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Get ServerThread.
- SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
- Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
- field.setAccessible(true);
- LRUPool clientpool = (LRUPool) field.get(invoker);
- assertEquals(1, clientpool.size());
- Set s = clientpool.getContents();
- ServerThread serverThread1 = (ServerThread) s.iterator().next();
-
- // Get threadpool.
- field = SocketServerInvoker.class.getDeclaredField("threadpool");
- field.setAccessible(true);
- LinkedList threadpool = (LinkedList) field.get(invoker);
- assertEquals(0, threadpool.size());
-
- // Wait for ServerThread to time out.
- Thread.sleep(6000);
- for (int i = 0; i < 5; i++)
- {
- Thread.sleep(2000);
- if (clientpool.size() == 0) break;
- }
-
- if (clientpool.size() > 0)
- {
- fail("expect clientpool.size() == 0");
- }
-
- // Verify original ServerThread was returned to threadpool.
- assertEquals(1, threadpool.size());
- assertEquals(serverThread1, threadpool.iterator().next());
-
- // Make another invocation and verify ServerThread was reused.
- client.invoke("xyz");
- assertEquals(1, clientpool.size());
- s = clientpool.getContents();
- ServerThread serverThread2 = (ServerThread) s.iterator().next();
- assertEquals(serverThread1, serverThread2);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void doJBossSerializationTest(Map clientConfig) throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer("jboss");
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- // Get clientpool and ServerThread.
- SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
- Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
- field.setAccessible(true);
- LRUPool clientpool = (LRUPool) field.get(invoker);
- assertEquals(1, clientpool.size());
- Set clientpoolContents = clientpool.getContents();
- ServerThread serverThread1 = (ServerThread) clientpoolContents.iterator().next();
-
- // Get threadpool.
- field = SocketServerInvoker.class.getDeclaredField("threadpool");
- field.setAccessible(true);
- LinkedList threadpool = (LinkedList) field.get(invoker);
- assertEquals(0, threadpool.size());
-
- // Wait for ServerThread to time out.
- Thread.sleep(8000);
-
- // Verify original ServerThread remains in clientpool.
- assertEquals(0, threadpool.size());
- assertEquals(1, clientpool.size());
- clientpoolContents = clientpool.getContents();
- assertEquals(serverThread1, clientpoolContents.iterator().next());
-
- // Make another invocation and verify ServerThread was reused.
- client.invoke("xyz");
- assertEquals(1, clientpool.size());
- clientpoolContents = clientpool.getContents();
- ServerThread serverThread2 = (ServerThread) clientpoolContents.iterator().next();
- assertEquals(serverThread1, serverThread2);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer(String serializationType) throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port + "/?timeout=4000";
- locatorURI += "&serializationtype=" + serializationType;
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- return invocation.getParameter();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
-
- static class TestCallbackHandler implements InvokerCallbackHandler
- {
- public void handleCallback(Callback callback) throws HandleCallbackException
- {
- log.info("received callback");
- }
- }
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.transport.socket.timeout;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.socket.LRUPool;
+import org.jboss.remoting.transport.socket.ServerThread;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+/**
+ *
+ * Unit test for JBREM-1002.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jun 22, 2008
+ * </p>
+ */
+public class ServerThreadReuseAfterTimeoutTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ServerThreadReuseAfterTimeoutTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testJavaSerializationDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+ Map config = new HashMap();
+ doJavaSerializationTest(config);
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testJavaSerializationConfigured() throws Throwable
+ {
+ log.info("entering " + getName());
+ Map config = new HashMap();
+ config.put(ServerThread.CONTINUE_AFTER_TIMEOUT, "false");
+ doJavaSerializationTest(config);
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testJBossSerializationDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+ Map config = new HashMap();
+ doJBossSerializationTest(config);
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testJBossSerializationConfigured() throws Throwable
+ {
+ log.info("entering " + getName());
+ Map config = new HashMap();
+ config.put(ServerThread.CONTINUE_AFTER_TIMEOUT, "true");
+ doJBossSerializationTest(config);
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void doJavaSerializationTest(Map clientConfig) throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer("java");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Get ServerThread.
+ SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
+ Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
+ field.setAccessible(true);
+ LRUPool clientpool = (LRUPool) field.get(invoker);
+ assertEquals(1, clientpool.size());
+ Set s = clientpool.getContents();
+ ServerThread serverThread1 = (ServerThread) s.iterator().next();
+
+ // Get threadpool.
+ field = SocketServerInvoker.class.getDeclaredField("threadpool");
+ field.setAccessible(true);
+ LinkedList threadpool = (LinkedList) field.get(invoker);
+ assertEquals(0, threadpool.size());
+
+ // Wait for ServerThread to time out.
+ Thread.sleep(6000);
+ for (int i = 0; i < 5; i++)
+ {
+ Thread.sleep(2000);
+ if (clientpool.size() == 0) break;
+ }
+
+ if (clientpool.size() > 0)
+ {
+ fail("expect clientpool.size() == 0");
+ }
+
+ // Verify original ServerThread was returned to threadpool.
+ assertEquals(1, threadpool.size());
+ assertEquals(serverThread1, threadpool.iterator().next());
+
+ // Make another invocation and verify ServerThread was reused.
+ client.invoke("xyz");
+ assertEquals(1, clientpool.size());
+ s = clientpool.getContents();
+ ServerThread serverThread2 = (ServerThread) s.iterator().next();
+ assertEquals(serverThread1, serverThread2);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void doJBossSerializationTest(Map clientConfig) throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer("jboss");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Get clientpool and ServerThread.
+ SocketServerInvoker invoker = (SocketServerInvoker) connector.getServerInvoker();
+ Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
+ field.setAccessible(true);
+ LRUPool clientpool = (LRUPool) field.get(invoker);
+ assertEquals(1, clientpool.size());
+ Set clientpoolContents = clientpool.getContents();
+ ServerThread serverThread1 = (ServerThread) clientpoolContents.iterator().next();
+
+ // Get threadpool.
+ field = SocketServerInvoker.class.getDeclaredField("threadpool");
+ field.setAccessible(true);
+ LinkedList threadpool = (LinkedList) field.get(invoker);
+ assertEquals(0, threadpool.size());
+
+ // Wait for ServerThread to time out.
+ Thread.sleep(8000);
+
+ // Verify original ServerThread remains in clientpool.
+ assertEquals(0, threadpool.size());
+ assertEquals(1, clientpool.size());
+ clientpoolContents = clientpool.getContents();
+ assertEquals(serverThread1, clientpoolContents.iterator().next());
+
+ // Make another invocation and verify ServerThread was reused.
+ client.invoke("xyz");
+ assertEquals(1, clientpool.size());
+ clientpoolContents = clientpool.getContents();
+ ServerThread serverThread2 = (ServerThread) clientpoolContents.iterator().next();
+ assertEquals(serverThread1, serverThread2);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(String serializationType) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?timeout=4000";
+ locatorURI += "&serializationtype=" + serializationType;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/ServerThreadReuseAfterTimeoutTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketDefaultTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketDefaultTimeoutTestCase.java 2010-08-05 02:14:13 UTC (rev 6047)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketDefaultTimeoutTestCase.java 2010-08-05 02:15:19 UTC (rev 6048)
@@ -1,241 +1,241 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.transport.socket.timeout;
-
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.InvokerRegistry;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.ClientFactory;
-import org.jboss.remoting.transport.ClientInvoker;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-import org.jboss.remoting.transport.ServerFactory;
-import org.jboss.remoting.transport.socket.ServerAddress;
-import org.jboss.remoting.transport.socket.SocketClientInvoker;
-import org.jboss.remoting.transport.socket.SocketServerInvoker;
-
-
-/**
- * Unit tests for JBREM-1188.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Feb 16, 2010
- */
-public class SocketDefaultTimeoutTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(SocketDefaultTimeoutTestCase.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
- InvokerRegistry.registerInvokerFactories(getTransport(), getClientFactoryClass(), TestServerFactory.class);
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testDefaultTimeout() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
- Method getServerAddress = getClientInvokerClass().getMethod("getServerAddress", new Class[]{});
- getServerAddress.setAccessible(true);
- ClientInvoker clientInvoker = client.getInvoker();
- ServerAddress address = (ServerAddress) getServerAddress.invoke(clientInvoker, new Object[]{});
- log.info("timeout in use: " + address.timeout);
- assertEquals(SocketClientInvoker.SO_TIMEOUT_DEFAULT, address.timeout);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "test";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- String metadata = System.getProperty("remoting.metadata");
- if (metadata != null)
- {
- locatorURI += "/?" + metadata;
- }
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- protected Class getClientFactoryClass()
- {
- return TestSocketClientFactory.class;
- }
-
-
- protected Class getClientInvokerClass()
- {
- return TestSocketClientInvoker.class;
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- return invocation.getParameter();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
-
- static public class TestSocketClientInvoker extends SocketClientInvoker
- {
- public TestSocketClientInvoker(InvokerLocator locator, Map configuration) throws IOException
- {
- super(locator, configuration);
- }
- public TestSocketClientInvoker(InvokerLocator locator)
- {
- super(locator);
- }
- public ServerAddress getServerAddress()
- {
- return address;
- }
- public String toString()
- {
- return "TestSocketClientInvoker";
- }
- }
-
-
- public static class TestSocketClientFactory implements ClientFactory
- {
- public ClientInvoker createClientInvoker(InvokerLocator locator, Map config) throws IOException
- {
- ClientInvoker clientInvoker = new TestSocketClientInvoker(locator, config);
- log.info("TestClientFaotory.createClientInvoker() returning " + clientInvoker);
- return clientInvoker;
- }
- public boolean supportsSSL()
- {
- return false;
- }
- }
-
-
- public static class TestServerFactory implements ServerFactory
- {
- public ServerInvoker createServerInvoker(InvokerLocator locator, Map config) throws IOException
- {
- log.info("TestServerFactory.createServerInvoker() called");
- return new SocketServerInvoker(locator, config);
- }
- public boolean supportsSSL()
- {
- return false;
- }
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.transport.socket.timeout;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.InvokerRegistry;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.ClientFactory;
+import org.jboss.remoting.transport.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.ServerFactory;
+import org.jboss.remoting.transport.socket.ServerAddress;
+import org.jboss.remoting.transport.socket.SocketClientInvoker;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+/**
+ * Unit tests for JBREM-1188.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 16, 2010
+ */
+public class SocketDefaultTimeoutTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(SocketDefaultTimeoutTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ InvokerRegistry.registerInvokerFactories(getTransport(), getClientFactoryClass(), TestServerFactory.class);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testDefaultTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+ Method getServerAddress = getClientInvokerClass().getMethod("getServerAddress", new Class[]{});
+ getServerAddress.setAccessible(true);
+ ClientInvoker clientInvoker = client.getInvoker();
+ ServerAddress address = (ServerAddress) getServerAddress.invoke(clientInvoker, new Object[]{});
+ log.info("timeout in use: " + address.timeout);
+ assertEquals(SocketClientInvoker.SO_TIMEOUT_DEFAULT, address.timeout);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "test";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ protected Class getClientFactoryClass()
+ {
+ return TestSocketClientFactory.class;
+ }
+
+
+ protected Class getClientInvokerClass()
+ {
+ return TestSocketClientInvoker.class;
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static public class TestSocketClientInvoker extends SocketClientInvoker
+ {
+ public TestSocketClientInvoker(InvokerLocator locator, Map configuration) throws IOException
+ {
+ super(locator, configuration);
+ }
+ public TestSocketClientInvoker(InvokerLocator locator)
+ {
+ super(locator);
+ }
+ public ServerAddress getServerAddress()
+ {
+ return address;
+ }
+ public String toString()
+ {
+ return "TestSocketClientInvoker";
+ }
+ }
+
+
+ public static class TestSocketClientFactory implements ClientFactory
+ {
+ public ClientInvoker createClientInvoker(InvokerLocator locator, Map config) throws IOException
+ {
+ ClientInvoker clientInvoker = new TestSocketClientInvoker(locator, config);
+ log.info("TestClientFaotory.createClientInvoker() returning " + clientInvoker);
+ return clientInvoker;
+ }
+ public boolean supportsSSL()
+ {
+ return false;
+ }
+ }
+
+
+ public static class TestServerFactory implements ServerFactory
+ {
+ public ServerInvoker createServerInvoker(InvokerLocator locator, Map config) throws IOException
+ {
+ log.info("TestServerFactory.createServerInvoker() called");
+ return new SocketServerInvoker(locator, config);
+ }
+ public boolean supportsSSL()
+ {
+ return false;
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketDefaultTimeoutTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java 2010-08-05 02:14:13 UTC (rev 6047)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java 2010-08-05 02:15:19 UTC (rev 6048)
@@ -1,39 +1,39 @@
-/*
-* 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.transport.socket.timeout;
-
-/**
- * Unit tests for JBREM-1120.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Rev$
- * <p>
- * Copyright Apr 22, 2009
- * </p>
- */
-public class SocketWriteTimeoutTestCase extends WriteTimeoutTestParent
-{
- protected String getTransport()
- {
- return "socket";
- }
-}
+/*
+* 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.transport.socket.timeout;
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public class SocketWriteTimeoutTestCase extends WriteTimeoutTestParent
+{
+ protected String getTransport()
+ {
+ return "socket";
+ }
+}
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java 2010-08-05 02:14:13 UTC (rev 6047)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java 2010-08-05 02:15:19 UTC (rev 6048)
@@ -1,845 +1,845 @@
-/*
-* 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.transport.socket.timeout;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.rmi.MarshalException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.management.MBeanServer;
-import javax.net.ServerSocketFactory;
-import javax.net.SocketFactory;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.CannotConnectException;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.Remoting;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.Callback;
-import org.jboss.remoting.callback.HandleCallbackException;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-import org.jboss.remoting.transport.bisocket.Bisocket;
-import org.jboss.remoting.transport.socket.SocketServerInvoker;
-import org.jboss.remoting.transport.socket.SocketWrapper;
-
-
-/**
- * Unit tests for JBREM-1120.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Rev$
- * <p>
- * Copyright Apr 22, 2009
- * </p>
- */
-public abstract class WriteTimeoutTestParent extends TestCase
-{
- private static Logger log = Logger.getLogger(WriteTimeoutTestParent.class);
-
- private static boolean firstTime = true;
- protected static int secondaryServerSocketPort;
- protected static boolean callbackTest;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
-
- TestOutputStream.counter = 0;
- callbackTest = false;
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testClientWriteTimeout() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(false, false, "", -1, -1);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(SocketWrapper.WRITE_TIMEOUT, "1000");
- SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(1)});
- clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- log.info("**************************************");
- log.info("*** WorkerThread error is expected ***");
- log.info("**************************************");
-
- // Test client side write timeout.
- try
- {
- client.invoke("abc");
- }
- catch (MarshalException e)
- {
- log.info(e.getMessage());
- assertNotNull(e.getMessage());
- log.info("e.getMessage(): " + e.getMessage());
- assertTrue(e.getMessage().startsWith("Failed to communicate. Problem during marshalling/unmarshalling"));
- assertTrue(e.getCause() instanceof IOException);
- IOException ioe = (IOException) e.getCause();
- assertEquals("closed", ioe.getMessage());
- log.info("got expected Exception");
- }
- catch (Throwable t)
- {
- log.error("got unexpected Exception", t);
- fail("got unexpected Exception");
- }
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testServerWriteTimeout() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(true, false, "1000", 5000, 1);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("numberOfCallRetries", "1");
- clientConfig.put("timeout", "10000");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- log.info("**************************************");
- log.info("*** WorkerThread error is expected ***");
- log.info("**************************************");
-
- // Test server side write timeout.
- try
- {
- client.invoke("abc");
- }
- catch (MarshalException e)
- {
- log.info(e.getMessage());
-// assertNotNull(e.getMessage());
-// assertTrue(e.getMessage().startsWith("Unable to perform invocation"));
-// assertTrue(e.getCause() instanceof EOFException);
- log.info("got expected Exception");
- }
- catch (Throwable t)
- {
- log.error("got unexpected Exception", t);
- fail("got unexpected Exception");
- }
-
- // Test server invoker state.
- Thread.sleep(4000);
- SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
- assertEquals(0, serverInvoker.getCurrentClientPoolSize());
- assertEquals(1, serverInvoker.getCurrentThreadPoolSize());
- log.info("used ServerThread has returned to threadPool");
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testClientCallbackWriteTimeout() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- if (isBisocket(getTransport()))
- {
- callbackTest = true;
- }
- setupServer(false, false, "", -1, -1);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(SocketWrapper.WRITE_TIMEOUT, "1000");
- if (isBisocket(getTransport()))
- {
- SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(1)});
- clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
- }
- else
- {
- ServerSocketFactory ssf = (ServerSocketFactory) getServerSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(-1)});
- clientConfig.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
- }
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connection
- client.invoke("abc");
- log.info("connection is good");
-
- // Test client callback write timeout.
- log.info("registering callback handler");
- log.info("**************************************");
- log.info("*** WorkerThread error is expected ***");
- log.info("**************************************");
- TestCallbackHandler callbackHandler = new TestCallbackHandler();
- HashMap metadata = new HashMap();
- if (isBisocket(getTransport()))
- {
-// metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
- metadata.put(Remoting.SOCKET_FACTORY_NAME, getSocketFactoryClassName());
- metadata.put("numberOfCallRetries", "1");
- metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
- metadata.put(Bisocket.PING_FREQUENCY, "11111111");
- }
- else
- {
-// metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
- metadata.put(ServerInvoker.SERVER_SOCKET_FACTORY, getServerSocketFactoryClassName());
- metadata.put("numberOfCallRetries", "1");
- }
- client.addListener(callbackHandler, metadata, null, true);
- log.info("called Client.addListener()");
-
- // Test server invoker state.
- // Wait for local ServerThread to time out. Might take a while in bisocket transports, since
- // the request to get a socket for the callback client invoker needs its own write on the
- // control socket.
- Thread.sleep(20000);
- log.info("back from sleep");
- Set callbackConnectors = client.getCallbackConnectors(callbackHandler);
- assertEquals(1, callbackConnectors.size());
- Connector callbackConnector = (Connector) callbackConnectors.iterator().next();
- SocketServerInvoker serverInvoker = (SocketServerInvoker) callbackConnector.getServerInvoker();
- assertEquals(0, serverInvoker.getCurrentClientPoolSize());
- assertEquals(1, serverInvoker.getCurrentThreadPoolSize());
- log.info("used ServerThread has returned to threadPool");
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testServerCallbackWriteTimeout() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- if (isBisocket(getTransport()))
- {
- callbackTest = true;
- setupServer(true, false, "1000", 5000, 1);
- }
- else
- {
- setupServer(false, true, "1000", 5000, 1);
- }
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put("numberOfCallRetries", "1");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connection
- client.invoke("abc");
- log.info("connection is good");
-
- // Test server callback write timeout.
- log.info("registering callback handler");
- log.info("**************************************");
- log.info("*** WorkerThread error is expected ***");
- log.info("**************************************");
- HashMap metadata = new HashMap();
- if (isBisocket(getTransport()))
- {
- metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
- }
- TestCallbackHandler callbackHandler = new TestCallbackHandler();
- client.addListener(callbackHandler, metadata, null, true);
- log.info("added listener");
-
- // Test server invoker state.
- Thread.sleep(20000);
- log.info("waking up");
- Throwable t = invocationHandler.t;
- assertTrue(t instanceof HandleCallbackException);
- log.info("t.getCause:", t.getCause());
- if (t.getCause() instanceof MarshalException)
- {
- MarshalException e = (MarshalException) t.getCause();
- assertNotNull(e.getMessage());
- assertTrue(e.getMessage().startsWith("Failed to communicate. Problem during marshalling/unmarshalling"));
- assertTrue(e.getCause() instanceof IOException);
- IOException ioe = (IOException) e.getCause();
- assertEquals("closed", ioe.getMessage());
- }
- else
- {
- assertTrue(t.getCause() instanceof CannotConnectException);
- log.info("t.getCause().getCause(): ", t.getCause().getCause());
- assertTrue(t.getCause().getCause() instanceof InvocationTargetException);
- log.info("t.getCause().getCause().getCause(): ", t.getCause().getCause().getCause());
-// assertTrue(t.getCause().getCause().getCause() instanceof SSLProtocolException);
- assertTrue(t.getCause().getCause().getCause() instanceof IOException);
- assertEquals("closed", t.getCause().getCause().getCause().getMessage());
- }
- log.info("got expected Exception");
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected abstract String getTransport();
-
- protected boolean isBisocket(String transport)
- {
- return transport.indexOf("bisocket") >= 0;
- }
-
- protected String getServerSocketFactoryClassName()
- {
- return TestServerSocketFactory.class.getName();
- }
-
- protected Constructor getServerSocketFactoryConstructor() throws NoSuchMethodException
- {
- return TestServerSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
- }
-
- protected String getSocketFactoryClassName()
- {
- return TestSocketFactory.class.getName();
- }
-
- protected Constructor getSocketFactoryConstructor() throws NoSuchMethodException
- {
- return TestSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
- }
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer(boolean setWriteTimeout, boolean setCallbackWriteTimeout,
- String writeTimeout, int blockingTime, int initialWrites) throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- String metadata = System.getProperty("remoting.metadata");
- if (metadata != null)
- {
- locatorURI += "/?" + metadata;
- }
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- if (isBisocket(getTransport()))
- {
- secondaryServerSocketPort = PortUtil.findFreePort(host);
- config.put(Bisocket.SECONDARY_BIND_PORT, Integer.toString(secondaryServerSocketPort));
- config.put(Bisocket.PING_FREQUENCY, "11111111");
- }
- if (setWriteTimeout)
- {
- config.put(SocketWrapper.WRITE_TIMEOUT, writeTimeout);
- ServerSocketFactory ssf = (ServerSocketFactory) getServerSocketFactoryConstructor().newInstance(new Object[]{new Integer(blockingTime), new Integer(initialWrites)});
- config.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
- }
- if (setCallbackWriteTimeout)
- {
- config.put(SocketWrapper.WRITE_TIMEOUT, writeTimeout);
- SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(blockingTime), new Integer(initialWrites)});
- config.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
- }
- if (callbackTest)
- {
- config.put("numberOfCallRetries", "1");
- }
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- Throwable t;
-
- public void addListener(final InvokerCallbackHandler callbackHandler)
- {
- new Thread()
- {
- public void run()
- {
- try
- {
- log.info("sending callback");
- callbackHandler.handleCallback(new Callback("callback"));
- }
- catch (Throwable t)
- {
- log.info("throwable: ", t);
- TestInvocationHandler.this.t = t;
- }
- }
- }.start();
- }
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- return invocation.getParameter();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
-
- static class TestCallbackHandler implements InvokerCallbackHandler
- {
- public void handleCallback(Callback callback) throws HandleCallbackException
- {
- log.info("received callback");
- }
- }
-
-
- static public class TestServerSocketFactory extends ServerSocketFactory
- {
- int timeout;
- int initialWrites;
-
- public TestServerSocketFactory()
- {
- this.timeout = 5000;
- this.initialWrites = -1;
- }
- public TestServerSocketFactory(int timeout, int initialWrites)
- {
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public ServerSocket createServerSocket() throws IOException
- {
- ServerSocket ss = null;
- if (callbackTest)
- {
- ss = ServerSocketFactory.getDefault().createServerSocket();
- }
- else
- {
- ss = new TestServerSocket(timeout, initialWrites);
- }
- log.info("returning: " + ss);
- return ss;
- }
- public ServerSocket createServerSocket(int port) throws IOException
- {
- ServerSocket ss = null;
- if (callbackTest && port != secondaryServerSocketPort)
- {
- ss = ServerSocketFactory.getDefault().createServerSocket(port);
- }
- else
- {
- ss = new TestServerSocket(port, timeout, initialWrites);
- }
- log.info("returning: " + ss);
- return ss;
- }
-
- public ServerSocket createServerSocket(int port, int backlog) throws IOException
- {
- ServerSocket ss = null;
- if (callbackTest && port != secondaryServerSocketPort)
- {
- ss = ServerSocketFactory.getDefault().createServerSocket(port, backlog);
- }
- else
- {
- ss = new TestServerSocket(port, backlog, timeout, initialWrites);
- }
- log.info("returning: " + ss);
- return ss;
- }
-
- public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
- {
- ServerSocket ss = null;
- if (callbackTest && port != secondaryServerSocketPort)
- {
- ss = ServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
- }
- else
- {
- ss = new TestServerSocket(port, backlog, ifAddress, timeout, initialWrites);
- }
- log.info("returning: " + ss);
- return ss;
- }
- }
-
-
- static class TestServerSocket extends ServerSocket
- {
- int timeout;
- int initialWrites;
-
- public TestServerSocket(int timeout, int initialWrites) throws IOException
- {
- super();
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public TestServerSocket(int port, int timeout, int initialWrites) throws IOException
- {
- super(port);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public TestServerSocket(int port, int backlog, int timeout, int initialWrites) throws IOException
- {
- super(port, backlog);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public TestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout, int initialWrites) throws IOException
- {
- super(port, backlog, bindAddr);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public Socket accept() throws IOException
- {
- Socket s = new TestSocket(timeout, initialWrites);
- implAccept(s);
- return s;
- }
- public String toString()
- {
- return "TestServerSocket[" + getLocalPort() + "]";
- }
- }
-
-
- public static class TestSocketFactory extends SocketFactory
- {
- int timeout;
- int initialWrites = -1;
-
- public TestSocketFactory()
- {
- timeout = 5000;
- }
- public TestSocketFactory(int timeout, int initialWrites)
- {
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public Socket createSocket()
- {
- log.info("callbackTest: " + callbackTest);
- Socket s = null;
- if (callbackTest)
- {
- s = new Socket();
- }
- else
- {
- s = new TestSocket(timeout, initialWrites);
- }
- log.info(this + " returning " + s);
- return s;
- }
- public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
- {
- log.info("callbackTest: " + callbackTest + ", port: " + arg1);
- Socket s = null;
- if (callbackTest && arg1 != secondaryServerSocketPort)
- {
- s = new Socket(arg0, arg1);
- }
- else
- {
- s = new TestSocket(arg0, arg1, timeout, initialWrites);
- }
- log.info(this + " returning " + s);
- return s;
- }
-
- public Socket createSocket(InetAddress arg0, int arg1) throws IOException
- {
- log.info("callbackTest: " + callbackTest + ", port: " + arg1);
- Socket s = null;
- if (callbackTest && arg1 != secondaryServerSocketPort)
- {
- s = new Socket(arg0, arg1);
- }
- else
- {
- s = new TestSocket(arg0, arg1, timeout, initialWrites);
- }
- log.info(this + " returning " + s);
- return s;
- }
-
- public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
- {
- log.info("callbackTest: " + callbackTest + ", port: " + arg1);
- Socket s = null;
- if (callbackTest && arg1 != secondaryServerSocketPort)
- {
- s = new Socket(arg0, arg1);
- }
- else
- {
- s = new TestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites);
- }
- log.info(this + " returning " + s);
- return s;
- }
-
- public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
- {
- log.info("callbackTest: " + callbackTest + ", port: " + arg1);
- Socket s = null;
- if (callbackTest && arg1 != secondaryServerSocketPort)
- {
- s = new Socket(arg0, arg1);
- }
- else
- {
- s = new TestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites);
- }
- log.info(this + " returning " + s);
- return s;
- }
- }
-
- static class TestSocket extends Socket
- {
- int timeout;
- int initialWrites;
-
- public TestSocket(int timeout, int initialWrites)
- {
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public TestSocket(String host, int port, int timeout, int initialWrites) throws UnknownHostException, IOException
- {
- super(host, port);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public TestSocket(InetAddress address, int port, int timeout, int initialWrites) throws IOException
- {
- super(address, port);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public TestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites) throws IOException
- {
- super(host, port, localAddr, localPort);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public TestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites) throws IOException
- {
- super(address, port, localAddr, localPort);
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public OutputStream getOutputStream() throws IOException
- {
- return new TestOutputStream(super.getOutputStream(), timeout, initialWrites);
- }
- public String toString()
- {
- return "TestSocket[" + getLocalPort() + "->" + getPort() + "]";
- }
- }
-
- static class TestOutputStream extends OutputStream
- {
- OutputStream os;
- int timeout;
- boolean closed;
- int initialWrites;
- boolean doWait = true;
- public static int counter;
-
- public TestOutputStream(OutputStream os, int timeout, int initialWrites)
- {
- this.os = os;
- this.timeout = timeout;
- this.initialWrites = initialWrites;
- }
- public void close()throws IOException
- {
- closed = true;
- super.close();
- log.info(this + " closed");
- }
- public void write(int b) throws IOException
- {
- System.out.print("b: " + b);
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- if (doWait && ++counter > initialWrites)
- {
- try
- {
- log.info("TestOutputStream.write() sleeping: " + timeout);
- Thread.sleep(timeout);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- }
- os.write(b);
- }
- public void write(byte b[], int off, int len) throws IOException
- {
- System.out.print("b: ");
- for (int i = 0; i < len; i++)
- {
- System.out.print(b[i] + " ");
- }
- System.out.println("");
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- log.info("TestOutputStream: counter = " + counter + ", initialWrites = " + initialWrites);
- if (++counter > initialWrites)
- {
- try
- {
- log.info("TestOutputStream.write() sleeping: " + timeout);
- Thread.sleep(timeout);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- }
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- try
- {
- log.info(this + " calling write()");
- doWait = false;
- os.write(b, off, len);
- os.flush();
- doWait = true;
- log.info(this + " back from write()");
- }
- catch (IOException e)
- {
- log.info("exception: ", e);
- throw e;
- }
- }
- }
+/*
+* 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.transport.socket.timeout;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.rmi.MarshalException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.CannotConnectException;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.bisocket.Bisocket;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+import org.jboss.remoting.transport.socket.SocketWrapper;
+
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public abstract class WriteTimeoutTestParent extends TestCase
+{
+ private static Logger log = Logger.getLogger(WriteTimeoutTestParent.class);
+
+ private static boolean firstTime = true;
+ protected static int secondaryServerSocketPort;
+ protected static boolean callbackTest;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+
+ TestOutputStream.counter = 0;
+ callbackTest = false;
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testClientWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false, false, "", -1, -1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(1)});
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+
+ // Test client side write timeout.
+ try
+ {
+ client.invoke("abc");
+ }
+ catch (MarshalException e)
+ {
+ log.info(e.getMessage());
+ assertNotNull(e.getMessage());
+ log.info("e.getMessage(): " + e.getMessage());
+ assertTrue(e.getMessage().startsWith("Failed to communicate. Problem during marshalling/unmarshalling"));
+ assertTrue(e.getCause() instanceof IOException);
+ IOException ioe = (IOException) e.getCause();
+ assertEquals("closed", ioe.getMessage());
+ log.info("got expected Exception");
+ }
+ catch (Throwable t)
+ {
+ log.error("got unexpected Exception", t);
+ fail("got unexpected Exception");
+ }
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testServerWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, false, "1000", 5000, 1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("numberOfCallRetries", "1");
+ clientConfig.put("timeout", "10000");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+
+ // Test server side write timeout.
+ try
+ {
+ client.invoke("abc");
+ }
+ catch (MarshalException e)
+ {
+ log.info(e.getMessage());
+// assertNotNull(e.getMessage());
+// assertTrue(e.getMessage().startsWith("Unable to perform invocation"));
+// assertTrue(e.getCause() instanceof EOFException);
+ log.info("got expected Exception");
+ }
+ catch (Throwable t)
+ {
+ log.error("got unexpected Exception", t);
+ fail("got unexpected Exception");
+ }
+
+ // Test server invoker state.
+ Thread.sleep(4000);
+ SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
+ assertEquals(0, serverInvoker.getCurrentClientPoolSize());
+ assertEquals(1, serverInvoker.getCurrentThreadPoolSize());
+ log.info("used ServerThread has returned to threadPool");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testClientCallbackWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ if (isBisocket(getTransport()))
+ {
+ callbackTest = true;
+ }
+ setupServer(false, false, "", -1, -1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ if (isBisocket(getTransport()))
+ {
+ SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(1)});
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
+ }
+ else
+ {
+ ServerSocketFactory ssf = (ServerSocketFactory) getServerSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(-1)});
+ clientConfig.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
+ }
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection
+ client.invoke("abc");
+ log.info("connection is good");
+
+ // Test client callback write timeout.
+ log.info("registering callback handler");
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ if (isBisocket(getTransport()))
+ {
+// metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ metadata.put(Remoting.SOCKET_FACTORY_NAME, getSocketFactoryClassName());
+ metadata.put("numberOfCallRetries", "1");
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ metadata.put(Bisocket.PING_FREQUENCY, "11111111");
+ }
+ else
+ {
+// metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ metadata.put(ServerInvoker.SERVER_SOCKET_FACTORY, getServerSocketFactoryClassName());
+ metadata.put("numberOfCallRetries", "1");
+ }
+ client.addListener(callbackHandler, metadata, null, true);
+ log.info("called Client.addListener()");
+
+ // Test server invoker state.
+ // Wait for local ServerThread to time out. Might take a while in bisocket transports, since
+ // the request to get a socket for the callback client invoker needs its own write on the
+ // control socket.
+ Thread.sleep(20000);
+ log.info("back from sleep");
+ Set callbackConnectors = client.getCallbackConnectors(callbackHandler);
+ assertEquals(1, callbackConnectors.size());
+ Connector callbackConnector = (Connector) callbackConnectors.iterator().next();
+ SocketServerInvoker serverInvoker = (SocketServerInvoker) callbackConnector.getServerInvoker();
+ assertEquals(0, serverInvoker.getCurrentClientPoolSize());
+ assertEquals(1, serverInvoker.getCurrentThreadPoolSize());
+ log.info("used ServerThread has returned to threadPool");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testServerCallbackWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ if (isBisocket(getTransport()))
+ {
+ callbackTest = true;
+ setupServer(true, false, "1000", 5000, 1);
+ }
+ else
+ {
+ setupServer(false, true, "1000", 5000, 1);
+ }
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("numberOfCallRetries", "1");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection
+ client.invoke("abc");
+ log.info("connection is good");
+
+ // Test server callback write timeout.
+ log.info("registering callback handler");
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+ HashMap metadata = new HashMap();
+ if (isBisocket(getTransport()))
+ {
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ }
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler, metadata, null, true);
+ log.info("added listener");
+
+ // Test server invoker state.
+ Thread.sleep(20000);
+ log.info("waking up");
+ Throwable t = invocationHandler.t;
+ assertTrue(t instanceof HandleCallbackException);
+ log.info("t.getCause:", t.getCause());
+ if (t.getCause() instanceof MarshalException)
+ {
+ MarshalException e = (MarshalException) t.getCause();
+ assertNotNull(e.getMessage());
+ assertTrue(e.getMessage().startsWith("Failed to communicate. Problem during marshalling/unmarshalling"));
+ assertTrue(e.getCause() instanceof IOException);
+ IOException ioe = (IOException) e.getCause();
+ assertEquals("closed", ioe.getMessage());
+ }
+ else
+ {
+ assertTrue(t.getCause() instanceof CannotConnectException);
+ log.info("t.getCause().getCause(): ", t.getCause().getCause());
+ assertTrue(t.getCause().getCause() instanceof InvocationTargetException);
+ log.info("t.getCause().getCause().getCause(): ", t.getCause().getCause().getCause());
+// assertTrue(t.getCause().getCause().getCause() instanceof SSLProtocolException);
+ assertTrue(t.getCause().getCause().getCause() instanceof IOException);
+ assertEquals("closed", t.getCause().getCause().getCause().getMessage());
+ }
+ log.info("got expected Exception");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected abstract String getTransport();
+
+ protected boolean isBisocket(String transport)
+ {
+ return transport.indexOf("bisocket") >= 0;
+ }
+
+ protected String getServerSocketFactoryClassName()
+ {
+ return TestServerSocketFactory.class.getName();
+ }
+
+ protected Constructor getServerSocketFactoryConstructor() throws NoSuchMethodException
+ {
+ return TestServerSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
+ }
+
+ protected String getSocketFactoryClassName()
+ {
+ return TestSocketFactory.class.getName();
+ }
+
+ protected Constructor getSocketFactoryConstructor() throws NoSuchMethodException
+ {
+ return TestSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
+ }
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean setWriteTimeout, boolean setCallbackWriteTimeout,
+ String writeTimeout, int blockingTime, int initialWrites) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ if (isBisocket(getTransport()))
+ {
+ secondaryServerSocketPort = PortUtil.findFreePort(host);
+ config.put(Bisocket.SECONDARY_BIND_PORT, Integer.toString(secondaryServerSocketPort));
+ config.put(Bisocket.PING_FREQUENCY, "11111111");
+ }
+ if (setWriteTimeout)
+ {
+ config.put(SocketWrapper.WRITE_TIMEOUT, writeTimeout);
+ ServerSocketFactory ssf = (ServerSocketFactory) getServerSocketFactoryConstructor().newInstance(new Object[]{new Integer(blockingTime), new Integer(initialWrites)});
+ config.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
+ }
+ if (setCallbackWriteTimeout)
+ {
+ config.put(SocketWrapper.WRITE_TIMEOUT, writeTimeout);
+ SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(blockingTime), new Integer(initialWrites)});
+ config.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
+ }
+ if (callbackTest)
+ {
+ config.put("numberOfCallRetries", "1");
+ }
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ Throwable t;
+
+ public void addListener(final InvokerCallbackHandler callbackHandler)
+ {
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ log.info("sending callback");
+ callbackHandler.handleCallback(new Callback("callback"));
+ }
+ catch (Throwable t)
+ {
+ log.info("throwable: ", t);
+ TestInvocationHandler.this.t = t;
+ }
+ }
+ }.start();
+ }
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
+
+
+ static public class TestServerSocketFactory extends ServerSocketFactory
+ {
+ int timeout;
+ int initialWrites;
+
+ public TestServerSocketFactory()
+ {
+ this.timeout = 5000;
+ this.initialWrites = -1;
+ }
+ public TestServerSocketFactory(int timeout, int initialWrites)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket();
+ }
+ else
+ {
+ ss = new TestServerSocket(timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port, backlog);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, backlog, timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, backlog, ifAddress, timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+ }
+
+
+ static class TestServerSocket extends ServerSocket
+ {
+ int timeout;
+ int initialWrites;
+
+ public TestServerSocket(int timeout, int initialWrites) throws IOException
+ {
+ super();
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestServerSocket(int port, int timeout, int initialWrites) throws IOException
+ {
+ super(port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestServerSocket(int port, int backlog, int timeout, int initialWrites) throws IOException
+ {
+ super(port, backlog);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout, int initialWrites) throws IOException
+ {
+ super(port, backlog, bindAddr);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public Socket accept() throws IOException
+ {
+ Socket s = new TestSocket(timeout, initialWrites);
+ implAccept(s);
+ return s;
+ }
+ public String toString()
+ {
+ return "TestServerSocket[" + getLocalPort() + "]";
+ }
+ }
+
+
+ public static class TestSocketFactory extends SocketFactory
+ {
+ int timeout;
+ int initialWrites = -1;
+
+ public TestSocketFactory()
+ {
+ timeout = 5000;
+ }
+ public TestSocketFactory(int timeout, int initialWrites)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public Socket createSocket()
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest)
+ {
+ s = new Socket();
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
+ {
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+ }
+
+ static class TestSocket extends Socket
+ {
+ int timeout;
+ int initialWrites;
+
+ public TestSocket(int timeout, int initialWrites)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(String host, int port, int timeout, int initialWrites) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(InetAddress address, int port, int timeout, int initialWrites) throws IOException
+ {
+ super(address, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(super.getOutputStream(), timeout, initialWrites);
+ }
+ public String toString()
+ {
+ return "TestSocket[" + getLocalPort() + "->" + getPort() + "]";
+ }
+ }
+
+ static class TestOutputStream extends OutputStream
+ {
+ OutputStream os;
+ int timeout;
+ boolean closed;
+ int initialWrites;
+ boolean doWait = true;
+ public static int counter;
+
+ public TestOutputStream(OutputStream os, int timeout, int initialWrites)
+ {
+ this.os = os;
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public void close()throws IOException
+ {
+ closed = true;
+ super.close();
+ log.info(this + " closed");
+ }
+ public void write(int b) throws IOException
+ {
+ System.out.print("b: " + b);
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ if (doWait && ++counter > initialWrites)
+ {
+ try
+ {
+ log.info("TestOutputStream.write() sleeping: " + timeout);
+ Thread.sleep(timeout);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ os.write(b);
+ }
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ System.out.print("b: ");
+ for (int i = 0; i < len; i++)
+ {
+ System.out.print(b[i] + " ");
+ }
+ System.out.println("");
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ log.info("TestOutputStream: counter = " + counter + ", initialWrites = " + initialWrites);
+ if (++counter > initialWrites)
+ {
+ try
+ {
+ log.info("TestOutputStream.write() sleeping: " + timeout);
+ Thread.sleep(timeout);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ try
+ {
+ log.info(this + " calling write()");
+ doWait = false;
+ os.write(b, off, len);
+ os.flush();
+ doWait = true;
+ log.info(this + " back from write()");
+ }
+ catch (IOException e)
+ {
+ log.info("exception: ", e);
+ throw e;
+ }
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 7 months
JBoss Remoting SVN: r6047 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 22:14:13 -0400 (Wed, 04 Aug 2010)
New Revision: 6047
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketDefaultTimeoutTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketDefaultTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketDefaultTimeoutTestCase.java 2010-08-05 02:13:36 UTC (rev 6046)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketDefaultTimeoutTestCase.java 2010-08-05 02:14:13 UTC (rev 6047)
@@ -1,96 +1,96 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.transport.socket.ssl.timeout;
-
-import java.io.IOException;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.transport.ClientFactory;
-import org.jboss.remoting.transport.ClientInvoker;
-import org.jboss.remoting.transport.socket.ServerAddress;
-import org.jboss.remoting.transport.sslsocket.SSLSocketClientInvoker;
-import org.jboss.test.remoting.transport.socket.timeout.SocketDefaultTimeoutTestCase;
-
-
-/**
- * Unit tests for JBREM-1188.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Feb 16, 2010
- */
-public class SSLSocketDefaultTimeoutTestCase extends SocketDefaultTimeoutTestCase
-{
- private static Logger log = Logger.getLogger(SSLSocketDefaultTimeoutTestCase.class);
-
-
- protected Class getClientFactoryClass()
- {
- return TestSSLSocketClientFactory.class;
- }
-
-
- protected Class getClientInvokerClass()
- {
- return TestSSLSocketClientInvoker.class;
- }
-
-
- public static class TestSSLSocketClientFactory implements ClientFactory
- {
- public ClientInvoker createClientInvoker(InvokerLocator locator, Map config) throws IOException
- {
- ClientInvoker clientInvoker = new TestSSLSocketClientInvoker(locator, config);
- log.info("TestClientFaotory.createClientInvoker() returning " + clientInvoker);
- return clientInvoker;
- }
- public boolean supportsSSL()
- {
- return true;
- }
- }
-
-
- public static class TestSSLSocketClientInvoker extends SSLSocketClientInvoker
- {
- public TestSSLSocketClientInvoker(InvokerLocator locator, Map configuration) throws IOException
- {
- super(locator, configuration);
- }
- public TestSSLSocketClientInvoker(InvokerLocator locator) throws IOException
- {
- super(locator);
- }
- public ServerAddress getServerAddress()
- {
- return address;
- }
- public String toString()
- {
- return "TestSSLSocketClientInvoker";
- }
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.transport.socket.ssl.timeout;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.transport.ClientFactory;
+import org.jboss.remoting.transport.ClientInvoker;
+import org.jboss.remoting.transport.socket.ServerAddress;
+import org.jboss.remoting.transport.sslsocket.SSLSocketClientInvoker;
+import org.jboss.test.remoting.transport.socket.timeout.SocketDefaultTimeoutTestCase;
+
+
+/**
+ * Unit tests for JBREM-1188.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 16, 2010
+ */
+public class SSLSocketDefaultTimeoutTestCase extends SocketDefaultTimeoutTestCase
+{
+ private static Logger log = Logger.getLogger(SSLSocketDefaultTimeoutTestCase.class);
+
+
+ protected Class getClientFactoryClass()
+ {
+ return TestSSLSocketClientFactory.class;
+ }
+
+
+ protected Class getClientInvokerClass()
+ {
+ return TestSSLSocketClientInvoker.class;
+ }
+
+
+ public static class TestSSLSocketClientFactory implements ClientFactory
+ {
+ public ClientInvoker createClientInvoker(InvokerLocator locator, Map config) throws IOException
+ {
+ ClientInvoker clientInvoker = new TestSSLSocketClientInvoker(locator, config);
+ log.info("TestClientFaotory.createClientInvoker() returning " + clientInvoker);
+ return clientInvoker;
+ }
+ public boolean supportsSSL()
+ {
+ return true;
+ }
+ }
+
+
+ public static class TestSSLSocketClientInvoker extends SSLSocketClientInvoker
+ {
+ public TestSSLSocketClientInvoker(InvokerLocator locator, Map configuration) throws IOException
+ {
+ super(locator, configuration);
+ }
+ public TestSSLSocketClientInvoker(InvokerLocator locator) throws IOException
+ {
+ super(locator);
+ }
+ public ServerAddress getServerAddress()
+ {
+ return address;
+ }
+ public String toString()
+ {
+ return "TestSSLSocketClientInvoker";
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketDefaultTimeoutTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java 2010-08-05 02:13:36 UTC (rev 6046)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java 2010-08-05 02:14:13 UTC (rev 6047)
@@ -1,41 +1,41 @@
-/*
-* 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.transport.socket.ssl.timeout;
-
-import org.jboss.test.remoting.transport.socket.timeout.SSLWriteTimeoutTestParent;
-
-/**
- * Unit tests for JBREM-1120.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Rev$
- * <p>
- * Copyright Apr 22, 2009
- * </p>
- */
-public class SSLSocketWriteTimeoutTestCase extends SSLWriteTimeoutTestParent
-{
- protected String getTransport()
- {
- return "sslsocket";
- }
-}
+/*
+* 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.transport.socket.ssl.timeout;
+
+import org.jboss.test.remoting.transport.socket.timeout.SSLWriteTimeoutTestParent;
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public class SSLSocketWriteTimeoutTestCase extends SSLWriteTimeoutTestParent
+{
+ protected String getTransport()
+ {
+ return "sslsocket";
+ }
+}
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 7 months
JBoss Remoting SVN: r6046 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 22:13:36 -0400 (Wed, 04 Aug 2010)
New Revision: 6046
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java 2010-08-05 02:12:55 UTC (rev 6045)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java 2010-08-05 02:13:36 UTC (rev 6046)
@@ -1,44 +1,44 @@
-
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, 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.transport.socket.ssl.socketfactory;
-
-import org.jboss.test.remoting.socketfactory.SSLSocketFactoryClassNameTestRoot;
-
-
-/**
- * Unit test for JBREM-1014.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Jul 18, 2008
- * </p>
- */
-public class SSLSocketFactoryClassNameTestCase extends SSLSocketFactoryClassNameTestRoot
-{
- protected String getTransport()
- {
- return "sslsocket";
- }
-}
-
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.transport.socket.ssl.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SSLSocketFactoryClassNameTestRoot;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SSLSocketFactoryClassNameTestCase extends SSLSocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "sslsocket";
+ }
+}
+
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 7 months
JBoss Remoting SVN: r6045 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 22:12:55 -0400 (Wed, 04 Aug 2010)
New Revision: 6045
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketClientPoolWithSemaphoreTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketWrapperWithIOException.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketWrapperWithSocketException.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketClientPoolWithSemaphoreTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketClientPoolWithSemaphoreTestCase.java 2010-08-05 02:12:01 UTC (rev 6044)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketClientPoolWithSemaphoreTestCase.java 2010-08-05 02:12:55 UTC (rev 6045)
@@ -1,494 +1,494 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, 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.transport.socket.socketpool;
-
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-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.jboss.remoting.transport.socket.LRUPool;
-import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
-import org.jboss.remoting.transport.socket.ServerThread;
-import org.jboss.remoting.transport.socket.SocketServerInvoker;
-
-
-/**
- * Unit test for JBREM-845.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Nov 30, 2007
- * </p>
- */
-public class SocketClientPoolWithSemaphoreTestCase extends TestCase
-{
- protected static String WAIT = "wait";
- protected static String DURATION = "duration";
-
- private static Logger log = Logger.getLogger(SocketClientPoolWithSemaphoreTestCase.class);
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testStressClientPoolTen() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "10");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- for (int i = 0; i < 5000; i++)
- {
- assertEquals(Integer.toString(i), (String) client.invoke(Integer.toString(i)));
- }
-
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testStressClientPoolOne() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "1");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
- assertEquals(1, clientInvoker.getNumberOfAvailableConnections());
-
- for (int i = 0; i < 5000; i++)
- {
- assertEquals(Integer.toString(i), (String) client.invoke(Integer.toString(i)));
- }
-
- assertEquals(1, clientInvoker.getNumberOfAvailableConnections());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testMaxPoolSize() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "10");
- addExtraClientConfig(clientConfig);
- final Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- final HashMap metadata = new HashMap();
- metadata.put(DURATION, "20000");
-
- for (int i = 0; i < 20; i++)
- {
- new Thread()
- {
- public void run()
- {
- try
- {
- client.invoke(WAIT, metadata);
- }
- catch (Throwable e)
- {
- log.error("Error", e);
- }
- }
- }.start();
- }
-
- Thread.sleep(10000);
- assertEquals(10, invocationHandler.counter);
- assertEquals(0, clientInvoker.getNumberOfAvailableConnections());
-
- Thread.sleep(20000);
- assertEquals(20, invocationHandler.counter);
- assertEquals(0, clientInvoker.getNumberOfAvailableConnections());
-
- Thread.sleep(20000);
- assertEquals(20, invocationHandler.counter);
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testRestartServer() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "10");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- for (int i = 0; i < 50; i++)
- {
- assertEquals(Integer.toString(i), (String) client.invoke(Integer.toString(i)));
- }
-
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- disableServer(connector);
- shutdownServer();
- setupServer(port);
-
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- for (int i = 0; i < 50; i++)
- {
- assertEquals(Integer.toString(i), (String) client.invoke(Integer.toString(i)));
- }
-
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testSemaphoreReleaseAfterGetConnection() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "/?" + MicroSocketClientInvoker.CLIENT_SOCKET_CLASS_FLAG + "=bogus";
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- log.info("clientLocator: " + clientLocator);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "10");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- try
- {
- log.info(client.invoke("abc"));
- fail("expected exception");
- }
- catch (Exception e)
- {
- log.info("got expected exception");
- }
-
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testSemaphoreReleaseAfterSocketException() throws Throwable
- {
- String exceptionClass = SocketWrapperWithSocketException.class.getName();
- doSemaphoreReleaseAfterSocketException(exceptionClass);
- }
-
-
-
- public void testSemaphoreReleaseAfterIOException() throws Throwable
- {
- String exceptionClass = SocketWrapperWithIOException.class.getName();
- doSemaphoreReleaseAfterSocketException(exceptionClass);
- }
-
-
- protected void doSemaphoreReleaseAfterSocketException(String exceptionClass) throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- String clientLocatorURI = locatorURI;
- clientLocatorURI += "/?" + MicroSocketClientInvoker.CLIENT_SOCKET_CLASS_FLAG + "=" + exceptionClass;
- InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
- log.info("clientLocator: " + clientLocator);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "10");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- try
- {
- log.info(client.invoke("abc"));
- fail("expected exception");
- }
- catch (Exception e)
- {
- log.info("got expected exception: " + e, e);
- }
-
- assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- setupServer(-1);
- }
-
-
- protected void setupServer(int localPort) throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
-
- if (localPort == -1)
- port = PortUtil.findFreePort(host);
- else
- port = localPort;
-
- locatorURI = getTransport() + "://" + host + ":" + port;
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
-
- for (int i = 0; i < 5; i++)
- {
- try
- {
- connector.start();
- }
- catch (Exception e)
- {
- log.error("unable to start Connector");
- Thread.sleep(60000);
- }
- }
- }
-
-
- protected void disableServer(Connector connector) throws Exception
- {
- log.info("disabling " + connector);
- SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
- Field field = SocketServerInvoker.class.getDeclaredField("serverSocket");
- field.setAccessible(true);
- ServerSocket ss = (ServerSocket) field.get(serverInvoker);
- ss.close();
-
- field = SocketServerInvoker.class.getDeclaredField("clientpool");
- field.setAccessible(true);
- LRUPool clientpool = (LRUPool) field.get(serverInvoker);
- Iterator it = clientpool.getContents().iterator();
- field = ServerThread.class.getDeclaredField("socket");
- field.setAccessible(true);
-
- while (it.hasNext())
- {
- Socket socket = (Socket) field.get(it.next());
- socket.close();
- }
-
- field = SocketServerInvoker.class.getDeclaredField("threadpool");
- field.setAccessible(true);
- List threadpool = (List) field.get(serverInvoker);
- it = threadpool.iterator();
- field = ServerThread.class.getDeclaredField("socket");
- field.setAccessible(true);
-
- while (it.hasNext())
- {
- Socket socket = (Socket) field.get(it.next());
- socket.close();
- }
-
- log.info("disabled " + connector);
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- public int counter;
- private Object lock = new Object();
-
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- synchronized (lock)
- {
- counter++;
- }
-
- String command = (String) invocation.getParameter();
-
- if (WAIT.equals(command))
- {
- Map metadata = invocation.getRequestPayload();
- int duration = Integer.parseInt((String) metadata.get(DURATION));
- Thread.sleep(duration);
- }
-
- return command;
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.transport.socket.socketpool;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+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.jboss.remoting.transport.socket.LRUPool;
+import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
+import org.jboss.remoting.transport.socket.ServerThread;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+/**
+ * Unit test for JBREM-845.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Nov 30, 2007
+ * </p>
+ */
+public class SocketClientPoolWithSemaphoreTestCase extends TestCase
+{
+ protected static String WAIT = "wait";
+ protected static String DURATION = "duration";
+
+ private static Logger log = Logger.getLogger(SocketClientPoolWithSemaphoreTestCase.class);
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testStressClientPoolTen() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "10");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ for (int i = 0; i < 5000; i++)
+ {
+ assertEquals(Integer.toString(i), (String) client.invoke(Integer.toString(i)));
+ }
+
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testStressClientPoolOne() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "1");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
+ assertEquals(1, clientInvoker.getNumberOfAvailableConnections());
+
+ for (int i = 0; i < 5000; i++)
+ {
+ assertEquals(Integer.toString(i), (String) client.invoke(Integer.toString(i)));
+ }
+
+ assertEquals(1, clientInvoker.getNumberOfAvailableConnections());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testMaxPoolSize() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "10");
+ addExtraClientConfig(clientConfig);
+ final Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ final HashMap metadata = new HashMap();
+ metadata.put(DURATION, "20000");
+
+ for (int i = 0; i < 20; i++)
+ {
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ client.invoke(WAIT, metadata);
+ }
+ catch (Throwable e)
+ {
+ log.error("Error", e);
+ }
+ }
+ }.start();
+ }
+
+ Thread.sleep(10000);
+ assertEquals(10, invocationHandler.counter);
+ assertEquals(0, clientInvoker.getNumberOfAvailableConnections());
+
+ Thread.sleep(20000);
+ assertEquals(20, invocationHandler.counter);
+ assertEquals(0, clientInvoker.getNumberOfAvailableConnections());
+
+ Thread.sleep(20000);
+ assertEquals(20, invocationHandler.counter);
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testRestartServer() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "10");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ for (int i = 0; i < 50; i++)
+ {
+ assertEquals(Integer.toString(i), (String) client.invoke(Integer.toString(i)));
+ }
+
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ disableServer(connector);
+ shutdownServer();
+ setupServer(port);
+
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ for (int i = 0; i < 50; i++)
+ {
+ assertEquals(Integer.toString(i), (String) client.invoke(Integer.toString(i)));
+ }
+
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testSemaphoreReleaseAfterGetConnection() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "/?" + MicroSocketClientInvoker.CLIENT_SOCKET_CLASS_FLAG + "=bogus";
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ log.info("clientLocator: " + clientLocator);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "10");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ try
+ {
+ log.info(client.invoke("abc"));
+ fail("expected exception");
+ }
+ catch (Exception e)
+ {
+ log.info("got expected exception");
+ }
+
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testSemaphoreReleaseAfterSocketException() throws Throwable
+ {
+ String exceptionClass = SocketWrapperWithSocketException.class.getName();
+ doSemaphoreReleaseAfterSocketException(exceptionClass);
+ }
+
+
+
+ public void testSemaphoreReleaseAfterIOException() throws Throwable
+ {
+ String exceptionClass = SocketWrapperWithIOException.class.getName();
+ doSemaphoreReleaseAfterSocketException(exceptionClass);
+ }
+
+
+ protected void doSemaphoreReleaseAfterSocketException(String exceptionClass) throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "/?" + MicroSocketClientInvoker.CLIENT_SOCKET_CLASS_FLAG + "=" + exceptionClass;
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ log.info("clientLocator: " + clientLocator);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "10");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ MicroSocketClientInvoker clientInvoker = (MicroSocketClientInvoker) client.getInvoker();
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ try
+ {
+ log.info(client.invoke("abc"));
+ fail("expected exception");
+ }
+ catch (Exception e)
+ {
+ log.info("got expected exception: " + e, e);
+ }
+
+ assertEquals(10, clientInvoker.getNumberOfAvailableConnections());
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ setupServer(-1);
+ }
+
+
+ protected void setupServer(int localPort) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+
+ if (localPort == -1)
+ port = PortUtil.findFreePort(host);
+ else
+ port = localPort;
+
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+
+ for (int i = 0; i < 5; i++)
+ {
+ try
+ {
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.error("unable to start Connector");
+ Thread.sleep(60000);
+ }
+ }
+ }
+
+
+ protected void disableServer(Connector connector) throws Exception
+ {
+ log.info("disabling " + connector);
+ SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
+ Field field = SocketServerInvoker.class.getDeclaredField("serverSocket");
+ field.setAccessible(true);
+ ServerSocket ss = (ServerSocket) field.get(serverInvoker);
+ ss.close();
+
+ field = SocketServerInvoker.class.getDeclaredField("clientpool");
+ field.setAccessible(true);
+ LRUPool clientpool = (LRUPool) field.get(serverInvoker);
+ Iterator it = clientpool.getContents().iterator();
+ field = ServerThread.class.getDeclaredField("socket");
+ field.setAccessible(true);
+
+ while (it.hasNext())
+ {
+ Socket socket = (Socket) field.get(it.next());
+ socket.close();
+ }
+
+ field = SocketServerInvoker.class.getDeclaredField("threadpool");
+ field.setAccessible(true);
+ List threadpool = (List) field.get(serverInvoker);
+ it = threadpool.iterator();
+ field = ServerThread.class.getDeclaredField("socket");
+ field.setAccessible(true);
+
+ while (it.hasNext())
+ {
+ Socket socket = (Socket) field.get(it.next());
+ socket.close();
+ }
+
+ log.info("disabled " + connector);
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public int counter;
+ private Object lock = new Object();
+
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ synchronized (lock)
+ {
+ counter++;
+ }
+
+ String command = (String) invocation.getParameter();
+
+ if (WAIT.equals(command))
+ {
+ Map metadata = invocation.getRequestPayload();
+ int duration = Integer.parseInt((String) metadata.get(DURATION));
+ Thread.sleep(duration);
+ }
+
+ return command;
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketClientPoolWithSemaphoreTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketWrapperWithIOException.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketWrapperWithIOException.java 2010-08-05 02:12:01 UTC (rev 6044)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketWrapperWithIOException.java 2010-08-05 02:12:55 UTC (rev 6045)
@@ -1,62 +1,62 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, 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.transport.socket.socketpool;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.Socket;
-import java.util.Map;
-
-import org.jboss.remoting.marshal.UnMarshaller;
-import org.jboss.remoting.transport.socket.ClientSocketWrapper;
-
-/**
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Nov 30, 2007
- * </p>
- */
-public class SocketWrapperWithIOException extends ClientSocketWrapper
-{
-
- public SocketWrapperWithIOException(Socket socket, Map metadata, Integer timeout) throws Exception
- {
- super(socket, metadata, timeout);
- }
-
- protected InputStream createInputStream(String serializationType, Socket socket, UnMarshaller unmarshaller)
- throws IOException
- {
- return new ExplodingInputStream();
- }
-
- public static class ExplodingInputStream extends InputStream
- {
- public int read() throws IOException
- {
- throw new IOException("bang");
- }
- }
-}
-
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.transport.socket.socketpool;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.Socket;
+import java.util.Map;
+
+import org.jboss.remoting.marshal.UnMarshaller;
+import org.jboss.remoting.transport.socket.ClientSocketWrapper;
+
+/**
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Nov 30, 2007
+ * </p>
+ */
+public class SocketWrapperWithIOException extends ClientSocketWrapper
+{
+
+ public SocketWrapperWithIOException(Socket socket, Map metadata, Integer timeout) throws Exception
+ {
+ super(socket, metadata, timeout);
+ }
+
+ protected InputStream createInputStream(String serializationType, Socket socket, UnMarshaller unmarshaller)
+ throws IOException
+ {
+ return new ExplodingInputStream();
+ }
+
+ public static class ExplodingInputStream extends InputStream
+ {
+ public int read() throws IOException
+ {
+ throw new IOException("bang");
+ }
+ }
+}
+
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketWrapperWithIOException.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketWrapperWithSocketException.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketWrapperWithSocketException.java 2010-08-05 02:12:01 UTC (rev 6044)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketWrapperWithSocketException.java 2010-08-05 02:12:55 UTC (rev 6045)
@@ -1,63 +1,63 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, 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.transport.socket.socketpool;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.Socket;
-import java.net.SocketException;
-import java.util.Map;
-
-import org.jboss.remoting.marshal.UnMarshaller;
-import org.jboss.remoting.transport.socket.ClientSocketWrapper;
-
-/**
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Nov 30, 2007
- * </p>
- */
-public class SocketWrapperWithSocketException extends ClientSocketWrapper
-{
-
- public SocketWrapperWithSocketException(Socket socket, Map metadata, Integer timeout) throws Exception
- {
- super(socket, metadata, timeout);
- }
-
- protected InputStream createInputStream(String serializationType, Socket socket, UnMarshaller unmarshaller)
- throws IOException
- {
- return new ExplodingInputStream();
- }
-
- public static class ExplodingInputStream extends InputStream
- {
- public int read() throws IOException
- {
- throw new SocketException("bang");
- }
- }
-}
-
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.transport.socket.socketpool;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.Socket;
+import java.net.SocketException;
+import java.util.Map;
+
+import org.jboss.remoting.marshal.UnMarshaller;
+import org.jboss.remoting.transport.socket.ClientSocketWrapper;
+
+/**
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Nov 30, 2007
+ * </p>
+ */
+public class SocketWrapperWithSocketException extends ClientSocketWrapper
+{
+
+ public SocketWrapperWithSocketException(Socket socket, Map metadata, Integer timeout) throws Exception
+ {
+ super(socket, metadata, timeout);
+ }
+
+ protected InputStream createInputStream(String serializationType, Socket socket, UnMarshaller unmarshaller)
+ throws IOException
+ {
+ return new ExplodingInputStream();
+ }
+
+ public static class ExplodingInputStream extends InputStream
+ {
+ public int read() throws IOException
+ {
+ throw new SocketException("bang");
+ }
+ }
+}
+
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketpool/SocketWrapperWithSocketException.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 7 months
JBoss Remoting SVN: r6044 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketfactory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 22:12:01 -0400 (Wed, 04 Aug 2010)
New Revision: 6044
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java 2010-08-05 02:11:36 UTC (rev 6043)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java 2010-08-05 02:12:01 UTC (rev 6044)
@@ -1,22 +1,22 @@
-package org.jboss.test.remoting.transport.socket.socketfactory;
-
-import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot;
-
-
-/**
- *
- * Unit test for JBREM-1014.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Jul 18, 2008
- * </p>
- */
-public class SocketFactoryClassNameTestCase extends SocketFactoryClassNameTestRoot
-{
- protected String getTransport()
- {
- return "socket";
- }
+package org.jboss.test.remoting.transport.socket.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot;
+
+
+/**
+ *
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SocketFactoryClassNameTestCase extends SocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "socket";
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 7 months
JBoss Remoting SVN: r6043 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 22:11:36 -0400 (Wed, 04 Aug 2010)
New Revision: 6043
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception/GeneralizeSocketExceptionTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception/SocketCreationExceptionTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception/GeneralizeSocketExceptionTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception/GeneralizeSocketExceptionTestCase.java 2010-08-05 02:10:57 UTC (rev 6042)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception/GeneralizeSocketExceptionTestCase.java 2010-08-05 02:11:36 UTC (rev 6043)
@@ -1,506 +1,506 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.transport.socket.socketexception;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.SocketException;
-import java.net.UnknownHostException;
-import java.rmi.MarshalException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-import javax.net.SocketFactory;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.Remoting;
-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;
-
-
-/**
- * Unit tests for JBREM-1146.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version
- * <p>
- * Copyright Sep 2, 2009
- * </p>
- */
-public class GeneralizeSocketExceptionTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(GeneralizeSocketExceptionTestCase.class);
- private static String connectionResetMessage = "yada yada connection reset yada yada";
- private static String connectionClosedMessage = "yada yada connection closed yada yada";
- private static String brokenPipeMessage = "yada yada broken pipe yada yada";
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
-
- TestOutputStream.counter = 0;
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testConnectionResetNotGeneralized() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(connectionResetMessage), 2));
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Verify invocation fails.
- try
- {
- client.invoke("abc");
- }
- catch (MarshalException e)
- {
- Throwable t = e.getCause();
- assertEquals(connectionResetMessage, t.getMessage());
- }
- catch (Throwable e)
- {
- fail("Expecteded message: " + connectionResetMessage + ", got: " + e.getMessage());
- }
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testConnectionResetGeneralized() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(connectionResetMessage), 2));
- clientConfig.put("generalizeSocketException", "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Verify invocation succeeds.
- assertEquals("abc", client.invoke("abc"));
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testConnectionClosedNotGeneralized() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(connectionClosedMessage), 2));
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Verify invocation fails.
- try
- {
- client.invoke("abc");
- }
- catch (MarshalException e)
- {
- Throwable t = e.getCause();
- assertEquals(connectionClosedMessage, t.getMessage());
- }
- catch (Throwable e)
- {
- fail("Expecteded message: " + connectionClosedMessage + ", got: " + e.getMessage());
- }
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testConnectionClosedGeneralized() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(connectionClosedMessage), 2));
- clientConfig.put("generalizeSocketException", "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Verify invocation succeeds.
- assertEquals("abc", client.invoke("abc"));
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testBrokedPipedNotGeneralized() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(brokenPipeMessage), 2));
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Verify invocation fails.
- try
- {
- client.invoke("abc");
- }
- catch (MarshalException e)
- {
- Throwable t = e.getCause();
- assertEquals(brokenPipeMessage, t.getMessage());
- }
- catch (Throwable e)
- {
- fail("Expecteded message: " + brokenPipeMessage + ", got: " + e.getMessage());
- }
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testBrokedPipeGeneralized() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(brokenPipeMessage), 2));
- clientConfig.put("generalizeSocketException", "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Verify invocation succeeds.
- assertEquals("abc", client.invoke("abc"));
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- String metadata = System.getProperty("remoting.metadata");
- if (metadata != null)
- {
- locatorURI += "/?" + metadata;
- }
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- return invocation.getParameter();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
- public static class TestSocketFactory extends SocketFactory
- {
- IOException exception;
- int throwOn = -1;
-
- public TestSocketFactory()
- {
- exception = new SocketException("default");
- }
- public TestSocketFactory(IOException exception, int throwOn)
- {
- this.exception = exception;
- this.throwOn = throwOn;
- }
- public Socket createSocket()
- {
- return new TestSocket(exception, throwOn);
- }
- public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
- {
- return new TestSocket(arg0, arg1, exception, throwOn);
- }
- public Socket createSocket(InetAddress arg0, int arg1) throws IOException
- {
- return new TestSocket(arg0, arg1, exception, throwOn);
- }
- public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
- {
- return new TestSocket(arg0, arg1, arg2, arg3, exception, throwOn);
- }
-
- public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
- {
- return new TestSocket(arg0, arg1, arg2, arg3, exception, throwOn);
- }
- }
-
- static class TestSocket extends Socket
- {
- IOException exception;
- int throwOn;
-
- public TestSocket(IOException exception, int throwOn)
- {
- this.exception = exception;
- this.throwOn = throwOn;
- }
- public TestSocket(String host, int port, IOException exception, int throwOn) throws UnknownHostException, IOException
- {
- super(host, port);
- this.exception = exception;
- this.throwOn = throwOn;
- }
- public TestSocket(InetAddress address, int port, IOException exception, int throwOn) throws IOException
- {
- super(address, port);
- this.exception = exception;
- this.throwOn = throwOn;
- }
- public TestSocket(String host, int port, InetAddress localAddr, int localPort, IOException exception, int throwOn) throws IOException
- {
- super(host, port, localAddr, localPort);
- this.exception = exception;
- this.throwOn = throwOn;
- }
- public TestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, IOException exception, int throwOn) throws IOException
- {
- super(address, port, localAddr, localPort);
- this.exception = exception;
- this.throwOn = throwOn;
- }
- public OutputStream getOutputStream() throws IOException
- {
- return new TestOutputStream(super.getOutputStream(), exception, throwOn);
- }
- public String toString()
- {
- return "TestSocket[" + getLocalPort() + "->" + getPort() + "]";
- }
- }
-
- static class TestOutputStream extends OutputStream
- {
- OutputStream os;
- IOException exception;
- boolean closed;
- int throwOn;
- boolean doThrowException = true;
- public static int counter;
-
- public TestOutputStream(OutputStream os, IOException exception, int throwOn)
- {
- this.os = os;
- this.exception = exception;
- this.throwOn = throwOn;
- }
- public void close()throws IOException
- {
- closed = true;
- super.close();
- log.info(this + " closed");
- }
- public void write(int b) throws IOException
- {
- System.out.print("b: " + b);
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- if (doThrowException && ++counter == throwOn)
- {
- throw exception;
- }
- os.write(b);
- }
- public void write(byte b[], int off, int len) throws IOException
- {
- System.out.print("b: ");
- for (int i = 0; i < len; i++)
- {
- System.out.print(b[i] + " ");
- }
- System.out.println("");
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- log.info("TestOutputStream: counter = " + counter + ", throwOn = " + throwOn);
- if (++counter == throwOn)
- {
- throw exception;
- }
- if (closed)
- {
- log.info("TestOutputStream closed, cannot write");
- throw new IOException("closed");
- }
- try
- {
- log.info(this + " calling write()");
- doThrowException = false;
- os.write(b, off, len);
- os.flush();
- doThrowException = true;
- log.info(this + " back from write()");
- }
- catch (IOException e)
- {
- log.info("exception: ", e);
- throw e;
- }
- }
- }
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.transport.socket.socketexception;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.rmi.MarshalException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.net.SocketFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+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;
+
+
+/**
+ * Unit tests for JBREM-1146.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Sep 2, 2009
+ * </p>
+ */
+public class GeneralizeSocketExceptionTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(GeneralizeSocketExceptionTestCase.class);
+ private static String connectionResetMessage = "yada yada connection reset yada yada";
+ private static String connectionClosedMessage = "yada yada connection closed yada yada";
+ private static String brokenPipeMessage = "yada yada broken pipe yada yada";
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+
+ TestOutputStream.counter = 0;
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testConnectionResetNotGeneralized() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(connectionResetMessage), 2));
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Verify invocation fails.
+ try
+ {
+ client.invoke("abc");
+ }
+ catch (MarshalException e)
+ {
+ Throwable t = e.getCause();
+ assertEquals(connectionResetMessage, t.getMessage());
+ }
+ catch (Throwable e)
+ {
+ fail("Expecteded message: " + connectionResetMessage + ", got: " + e.getMessage());
+ }
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testConnectionResetGeneralized() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(connectionResetMessage), 2));
+ clientConfig.put("generalizeSocketException", "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Verify invocation succeeds.
+ assertEquals("abc", client.invoke("abc"));
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testConnectionClosedNotGeneralized() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(connectionClosedMessage), 2));
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Verify invocation fails.
+ try
+ {
+ client.invoke("abc");
+ }
+ catch (MarshalException e)
+ {
+ Throwable t = e.getCause();
+ assertEquals(connectionClosedMessage, t.getMessage());
+ }
+ catch (Throwable e)
+ {
+ fail("Expecteded message: " + connectionClosedMessage + ", got: " + e.getMessage());
+ }
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testConnectionClosedGeneralized() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(connectionClosedMessage), 2));
+ clientConfig.put("generalizeSocketException", "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Verify invocation succeeds.
+ assertEquals("abc", client.invoke("abc"));
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testBrokedPipedNotGeneralized() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(brokenPipeMessage), 2));
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Verify invocation fails.
+ try
+ {
+ client.invoke("abc");
+ }
+ catch (MarshalException e)
+ {
+ Throwable t = e.getCause();
+ assertEquals(brokenPipeMessage, t.getMessage());
+ }
+ catch (Throwable e)
+ {
+ fail("Expecteded message: " + brokenPipeMessage + ", got: " + e.getMessage());
+ }
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testBrokedPipeGeneralized() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException(brokenPipeMessage), 2));
+ clientConfig.put("generalizeSocketException", "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Verify invocation succeeds.
+ assertEquals("abc", client.invoke("abc"));
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+ public static class TestSocketFactory extends SocketFactory
+ {
+ IOException exception;
+ int throwOn = -1;
+
+ public TestSocketFactory()
+ {
+ exception = new SocketException("default");
+ }
+ public TestSocketFactory(IOException exception, int throwOn)
+ {
+ this.exception = exception;
+ this.throwOn = throwOn;
+ }
+ public Socket createSocket()
+ {
+ return new TestSocket(exception, throwOn);
+ }
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ return new TestSocket(arg0, arg1, exception, throwOn);
+ }
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ return new TestSocket(arg0, arg1, exception, throwOn);
+ }
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
+ {
+ return new TestSocket(arg0, arg1, arg2, arg3, exception, throwOn);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ return new TestSocket(arg0, arg1, arg2, arg3, exception, throwOn);
+ }
+ }
+
+ static class TestSocket extends Socket
+ {
+ IOException exception;
+ int throwOn;
+
+ public TestSocket(IOException exception, int throwOn)
+ {
+ this.exception = exception;
+ this.throwOn = throwOn;
+ }
+ public TestSocket(String host, int port, IOException exception, int throwOn) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.exception = exception;
+ this.throwOn = throwOn;
+ }
+ public TestSocket(InetAddress address, int port, IOException exception, int throwOn) throws IOException
+ {
+ super(address, port);
+ this.exception = exception;
+ this.throwOn = throwOn;
+ }
+ public TestSocket(String host, int port, InetAddress localAddr, int localPort, IOException exception, int throwOn) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.exception = exception;
+ this.throwOn = throwOn;
+ }
+ public TestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, IOException exception, int throwOn) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.exception = exception;
+ this.throwOn = throwOn;
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(super.getOutputStream(), exception, throwOn);
+ }
+ public String toString()
+ {
+ return "TestSocket[" + getLocalPort() + "->" + getPort() + "]";
+ }
+ }
+
+ static class TestOutputStream extends OutputStream
+ {
+ OutputStream os;
+ IOException exception;
+ boolean closed;
+ int throwOn;
+ boolean doThrowException = true;
+ public static int counter;
+
+ public TestOutputStream(OutputStream os, IOException exception, int throwOn)
+ {
+ this.os = os;
+ this.exception = exception;
+ this.throwOn = throwOn;
+ }
+ public void close()throws IOException
+ {
+ closed = true;
+ super.close();
+ log.info(this + " closed");
+ }
+ public void write(int b) throws IOException
+ {
+ System.out.print("b: " + b);
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ if (doThrowException && ++counter == throwOn)
+ {
+ throw exception;
+ }
+ os.write(b);
+ }
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ System.out.print("b: ");
+ for (int i = 0; i < len; i++)
+ {
+ System.out.print(b[i] + " ");
+ }
+ System.out.println("");
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ log.info("TestOutputStream: counter = " + counter + ", throwOn = " + throwOn);
+ if (++counter == throwOn)
+ {
+ throw exception;
+ }
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ try
+ {
+ log.info(this + " calling write()");
+ doThrowException = false;
+ os.write(b, off, len);
+ os.flush();
+ doThrowException = true;
+ log.info(this + " back from write()");
+ }
+ catch (IOException e)
+ {
+ log.info("exception: ", e);
+ throw e;
+ }
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception/GeneralizeSocketExceptionTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception/SocketCreationExceptionTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception/SocketCreationExceptionTestCase.java 2010-08-05 02:10:57 UTC (rev 6042)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception/SocketCreationExceptionTestCase.java 2010-08-05 02:11:36 UTC (rev 6043)
@@ -1,300 +1,300 @@
-/*
-* 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.transport.socket.socketexception;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.SocketException;
-import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-import javax.net.ServerSocketFactory;
-import javax.net.SocketFactory;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.Remoting;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.Callback;
-import org.jboss.remoting.callback.HandleCallbackException;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-
-/**
- * Unit tests for JBREM-1152.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Rev$
- * <p>
- * Copyright Sep 9, 2009
- * </p>
- */
-public class SocketCreationExceptionTestCase extends TestCase
-{
- protected static String SEND_CALLBACK = "sendCallback";
- private static Logger log = Logger.getLogger(SocketCreationExceptionTestCase.class);
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.TRACE);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testInvocationWithSocketException() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(null);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new SocketException(getName()), 2));
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connection.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testInvocationWithIOException() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer(null);
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException("Connection reset"), 2));
- clientConfig.put("generalizeSocketException", "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connection.
- assertEquals("abc", client.invoke("abc"));
- log.info("connection is good");
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer(ServerSocketFactory ssf) throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- String metadata = System.getProperty("remoting.metadata");
- if (metadata != null)
- {
- locatorURI += "/?" + metadata;
- }
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- config.put("timeout", "5000");
- if (ssf != null)
- {
- config.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
- }
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- InvokerCallbackHandler callbackHandler;
-
- public void addListener(InvokerCallbackHandler callbackHandler)
- {
- this.callbackHandler = callbackHandler;
- }
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- Object parameter = invocation.getParameter();
- if (SEND_CALLBACK.equals(parameter))
- {
- try
- {
- callbackHandler.handleCallback(new Callback("callback"));
- }
- catch (HandleCallbackException e)
- {
- log.error("unable to send callback", e);
- }
- }
- return parameter;
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
-
- public static class TestSocketFactory extends SocketFactory
- {
- int counter;
- int limit;
- IOException exception;
-
- public TestSocketFactory()
- {
- }
- public TestSocketFactory(IOException exception, int limit)
- {
- this.exception = exception;
- this.limit = limit;
- }
- public Socket createSocket() throws IOException
- {
- counter++;
- log.info("counter: " + counter);
- if (counter <= limit)
- {
- log.info("throwing exception");
- throw exception;
- }
- log.info("returning socket");
- return new Socket();
- }
- public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
- {
- counter++;
- log.info("counter: " + counter);
- if (counter <= limit)
- {
- throw exception;
- }
- log.info("returning socket");
- return new Socket(arg0, arg1);
- }
- public Socket createSocket(InetAddress arg0, int arg1) throws IOException
- {
- counter++;
- log.info("counter: " + counter);
- if (counter <= limit)
- {
- throw exception;
- }
- log.info("returning socket");
- return new Socket(arg0, arg1);
- }
- public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
- {
- counter++;
- log.info("counter: " + counter);
- if (counter <= limit)
- {
- throw exception;
- }
- log.info("returning socket");
- return new Socket(arg0, arg1, arg2, arg3);
- }
-
- public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
- {
- counter++;
- log.info("counter: " + counter);
- if (counter <= limit)
- {
- throw exception;
- }
- log.info("returning socket");
- return new Socket(arg0, arg1, arg2, arg3);
- }
- }
+/*
+* 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.transport.socket.socketexception;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+/**
+ * Unit tests for JBREM-1152.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Sep 9, 2009
+ * </p>
+ */
+public class SocketCreationExceptionTestCase extends TestCase
+{
+ protected static String SEND_CALLBACK = "sendCallback";
+ private static Logger log = Logger.getLogger(SocketCreationExceptionTestCase.class);
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.TRACE);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testInvocationWithSocketException() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(null);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new SocketException(getName()), 2));
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testInvocationWithIOException() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(null);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, new TestSocketFactory(new IOException("Connection reset"), 2));
+ clientConfig.put("generalizeSocketException", "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(ServerSocketFactory ssf) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put("timeout", "5000");
+ if (ssf != null)
+ {
+ config.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
+ }
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ InvokerCallbackHandler callbackHandler;
+
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ this.callbackHandler = callbackHandler;
+ }
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ Object parameter = invocation.getParameter();
+ if (SEND_CALLBACK.equals(parameter))
+ {
+ try
+ {
+ callbackHandler.handleCallback(new Callback("callback"));
+ }
+ catch (HandleCallbackException e)
+ {
+ log.error("unable to send callback", e);
+ }
+ }
+ return parameter;
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ public static class TestSocketFactory extends SocketFactory
+ {
+ int counter;
+ int limit;
+ IOException exception;
+
+ public TestSocketFactory()
+ {
+ }
+ public TestSocketFactory(IOException exception, int limit)
+ {
+ this.exception = exception;
+ this.limit = limit;
+ }
+ public Socket createSocket() throws IOException
+ {
+ counter++;
+ log.info("counter: " + counter);
+ if (counter <= limit)
+ {
+ log.info("throwing exception");
+ throw exception;
+ }
+ log.info("returning socket");
+ return new Socket();
+ }
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ counter++;
+ log.info("counter: " + counter);
+ if (counter <= limit)
+ {
+ throw exception;
+ }
+ log.info("returning socket");
+ return new Socket(arg0, arg1);
+ }
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ counter++;
+ log.info("counter: " + counter);
+ if (counter <= limit)
+ {
+ throw exception;
+ }
+ log.info("returning socket");
+ return new Socket(arg0, arg1);
+ }
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
+ {
+ counter++;
+ log.info("counter: " + counter);
+ if (counter <= limit)
+ {
+ throw exception;
+ }
+ log.info("returning socket");
+ return new Socket(arg0, arg1, arg2, arg3);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ counter++;
+ log.info("counter: " + counter);
+ if (counter <= limit)
+ {
+ throw exception;
+ }
+ log.info("returning socket");
+ return new Socket(arg0, arg1, arg2, arg3);
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/socketexception/SocketCreationExceptionTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 7 months
JBoss Remoting SVN: r6042 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 22:10:57 -0400 (Wed, 04 Aug 2010)
New Revision: 6042
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/InterruptedExceptionTestCase.java
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/MockInvokerInterruptTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/InterruptedExceptionTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/InterruptedExceptionTestCase.java 2010-08-05 02:10:04 UTC (rev 6041)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/InterruptedExceptionTestCase.java 2010-08-05 02:10:57 UTC (rev 6042)
@@ -1,364 +1,364 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, 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.transport.socket.interrupt;
-
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
-import org.jboss.remoting.CannotConnectException;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-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.jboss.remoting.transport.socket.MicroSocketClientInvoker;
-
-
-/**
- * Unit test for JBREM-955.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Apr 25, 2008
- * </p>
- */
-public class InterruptedExceptionTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(InterruptedExceptionTestCase.class);
-
- private static boolean firstTime = true;
- private static String FAST = "fast";
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testNotWrappedInterruptedExceptionDefault() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "1");
- clientConfig.put("numberOfCallRetries", "1");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals(FAST, client.invoke(FAST));
- log.info("connection is good");
-
- InvokerThread t1 = new InvokerThread(client, "abc");
- InvokerThread t2 = new InvokerThread(client, "xyz");
-
- // Start first invocation.
- t1.start();
- log.info("started first invocation");
-
- // Give first invocation time to start.
- Thread.sleep(5000);
-
- // Start second invocation.
- t2.start();
- log.info("started second invocation");
-
- // Give second invocation time to start.
- Thread.sleep(5000);
-
- // Interrupt second invocation as it waits for a semaphore.
- t2.interrupt();
- log.info("interrupted second invocation");
-
- // Wait until second invocation throws an exception.
- synchronized (t2)
- {
- t2.wait(10000);
- }
-
- // Verify exception is an CannotConnectException (not wrapped in a RuntimeException).
- Throwable t = t2.throwable;
- log.info("throwable: " + t);
- assertTrue(t instanceof CannotConnectException);
- assertTrue(t.getCause() instanceof InterruptedException);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testNotWrappedInterruptedExceptionConfigured() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "1");
- clientConfig.put("numberOfCallRetries", "1");
- clientConfig.put(MicroSocketClientInvoker.WRAP_INTERRUPTED_EXCEPTION, "false");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals(FAST, client.invoke(FAST));
- log.info("connection is good");
-
- InvokerThread t1 = new InvokerThread(client, "abc");
- InvokerThread t2 = new InvokerThread(client, "xyz");
-
- // Start first invocation.
- t1.start();
- log.info("started first invocation");
-
- // Give first invocation time to start.
- Thread.sleep(5000);
-
- // Start second invocation.
- t2.start();
- log.info("started second invocation");
-
- // Give second invocation time to start.
- Thread.sleep(5000);
-
- // Interrupt second invocation as it waits for a semaphore.
- t2.interrupt();
- log.info("interrupted second invocation");
-
- // Wait until second invocation throws an exception.
- synchronized (t2)
- {
- t2.wait(10000);
- }
-
- // Verify exception is an CannotConnectException (not wrapped in a RuntimeException).
- Throwable t = t2.throwable;
- log.info("throwable: " + t);
- assertTrue(t instanceof CannotConnectException);
- assertTrue(t.getCause() instanceof InterruptedException);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- public void testWrappedInterruptedException() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create client.
- InvokerLocator clientLocator = new InvokerLocator(locatorURI);
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "1");
- clientConfig.put("numberOfCallRetries", "1");
- clientConfig.put(MicroSocketClientInvoker.WRAP_INTERRUPTED_EXCEPTION, "true");
- addExtraClientConfig(clientConfig);
- Client client = new Client(clientLocator, clientConfig);
- client.connect();
- log.info("client is connected");
-
- // Test connections.
- assertEquals(FAST, client.invoke(FAST));
- log.info("connection is good");
-
- InvokerThread t1 = new InvokerThread(client, "abc");
- InvokerThread t2 = new InvokerThread(client, "xyz");
-
- // Start first invocation.
- t1.start();
- log.info("started first invocation");
-
- // Give first invocation time to start.
- Thread.sleep(5000);
-
- // Start second invocation.
- t2.start();
- log.info("started second invocation");
-
- // Give second invocation time to start.
- Thread.sleep(5000);
-
- // Interrupt second invocation as it waits for a semaphore.
- t2.interrupt();
- log.info("interrupted second invocation");
-
- // Wait until second invocation throws an exception.
- synchronized (t2)
- {
- t2.wait(10000);
- }
-
- // Verify exception is an InterruptedException wrapped in a RuntimeException.
- Throwable t = t2.throwable;
- log.info("throwable: " + t);
- assertTrue(t instanceof RuntimeException);
- assertFalse(t instanceof CannotConnectException);
- assertTrue(t.getCause() instanceof InterruptedException);
-
- client.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- Object o = invocation.getParameter();
- if (!FAST.equals(o))
- {
- Thread.sleep(20000);
- }
- return invocation.getParameter();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
-
- static class InvokerThread extends Thread
- {
- static int counter;
- Client client;
- String message;
- Throwable throwable;
-
- public InvokerThread(Client client, String message)
- {
- this.client = client;
- this.message = message;
- setName("InvokerThread:" + counter++);
- }
-
- public void run()
- {
- try
- {
- log.info("invocation succeeded: " + client.invoke(message));
- }
- catch (Throwable t)
- {
- throwable = t;
- log.error("invocation error: " + t.getMessage());
- }
-
- synchronized (this)
- {
- notify();
- }
- }
- }
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.transport.socket.interrupt;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.CannotConnectException;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+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.jboss.remoting.transport.socket.MicroSocketClientInvoker;
+
+
+/**
+ * Unit test for JBREM-955.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Apr 25, 2008
+ * </p>
+ */
+public class InterruptedExceptionTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(InterruptedExceptionTestCase.class);
+
+ private static boolean firstTime = true;
+ private static String FAST = "fast";
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testNotWrappedInterruptedExceptionDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "1");
+ clientConfig.put("numberOfCallRetries", "1");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals(FAST, client.invoke(FAST));
+ log.info("connection is good");
+
+ InvokerThread t1 = new InvokerThread(client, "abc");
+ InvokerThread t2 = new InvokerThread(client, "xyz");
+
+ // Start first invocation.
+ t1.start();
+ log.info("started first invocation");
+
+ // Give first invocation time to start.
+ Thread.sleep(5000);
+
+ // Start second invocation.
+ t2.start();
+ log.info("started second invocation");
+
+ // Give second invocation time to start.
+ Thread.sleep(5000);
+
+ // Interrupt second invocation as it waits for a semaphore.
+ t2.interrupt();
+ log.info("interrupted second invocation");
+
+ // Wait until second invocation throws an exception.
+ synchronized (t2)
+ {
+ t2.wait(10000);
+ }
+
+ // Verify exception is an CannotConnectException (not wrapped in a RuntimeException).
+ Throwable t = t2.throwable;
+ log.info("throwable: " + t);
+ assertTrue(t instanceof CannotConnectException);
+ assertTrue(t.getCause() instanceof InterruptedException);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testNotWrappedInterruptedExceptionConfigured() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "1");
+ clientConfig.put("numberOfCallRetries", "1");
+ clientConfig.put(MicroSocketClientInvoker.WRAP_INTERRUPTED_EXCEPTION, "false");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals(FAST, client.invoke(FAST));
+ log.info("connection is good");
+
+ InvokerThread t1 = new InvokerThread(client, "abc");
+ InvokerThread t2 = new InvokerThread(client, "xyz");
+
+ // Start first invocation.
+ t1.start();
+ log.info("started first invocation");
+
+ // Give first invocation time to start.
+ Thread.sleep(5000);
+
+ // Start second invocation.
+ t2.start();
+ log.info("started second invocation");
+
+ // Give second invocation time to start.
+ Thread.sleep(5000);
+
+ // Interrupt second invocation as it waits for a semaphore.
+ t2.interrupt();
+ log.info("interrupted second invocation");
+
+ // Wait until second invocation throws an exception.
+ synchronized (t2)
+ {
+ t2.wait(10000);
+ }
+
+ // Verify exception is an CannotConnectException (not wrapped in a RuntimeException).
+ Throwable t = t2.throwable;
+ log.info("throwable: " + t);
+ assertTrue(t instanceof CannotConnectException);
+ assertTrue(t.getCause() instanceof InterruptedException);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testWrappedInterruptedException() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG, "1");
+ clientConfig.put("numberOfCallRetries", "1");
+ clientConfig.put(MicroSocketClientInvoker.WRAP_INTERRUPTED_EXCEPTION, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals(FAST, client.invoke(FAST));
+ log.info("connection is good");
+
+ InvokerThread t1 = new InvokerThread(client, "abc");
+ InvokerThread t2 = new InvokerThread(client, "xyz");
+
+ // Start first invocation.
+ t1.start();
+ log.info("started first invocation");
+
+ // Give first invocation time to start.
+ Thread.sleep(5000);
+
+ // Start second invocation.
+ t2.start();
+ log.info("started second invocation");
+
+ // Give second invocation time to start.
+ Thread.sleep(5000);
+
+ // Interrupt second invocation as it waits for a semaphore.
+ t2.interrupt();
+ log.info("interrupted second invocation");
+
+ // Wait until second invocation throws an exception.
+ synchronized (t2)
+ {
+ t2.wait(10000);
+ }
+
+ // Verify exception is an InterruptedException wrapped in a RuntimeException.
+ Throwable t = t2.throwable;
+ log.info("throwable: " + t);
+ assertTrue(t instanceof RuntimeException);
+ assertFalse(t instanceof CannotConnectException);
+ assertTrue(t.getCause() instanceof InterruptedException);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ Object o = invocation.getParameter();
+ if (!FAST.equals(o))
+ {
+ Thread.sleep(20000);
+ }
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class InvokerThread extends Thread
+ {
+ static int counter;
+ Client client;
+ String message;
+ Throwable throwable;
+
+ public InvokerThread(Client client, String message)
+ {
+ this.client = client;
+ this.message = message;
+ setName("InvokerThread:" + counter++);
+ }
+
+ public void run()
+ {
+ try
+ {
+ log.info("invocation succeeded: " + client.invoke(message));
+ }
+ catch (Throwable t)
+ {
+ throwable = t;
+ log.error("invocation error: " + t.getMessage());
+ }
+
+ synchronized (this)
+ {
+ notify();
+ }
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/InterruptedExceptionTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/interrupt/MockInvokerInterruptTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 7 months
JBoss Remoting SVN: r6041 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/connectionpool.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-08-04 22:10:04 -0400 (Wed, 04 Aug 2010)
New Revision: 6041
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/connectionpool/ConnectionPoolSizeTestCase.java
Log:
JBREM-1241: Added svn:eol-style subversion property.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/connectionpool/ConnectionPoolSizeTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/connectionpool/ConnectionPoolSizeTestCase.java 2010-08-05 02:09:36 UTC (rev 6040)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/connectionpool/ConnectionPoolSizeTestCase.java 2010-08-05 02:10:04 UTC (rev 6041)
@@ -1,198 +1,198 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, 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.transport.socket.connectionpool;
-
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.InvokerLocator;
-import org.jboss.remoting.ServerInvocationHandler;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.Callback;
-import org.jboss.remoting.callback.HandleCallbackException;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.transport.Connector;
-import org.jboss.remoting.transport.PortUtil;
-import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
-
-
-/**
- *
- * Unit test for JBREM-858.
- *
- * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
- * @version $Revision: 1.1 $
- * <p>
- * Copyright Dec 3, 2007
- * </p>
- */
-public class ConnectionPoolSizeTestCase extends TestCase
-{
- private static Logger log = Logger.getLogger(ConnectionPoolSizeTestCase.class);
-
- private static boolean firstTime = true;
-
- protected String host;
- protected int port;
- protected String locatorURI;
- protected InvokerLocator serverLocator;
- protected Connector connector;
- protected TestInvocationHandler invocationHandler;
-
-
- public void setUp() throws Exception
- {
- if (firstTime)
- {
- firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
- Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
- String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
- PatternLayout layout = new PatternLayout(pattern);
- ConsoleAppender consoleAppender = new ConsoleAppender(layout);
- Logger.getRootLogger().addAppender(consoleAppender);
- }
- }
-
-
- public void tearDown()
- {
- }
-
-
- public void testClientMaxPoolSizeInConnectionPoolKey() throws Throwable
- {
- log.info("entering " + getName());
-
- // Start server.
- setupServer();
-
- // Create clients.
- InvokerLocator clientLocator1 = new InvokerLocator(locatorURI + "/?" + MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG + "=3");
- InvokerLocator clientLocator2 = new InvokerLocator(locatorURI + "/?" + MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG + "=7");
- HashMap clientConfig = new HashMap();
- clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraClientConfig(clientConfig);
- Client client1 = new Client(clientLocator1, clientConfig);
- client1.connect();
- log.info("client1 is connected: " + clientLocator1);
- Client client2 = new Client(clientLocator2, clientConfig);
- client2.connect();
- log.info("client2 is connected: " + clientLocator2);
-
- // Test connections.
- assertEquals("abc", client1.invoke("abc"));
- log.info("connection 1 is good");
- assertEquals("def", client2.invoke("def"));
- log.info("connection 2 is good");
-
- log.info("invoker1: " + client1.getInvoker());
- log.info("invoker2: " + client2.getInvoker());
- assertTrue(client1.getInvoker() instanceof MicroSocketClientInvoker);
- assertTrue(client2.getInvoker() instanceof MicroSocketClientInvoker);
- MicroSocketClientInvoker invoker1 = (MicroSocketClientInvoker) client1.getInvoker();
- MicroSocketClientInvoker invoker2 = (MicroSocketClientInvoker) client2.getInvoker();
- assertNotSame(invoker1, invoker2);
- Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
- field.setAccessible(true);
- assertNotSame(field.get(invoker1), field.get(invoker2));
-
- field = MicroSocketClientInvoker.class.getDeclaredField("address");
- field.setAccessible(true);
- log.info("invoker1.address: " + field.get(invoker1));
- log.info("invoker2.address: " + field.get(invoker2));
-
- client1.disconnect();
- client2.disconnect();
- shutdownServer();
- log.info(getName() + " PASSES");
- }
-
-
- protected String getTransport()
- {
- return "socket";
- }
-
-
- protected void addExtraClientConfig(Map config) {}
- protected void addExtraServerConfig(Map config) {}
-
-
- protected void setupServer() throws Exception
- {
- host = InetAddress.getLocalHost().getHostAddress();
- port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
- serverLocator = new InvokerLocator(locatorURI);
- log.info("Starting remoting server with locator uri of: " + locatorURI);
- HashMap config = new HashMap();
- config.put(InvokerLocator.FORCE_REMOTE, "true");
- addExtraServerConfig(config);
- connector = new Connector(serverLocator, config);
- connector.create();
- invocationHandler = new TestInvocationHandler();
- connector.addInvocationHandler("test", invocationHandler);
- connector.start();
- }
-
-
- protected void shutdownServer() throws Exception
- {
- if (connector != null)
- connector.stop();
- }
-
-
- static class TestInvocationHandler implements ServerInvocationHandler
- {
- public void addListener(InvokerCallbackHandler callbackHandler) {}
- public Object invoke(final InvocationRequest invocation) throws Throwable
- {
- return invocation.getParameter();
- }
- public void removeListener(InvokerCallbackHandler callbackHandler) {}
- public void setMBeanServer(MBeanServer server) {}
- public void setInvoker(ServerInvoker invoker) {}
- }
-
-
- static class TestCallbackHandler implements InvokerCallbackHandler
- {
- public void handleCallback(Callback callback) throws HandleCallbackException
- {
- log.info("received callback");
- }
- }
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.transport.socket.connectionpool;
+
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
+
+
+/**
+ *
+ * Unit test for JBREM-858.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Dec 3, 2007
+ * </p>
+ */
+public class ConnectionPoolSizeTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ConnectionPoolSizeTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testClientMaxPoolSizeInConnectionPoolKey() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create clients.
+ InvokerLocator clientLocator1 = new InvokerLocator(locatorURI + "/?" + MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG + "=3");
+ InvokerLocator clientLocator2 = new InvokerLocator(locatorURI + "/?" + MicroSocketClientInvoker.MAX_POOL_SIZE_FLAG + "=7");
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client1 = new Client(clientLocator1, clientConfig);
+ client1.connect();
+ log.info("client1 is connected: " + clientLocator1);
+ Client client2 = new Client(clientLocator2, clientConfig);
+ client2.connect();
+ log.info("client2 is connected: " + clientLocator2);
+
+ // Test connections.
+ assertEquals("abc", client1.invoke("abc"));
+ log.info("connection 1 is good");
+ assertEquals("def", client2.invoke("def"));
+ log.info("connection 2 is good");
+
+ log.info("invoker1: " + client1.getInvoker());
+ log.info("invoker2: " + client2.getInvoker());
+ assertTrue(client1.getInvoker() instanceof MicroSocketClientInvoker);
+ assertTrue(client2.getInvoker() instanceof MicroSocketClientInvoker);
+ MicroSocketClientInvoker invoker1 = (MicroSocketClientInvoker) client1.getInvoker();
+ MicroSocketClientInvoker invoker2 = (MicroSocketClientInvoker) client2.getInvoker();
+ assertNotSame(invoker1, invoker2);
+ Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
+ field.setAccessible(true);
+ assertNotSame(field.get(invoker1), field.get(invoker2));
+
+ field = MicroSocketClientInvoker.class.getDeclaredField("address");
+ field.setAccessible(true);
+ log.info("invoker1.address: " + field.get(invoker1));
+ log.info("invoker2.address: " + field.get(invoker2));
+
+ client1.disconnect();
+ client2.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
}
\ No newline at end of file
Property changes on: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/connectionpool/ConnectionPoolSizeTestCase.java
___________________________________________________________________
Name: svn:eol-style
+ native
14 years, 7 months