tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1228724 - in /tomcat/trunk: java/org/apache/catalina/connector/ java/org/apache/coyote/ test/org/apache/catalina/mbeans/ test/org/apache/catalina/startup/ test/org/apache/tomcat/util/net/
Date Sat, 07 Jan 2012 20:52:08 GMT
Author: markt
Date: Sat Jan  7 20:52:08 2012
New Revision: 1228724

URL: http://svn.apache.org/viewvc?rev=1228724&view=rev
Log:
Bind connectors to localhost for unit tests
Improve format of JMX names that include an address
Update unit tests so they pass with the above changes

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/Connector.java
    tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java
    tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java
    tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
    tomcat/trunk/test/org/apache/tomcat/util/net/TestXxxEndpoint.java

Modified: tomcat/trunk/java/org/apache/catalina/connector/Connector.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Connector.java?rev=1228724&r1=1228723&r2=1228724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Connector.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Connector.java Sat Jan  7 20:52:08 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.catalina.connector;
 
+import java.net.InetAddress;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -881,7 +882,10 @@ public class Connector extends Lifecycle
             sb.append("auto-");
             sb.append(getProperty("nameIndex"));
         }
-        if (addressObj != null) {
+        if (addressObj instanceof InetAddress) {
+            sb.append(",address=");
+            sb.append(((InetAddress) addressObj).getHostAddress());
+        } else if(addressObj != null) {
             String address = addressObj.toString();
             if (address.length() > 0) {
                 sb.append(",address=");

Modified: tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java?rev=1228724&r1=1228723&r2=1228724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java (original)
+++ tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java Sat Jan  7 20:52:08 2012
@@ -255,7 +255,7 @@ public abstract class AbstractProtocol i
         StringBuilder name = new StringBuilder(getNamePrefix());
         name.append('-');
         if (getAddress() != null) {
-            name.append(getAddress());
+            name.append(getAddress().getHostAddress());
             name.append('-');
         }
         int port = getPort();
@@ -356,7 +356,7 @@ public abstract class AbstractProtocol i
         InetAddress address = getAddress();
         if (address != null) {
             name.append(",address=");
-            name.append(ObjectName.quote(address.toString()));
+            name.append(ObjectName.quote(address.getHostAddress()));
         }
         return new ObjectName(name.toString());
     }

Modified: tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java?rev=1228724&r1=1228723&r2=1228724&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java (original)
+++ tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java Sat Jan  7 20:52:08
2012
@@ -17,6 +17,8 @@
 package org.apache.catalina.mbeans;
 
 import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -45,6 +47,19 @@ public class TestRegistration extends To
 
     private static final String contextName = "/foo";
 
+    private static final String ADDRESS;
+
+    static {
+        String address;
+        try {
+            address = InetAddress.getByName("localhost").getHostAddress();
+        } catch (UnknownHostException e) {
+            address = "INIT_FAILED";
+        }
+        ADDRESS = address;
+    }
+
+
     private static String[] basicMBeanNames() {
         return new String[] {
             "Tomcat:type=Engine",
@@ -95,11 +110,14 @@ public class TestRegistration extends To
 
     private static String[] connectorMBeanNames(String port, String type) {
         return new String[] {
-        "Tomcat:type=Connector,port=" + port,
-        "Tomcat:type=GlobalRequestProcessor,name=\"http-" + type + "-" + port + "\"",
-        "Tomcat:type=Mapper,port=" + port,
-        "Tomcat:type=ProtocolHandler,port=" + port,
-        "Tomcat:type=ThreadPool,name=\"http-" + type + "-" + port + "\"",
+        "Tomcat:type=Connector,port=" + port + ",address=" + ADDRESS,
+        "Tomcat:type=GlobalRequestProcessor,name=\"http-" + type + "-" +
+                ADDRESS + "-" + port + "\"",
+        "Tomcat:type=Mapper,port=" + port + ",address=" + ADDRESS,
+        "Tomcat:type=ProtocolHandler,port=" + port + ",address=\"" + ADDRESS +
+                "\"",
+        "Tomcat:type=ThreadPool,name=\"http-" + type + "-" + ADDRESS + "-" +
+                port + "\"",
         };
     }
 

Modified: tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java?rev=1228724&r1=1228723&r2=1228724&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java Sat Jan  7 20:52:08
2012
@@ -23,6 +23,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.net.HttpURLConnection;
+import java.net.InetAddress;
 import java.net.URL;
 import java.util.List;
 import java.util.Map;
@@ -97,6 +98,9 @@ public abstract class TomcatBaseTest ext
 
         String protocol = getProtocol();
         Connector connector = new Connector(protocol);
+        // Listen only on localhost
+        connector.setAttribute("address",
+                InetAddress.getByName("localhost").getHostAddress());
         // Use random free port
         connector.setPort(0);
         // Mainly set to reduce timeouts during async tests

Modified: tomcat/trunk/test/org/apache/tomcat/util/net/TestXxxEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/net/TestXxxEndpoint.java?rev=1228724&r1=1228723&r2=1228724&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/net/TestXxxEndpoint.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/net/TestXxxEndpoint.java Sat Jan  7 20:52:08
2012
@@ -18,6 +18,7 @@
 package org.apache.tomcat.util.net;
 
 import java.io.File;
+import java.net.InetAddress;
 import java.net.ServerSocket;
 
 import static org.junit.Assert.assertNotNull;
@@ -136,7 +137,8 @@ public class TestXxxEndpoint extends Tom
                 nativeSocket = createAprSocket(port, pool);
                 assertTrue(nativeSocket != 0);
             } else {
-                s = new ServerSocket(port);
+                s = new ServerSocket(port, 100,
+                        InetAddress.getByName("localhost"));
             }
         } catch (Exception e1) {
             e = e1;
@@ -183,7 +185,8 @@ public class TestXxxEndpoint extends Tom
                 nativeSocket = createAprSocket(port, pool);
                 assertTrue(nativeSocket != 0);
             } else {
-                s = new ServerSocket(port);
+                s = new ServerSocket(port, 100,
+                        InetAddress.getByName("localhost"));
             }
         } catch (Exception e1) {
             e = e1;



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message