Author: dkulp
Date: Mon Oct 22 14:11:46 2007
New Revision: 587258
URL: http://svn.apache.org/viewvc?rev=587258&view=rev
Log:
Merged revisions 586996 via svnmerge from
https://svn.apache.org/repos/asf/incubator/cxf/trunk
........
r586996 | ningjiang | 2007-10-22 01:09:13 -0400 (Mon, 22 Oct 2007) | 1 line
CXF-1120 Fixed the EngineLifecycleTest issue on Windows box, also enabled the
Engine's shutdown property
........
Modified:
incubator/cxf/branches/2.0.x-fixes/ (props changed)
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java?rev=587258&r1=587257&r2=587258&view=diff
==============================================================================
---
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
(original)
+++
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/http_jetty/EngineLifecycleTest.java
Mon Oct 22 14:11:46 2007
@@ -22,6 +22,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.ServerSocket;
@@ -29,6 +30,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
+import java.nio.channels.ServerSocketChannel;
import java.util.Properties;
@@ -41,11 +43,14 @@
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.transport.http_jetty.JettyHTTPDestination;
import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine;
+import org.junit.After;
import org.junit.Assert;
-import org.junit.Ignore;
+import org.junit.Before;
+
import org.junit.Test;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
@@ -58,13 +63,30 @@
* is extra jetty configuration.
*/
public class EngineLifecycleTest extends Assert {
+ private String close;
private GenericApplicationContext applicationContext;
+
+
private void readBeans(Resource beanResource) {
XmlBeanDefinitionReader reader = new
XmlBeanDefinitionReader(applicationContext);
reader.loadBeanDefinitions(beanResource);
}
+ @Before
+ public void setSystemProperties() {
+ close =
System.getProperty("org.apache.cxf.transports.http_jetty.DontClosePort");
+
System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort",
"false");
+
+ }
+
+ @After
+ public void resetSystemProperties() {
+ if (close != null) {
+
System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort", close);
+ }
+ }
+
public void setUpBus(boolean includeService) throws Exception {
applicationContext = new GenericApplicationContext();
readBeans(new ClassPathResource("META-INF/cxf/cxf.xml"));
@@ -138,14 +160,17 @@
Bus bus = (Bus)applicationContext.getBean("cxf");
bus.shutdown(true);
applicationContext.destroy();
- applicationContext.close();
+ applicationContext.close();
+ Thread.sleep(2000);
+
}
-
- @Ignore
+
+
@Test
- public void testUpDownWithServlets() throws Exception {
+ public void testUpDownWithServlets() throws Exception {
setUpBus(true);
-
+ setReuseAddrForServer(8801);
+ setReuseAddrForServer(8808);
Bus bus = (Bus)applicationContext.getBean("cxf");
ServerRegistry sr = bus.getExtension(ServerRegistry.class);
ServerImpl si = (ServerImpl) sr.getServers().get(0);
@@ -166,6 +191,8 @@
getTestHtml();
invokeService();
shutdownService();
+ verifyNoServer(8808);
+ verifyNoServer(8801);
}
private void setReuseAddrForServer(int port) throws IOException {
@@ -178,11 +205,19 @@
JettyHTTPServerEngine e = (JettyHTTPServerEngine) jhd.getEngine();
Connector connector = e.getConnector();
if (connector.getPort() == port) {
- connector.open(); // it might not be opened.
- ServerSocket socket = (ServerSocket)connector.getConnection();
+ if (connector.getConnection() == null) {
+ connector.open(); // it might not be opened.
+ }
+ ServerSocket socket = null;
+ if (connector instanceof SelectChannelConnector) {
+ ServerSocketChannel channel = (ServerSocketChannel)
connector.getConnection();
+ socket = channel.socket();
+ } else {
+ socket = (ServerSocket)connector.getConnection();
+ }
assertNotNull("connector must have socket", socket);
socket.setReuseAddress(true);
- turnedOnReuseAddr = true;
+ turnedOnReuseAddr = socket.getReuseAddress();
}
}
assertTrue(turnedOnReuseAddr); // insure that we actually found the
server for 8801 and did the deed.
@@ -195,7 +230,7 @@
socket.close();
} catch (UnknownHostException e) {
fail("Unknown host for local address");
- } catch (IOException e) {
+ } catch (IOException e) {
return; // this is what we want.
}
fail("Server on port " + port + " accepted a connection.");
@@ -207,27 +242,29 @@
* @throws Exception
*/
@Test
- public void testServerUpDownUp() throws Exception {
+ public void testServerUpDownUp() throws Exception {
+
setUpBus(true);
setReuseAddrForServer(8801);
-
+ setReuseAddrForServer(8808);
getTestHtml();
invokeService();
invokeService8801();
shutdownService();
verifyNoServer(8808);
verifyNoServer(8801);
-
+
+
setUpBus(true);
setReuseAddrForServer(8801);
-
+ setReuseAddrForServer(8808);
invokeService();
invokeService8801();
getTestHtml();
-
shutdownService();
verifyNoServer(8808);
verifyNoServer(8801);
+
}