You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2009/05/12 09:20:21 UTC

svn commit: r773809 - in /servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test: java/org/apache/servicemix/cxfbc/ java/org/apache/servicemix/cxfbc/ws/security/ resources/org/apache/servicemix/cxfbc/

Author: ffang
Date: Tue May 12 07:20:21 2009
New Revision: 773809

URL: http://svn.apache.org/viewvc?rev=773809&view=rev
Log:
[SMXCOMP-28]testcase to demostrate how cxf jms throttle work

Added:
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcJmsThrottleTest.java   (with props)
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/jms_transport_throttle.xml   (with props)
Modified:
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/GreeterImpl.java

Added: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcJmsThrottleTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcJmsThrottleTest.java?rev=773809&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcJmsThrottleTest.java (added)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcJmsThrottleTest.java Tue May 12 07:20:21 2009
@@ -0,0 +1,198 @@
+/*
+ * 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.servicemix.cxfbc;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.testutil.common.ServerLauncher;
+import org.apache.hello_world_soap_http.BadRecordLitFault;
+import org.apache.hello_world_soap_http.Greeter;
+import org.apache.hello_world_soap_http.HelloWorldService;
+import org.apache.hello_world_soap_http.NoSuchCodeLitFault;
+import org.apache.servicemix.jbi.container.SpringJBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+public class CxfBcJmsThrottleTest extends SpringTestSupport {
+
+    protected static boolean serversStarted;
+    private ServerLauncher sl;
+    private ServerLauncher embeddedLauncher;
+    
+    
+    
+    public void startServers() throws Exception {
+        if (serversStarted) {
+            return;
+        }
+        Map<String, String> props = new HashMap<String, String>();                
+        if (System.getProperty("activemq.store.dir") != null) {
+            props.put("activemq.store.dir", System.getProperty("activemq.store.dir"));
+        }
+        props.put("java.util.logging.config.file", 
+                  System.getProperty("java.util.logging.config.file"));
+        
+        assertTrue("server did not launch correctly", 
+                   launchServer(EmbededJMSBrokerLauncher.class, props, true));
+        embeddedLauncher =  sl;
+                
+        serversStarted = true;
+    }
+    
+    protected void setUp() throws Exception {
+        startServers();
+    }
+    
+    public void setUpJBI(String beanFile) throws Exception {
+        if (context != null) {
+            context.refresh();
+        }
+        transformer = new SourceTransformer();
+        if (beanFile == null) {
+            context = createBeanFactory();
+        } else {
+            context = createBeanFactory(beanFile);
+        }
+
+        jbi = (SpringJBIContainer) context.getBean("jbi");
+        assertNotNull("JBI Container not found in spring!", jbi);
+    }
+    
+    protected void tearDown() throws Exception {
+        try {
+            embeddedLauncher.stopServer();         
+        } catch (IOException ex) {
+            ex.printStackTrace();
+            fail("failed to stop server " + embeddedLauncher.getClass());
+        }
+        
+        serversStarted = false;
+    }
+    
+    public boolean launchServer(Class<?> clz, Map<String, String> p, boolean inProcess) {
+        boolean ok = false;
+        try { 
+            sl = new ServerLauncher(clz.getName(), p, null, inProcess);
+            ok = sl.launchServer();
+            assertTrue("server failed to launch", ok);
+            
+        } catch (IOException ex) {
+            ex.printStackTrace();
+            fail("failed to launch server " + clz);
+        }
+        
+        return ok;
+    }
+
+    public void testJMSThrottle() throws Exception {
+        setUpJBI("org/apache/servicemix/cxfbc/jms_transport_throttle.xml");
+        jmsTestBase();
+    }
+    
+    private void jmsTestBase() throws Exception, NoSuchCodeLitFault, BadRecordLitFault {
+        SpringBusFactory bf = new SpringBusFactory();
+        Bus testBus = bf.createBus("org/apache/servicemix/cxfbc/jms_test_timeout.xml");
+        BusFactory.setDefaultBus(testBus);
+
+        URL wsdl = getWSDLURL("org/apache/servicemix/cxfbc/ws/security/hello_world.wsdl");
+
+        QName serviceName = getServiceName(new QName(
+                "http://apache.org/hello_world_soap_http", "HelloWorldService"));
+        QName portName = getPortName(new QName(
+                "http://apache.org/hello_world_soap_http", "HelloWorldPort"));
+        
+        assertNotNull(wsdl);
+
+        HelloWorldService service = new HelloWorldService(wsdl, serviceName);
+        assertNotNull(service);
+
+        
+        Greeter greeter = service.getPort(portName, Greeter.class);
+        MultiClient[] clients = new MultiClient[10];
+        for (int i = 0; i < clients.length; i++) {
+            clients[i] = new MultiClient(greeter);
+        }
+
+        for (int i = 0; i < clients.length; i++) {
+            clients[i].start();
+        }
+
+        for (int i = 0; i < clients.length; i++) {
+            clients[i].join();
+            assertEquals(clients[i].getResult(), "Hello throttle");
+        }
+    }
+
+    @Override
+    protected AbstractXmlApplicationContext createBeanFactory() {
+        return new ClassPathXmlApplicationContext(
+                "org/apache/servicemix/cxfbc/jms_transport_throttle.xml");
+    }
+    
+    protected AbstractXmlApplicationContext createBeanFactory(String beanFile) {
+        // load cxf se and bc from specified spring config file
+        return new ClassPathXmlApplicationContext(beanFile);
+    }
+    
+    public QName getServiceName(QName q) {
+        return q;
+    }
+    
+    public QName getPortName(QName q) {
+        return q;
+    }
+    
+    public URL getWSDLURL(String s) throws Exception {
+        return CxfBcJmsThrottleTest.class.getClassLoader().getResource(s);
+    }
+
+}
+
+class MultiClient extends Thread {
+    private String result = "";
+    private Greeter greeter;
+    
+    public MultiClient(Greeter greeter) {
+        this.greeter = greeter;
+    }
+
+    public void run() {
+        try {
+            String greeting = greeter.greetMe("throttle");
+            result = result + greeting;
+                
+        } catch (Exception ex) {
+            result = "invocation failed " + ex.getMessage();
+        }
+    }
+
+    public String getResult() {
+        return result;
+    }
+
+}
+

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcJmsThrottleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcJmsThrottleTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/GreeterImpl.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/GreeterImpl.java?rev=773809&r1=773808&r2=773809&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/GreeterImpl.java (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ws/security/GreeterImpl.java Tue May 12 07:20:21 2009
@@ -26,6 +26,13 @@
 public class GreeterImpl 
     extends org.apache.hello_world_soap_http.GreeterImpl {
     public String greetMe(String me) {
+        if ("throttle".equals(me)) {
+            try {
+                Thread.sleep(2000);
+            } catch (InterruptedException e) {
+                //
+            }
+        }
         System.out.println("\n\n*** GreetMe called with: " + me + "***\n\n");
         return "Hello " + me;
     }

Added: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/jms_transport_throttle.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/jms_transport_throttle.xml?rev=773809&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/jms_transport_throttle.xml (added)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/jms_transport_throttle.xml Tue May 12 07:20:21 2009
@@ -0,0 +1,120 @@
+<?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:sm="http://servicemix.apache.org/config/1.0"
+       xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0"
+       xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0"
+       xmlns:test="urn:test"
+       xmlns:greeter="http://apache.org/hello_world_soap_http"
+       >
+  <sm:container id="jbi" embedded="true">
+    <sm:executorFactory>
+    <bean class="org.apache.servicemix.executors.impl.ExecutorFactoryImpl">
+      <property name="configs">
+        <map>
+          <entry key="flow.seda.servicemix-cxfse">
+            <bean class="org.apache.servicemix.executors.impl.ExecutorConfig">
+              <property name="corePoolSize" value="1"/>
+              <property name="queueSize" value="16"/>
+            </bean>
+          </entry>
+        </map>
+      </property>
+    </bean>
+  </sm:executorFactory>
+    
+    <sm:endpoints>
+      <cxfbc:consumer wsdl="org/apache/servicemix/cxfbc/ws/security/hello_world.wsdl"
+                      service="greeter:HelloWorldService"
+                      endpoint="HelloWorldPort"
+                      targetEndpoint="TimestampSignEncrypt"
+                      targetService="greeter:SOAPServiceWSSecurity"
+                      targetInterface="greeter:Greeter"
+                      synchronous="false"
+                      timeout="3"
+                      >
+        <cxfbc:inInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+        </cxfbc:inInterceptors>
+        <cxfbc:outInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+        </cxfbc:outInterceptors>
+        <cxfbc:inFaultInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+        </cxfbc:inFaultInterceptors>
+        <cxfbc:outFaultInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+        </cxfbc:outFaultInterceptors>
+        <cxfbc:features>
+           <bean class="org.apache.cxf.transport.jms.JMSConfigFeature">
+                <property name="jmsConfig">
+                    <bean class="org.apache.cxf.transport.jms.JMSConfiguration">
+                        <property name="connectionFactory">
+                            <ref bean="myConnectionFactory" />
+                        </property>
+                        <property name="targetDestination">
+                            <value>test.jmstransport.text</value>
+                        </property>
+                        <property name="timeToLive">
+                            <value>500000</value>
+                        </property>
+                        <property name="concurrentConsumers">
+                            <value>1</value>
+                        </property>
+                        <property name="maxConcurrentConsumers">
+                            <value>1</value>
+                        </property>
+                        <property name="maxSuspendedContinuations">
+                            <!--since corePoolSize of cxf se is 1, so set maxSuspendedContinuations aslo 1 to avoid the message queued in cxf se-->
+                            <value>1</value>
+                        </property>
+                        <property name="cacheLevel">
+                            <value>2</value>
+                        </property>
+                    </bean>
+                </property>
+            </bean>
+        </cxfbc:features>
+      </cxfbc:consumer>
+       <cxfse:endpoint>
+        <cxfse:pojo>
+          <bean class="org.apache.servicemix.cxfbc.ws.security.GreeterImpl" />
+        </cxfse:pojo>
+        <cxfse:inInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+        </cxfse:inInterceptors>
+        <cxfse:outInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+        </cxfse:outInterceptors>
+        <cxfse:inFaultInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+        </cxfse:inFaultInterceptors>
+        <cxfse:outFaultInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+        </cxfse:outFaultInterceptors>
+      </cxfse:endpoint>
+     
+    </sm:endpoints>
+    
+  </sm:container>
+  <bean id="myConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
+      <property name="brokerURL" value="tcp://localhost:61616" />
+  </bean>
+  
+</beans>

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/jms_transport_throttle.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/jms_transport_throttle.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/jms_transport_throttle.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml