You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2011/06/20 13:13:41 UTC

svn commit: r1137595 - in /camel/trunk/components: camel-cxf/src/test/java/org/apache/camel/component/cxf/ camel-cxf/src/test/resources/org/apache/camel/component/cxf/ camel-test/src/main/java/org/apache/camel/test/

Author: ningjiang
Date: Mon Jun 20 11:13:41 2011
New Revision: 1137595

URL: http://svn.apache.org/viewvc?rev=1137595&view=rev
Log:
Added a test to verify the isse of jetty engine shutdown with camel context

Added:
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomerStartStopTest.java   (with props)
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CamelCxfConsumerContext.xml   (with props)
Modified:
    camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomerStartStopTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomerStartStopTest.java?rev=1137595&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomerStartStopTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomerStartStopTest.java Mon Jun 20 11:13:41 2011
@@ -0,0 +1,78 @@
+/**
+ * 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.camel.component.cxf;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine;
+import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CxfCustomerStartStopTest extends Assert {
+    
+    @Test
+    public void startAndStopService() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        // start a server    
+        context.addRoutes(new RouteBuilder() {
+            public void configure() {
+                from("cxf:http://localhost:7070/test?serviceClass=org.apache.camel.component.cxf.HelloService")
+                    .to("log:endpoint");
+            }
+        });
+        
+        context.start();
+        Thread.sleep(300);
+        context.stop();
+        Bus bus = BusFactory.getDefaultBus();
+        JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
+        JettyHTTPServerEngine engine = factory.retrieveJettyHTTPServerEngine(7070);
+        assertNotNull("Jetty engine should be found there", engine);
+        // Need to call the bus shutdown ourselves.
+        bus.shutdown(true);
+        engine = factory.retrieveJettyHTTPServerEngine(7070);
+        assertNull("Jetty engine should be removed", engine);
+    }
+    
+    @Test
+    public void startAndStopServiceFromSpring() throws Exception {
+        ClassPathXmlApplicationContext applicationContext = 
+            new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/CamelCxfConsumerContext.xml");
+        Bus bus = (Bus)applicationContext.getBean("cxf");
+        // Bus shutdown will be called when the application context is closed.
+        applicationContext.close();
+        JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
+        // test if the port is still used
+        JettyHTTPServerEngine engine = factory.retrieveJettyHTTPServerEngine(9003);
+        assertNull("Jetty engine should be removed", engine);
+    }
+    
+    
+    
+    
+    
+    
+
+}

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomerStartStopTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfCustomerStartStopTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CamelCxfConsumerContext.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CamelCxfConsumerContext.xml?rev=1137595&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CamelCxfConsumerContext.xml (added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CamelCxfConsumerContext.xml Mon Jun 20 11:13:41 2011
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:cxf="http://camel.apache.org/schema/cxf"
+
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+   
+   <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9003/CamelContext/RouterPort"
+    		serviceClass="org.apache.hello_world_soap_http.GreeterImpl">
+   </cxf:cxfEndpoint>
+   
+   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+    <route errorHandlerRef="noErrorHandler">
+      <from uri="cxf:bean:routerEndpoint" />
+      <to uri="log:test" />
+    </route>
+   </camelContext>
+
+   <bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/>
+
+</beans>
\ No newline at end of file

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CamelCxfConsumerContext.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CamelCxfConsumerContext.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CamelCxfConsumerContext.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java?rev=1137595&r1=1137594&r2=1137595&view=diff
==============================================================================
--- camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java (original)
+++ camel/trunk/components/camel-test/src/main/java/org/apache/camel/test/AvailablePortFinder.java Mon Jun 20 11:13:41 2011
@@ -60,7 +60,7 @@ public final class AvailablePortFinder {
      *
      * @throws NoSuchElementException if there are no ports available
      */
-    public synchronized static int getNextAvailable() {
+    public static synchronized int getNextAvailable() {
         int next = getNextAvailable(currentMinPort.get());
         currentMinPort.set(next + 1);
         return next;
@@ -72,7 +72,7 @@ public final class AvailablePortFinder {
      * @param fromPort the currentMinPort to scan for availability
      * @throws NoSuchElementException if there are no ports available
      */
-    public synchronized static int getNextAvailable(int fromPort) {
+    public static synchronized int getNextAvailable(int fromPort) {
         if (fromPort < currentMinPort.get() || fromPort > MAX_PORT_NUMBER) {
             throw new IllegalArgumentException("Invalid start currentMinPort: " + fromPort);
         }