cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r586917 - /incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
Date Sun, 21 Oct 2007 17:10:24 GMT
Author: bimargulies
Date: Sun Oct 21 10:10:23 2007
New Revision: 586917

URL: http://svn.apache.org/viewvc?rev=586917&view=rev
Log:
The server socket might be null when we go to turn on reuse address. I don't know why, but
that's 
apparently just how Jetty works.

Modified:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java?rev=586917&r1=586916&r2=586917&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
Sun Oct 21 10:10:23 2007
@@ -20,12 +20,15 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.net.HttpURLConnection;
+import java.net.InetAddress;
 import java.net.ServerSocket;
-import java.net.SocketException;
+import java.net.Socket;
 import java.net.URL;
 import java.net.URLConnection;
+import java.net.UnknownHostException;
 import java.util.Properties;
 
 
@@ -41,6 +44,7 @@
 import org.junit.Assert;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.mortbay.jetty.Connector;
 import org.mortbay.jetty.Handler;
 import org.mortbay.jetty.webapp.WebAppContext;
 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
@@ -164,7 +168,7 @@
         shutdownService();
     }
     
-    private void setReuseAddrForServer(int port) throws SocketException {
+    private void setReuseAddrForServer(int port) throws IOException {
         Bus bus = (Bus)applicationContext.getBean("cxf");
         boolean turnedOnReuseAddr = false;
         ServerRegistry sr = bus.getExtension(ServerRegistry.class);
@@ -172,8 +176,11 @@
             ServerImpl si = (ServerImpl) server;
             JettyHTTPDestination jhd = (JettyHTTPDestination) si.getDestination();
             JettyHTTPServerEngine e = (JettyHTTPServerEngine) jhd.getEngine();
-            if (e.getConnector().getPort() == port) {
-                ServerSocket socket = (ServerSocket)e.getConnector().getConnection();
+            Connector connector = e.getConnector();
+            if (connector.getPort() == port) {
+                connector.open();  // it might not be opened. 
+                ServerSocket socket = (ServerSocket)connector.getConnection();
+                assertNotNull("connector must have socket", socket);
                 socket.setReuseAddress(true);
                 turnedOnReuseAddr = true;
             }
@@ -181,6 +188,19 @@
         assertTrue(turnedOnReuseAddr); // insure that we actually found the server for 8801
and did the deed.
         
     }
+    
+    private void verifyNoServer(int port) {
+        try {
+            Socket socket = new Socket(InetAddress.getLocalHost(), port);
+            socket.close();
+        } catch (UnknownHostException e) {
+            fail("Unknown host for local address");
+        } catch (IOException e) {
+            return; // this is what we want.
+        }
+        fail("Server on port " + port + " accepted a connection.");
+        
+    }
 
     /**
      * 
@@ -195,6 +215,8 @@
         invokeService();    
         invokeService8801();
         shutdownService();
+        verifyNoServer(8808);
+        verifyNoServer(8801);
 
         setUpBus(true);
         setReuseAddrForServer(8801);
@@ -204,6 +226,9 @@
         getTestHtml();
         
         shutdownService();
+        verifyNoServer(8808);
+        verifyNoServer(8801);
+
     }
 
 }



Mime
View raw message