cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r597308 - /incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/BusShutdownTest.java
Date Thu, 22 Nov 2007 06:13:34 GMT
Author: ningjiang
Date: Wed Nov 21 22:13:32 2007
New Revision: 597308

URL: http://svn.apache.org/viewvc?rev=597308&view=rev
Log:
CXF1217 Added Gary's test case into the systest

Added:
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/BusShutdownTest.java
  (with props)

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/BusShutdownTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/BusShutdownTest.java?rev=597308&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/BusShutdownTest.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/BusShutdownTest.java
Wed Nov 21 22:13:32 2007
@@ -0,0 +1,109 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.bus;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.net.URL;
+
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.hello_world_soap_http.Greeter;
+import org.apache.hello_world_soap_http.GreeterImpl;
+import org.apache.hello_world_soap_http.SOAPService;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BusShutdownTest extends Assert {
+    private String close;
+    
+    @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);
+        }
+    }
+    
+    @Test
+    public void testStartWorkShutdownWork() throws Exception {
+        
+        
+        URL wsdlUrl = getClass().getResource("/wsdl/hello_world.wsdl");
+        assertNotNull("wsdl resource was not found", wsdlUrl); 
+
+        String serverAddr = "http://localhost:9098/greeter/port";
+        makeTwoWayCallOnNewBus(wsdlUrl, serverAddr);
+        Thread.sleep(4000);
+        
+        // verify sutdown cleans the slate and reverts to null state
+        //
+        // This test should not need to workaroundHangWithDifferentAddr,
+        // and when using ADDR, the test should not need: 
+        //  org.apache.cxf.transports.http_jetty.DontClosePort
+        //
+        String workaroundHangWithDifferentAddr = serverAddr;
+        
+        // reusing same address will cause failure, hang on client invoke
+        //possibleWorkaroundHandWithDifferentAddr = ADDR.replace('8', '9');
+        makeTwoWayCallOnNewBus(wsdlUrl, workaroundHangWithDifferentAddr);
+    }
+
+    private void makeTwoWayCallOnNewBus(URL wsdlUrl, String address) {
+        SpringBusFactory bf = new SpringBusFactory();
+        Bus bus = bf.createBus();
+        SpringBusFactory.setDefaultBus(bus);
+        createService(address);
+        doWork(wsdlUrl, address);
+        // this should revert the JVM to its original state pending gc
+        bus.shutdown(false);
+    }
+
+    private void doWork(URL wsdlUrl, String address) {
+        SOAPService service = new SOAPService(wsdlUrl);
+        assertNotNull(service);        
+        Greeter greeter = service.getSoapPort();
+        
+        // overwrite client address
+        InvocationHandler handler  = Proxy.getInvocationHandler(greeter);
+        BindingProvider bp = (BindingProvider)handler;    
+        bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+                                   address);
+        // invoke twoway call
+        greeter.sayHi();
+        
+    }
+
+    private void createService(String address) {        
+        Object impl = new GreeterImpl();
+        Endpoint.publish(address, impl);
+    }
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/BusShutdownTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/BusShutdownTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message