camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r802038 - in /camel/sandbox/tuning-experiment: camel-core/src/main/java/org/apache/camel/impl/ components/camel-jms/src/main/java/org/apache/camel/component/jms/ components/camel-jms/src/test/java/org/apache/camel/component/jms/ components/...
Date Fri, 07 Aug 2009 15:08:33 GMT
Author: davsclaus
Date: Fri Aug  7 15:08:33 2009
New Revision: 802038

URL: http://svn.apache.org/viewvc?rev=802038&view=rev
Log:
More tuning

Added:
    camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/
    camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteCountTest.java
  (with props)
    camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteTest.java
  (with props)
Modified:
    camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
    camel/sandbox/tuning-experiment/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
    camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/ConsumeJmsBytesMessageTest.java
    camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/ConsumeJmsMapMessageTest.java
    camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeadLetterQueueUsingTransferExchangeTest.java
    camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/ActiveMQPropagateHeadersTest.java
    camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java
    camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java
    camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsToFileMessageIdTest.java

Modified: camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java?rev=802038&r1=802037&r2=802038&view=diff
==============================================================================
--- camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
(original)
+++ camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
Fri Aug  7 15:08:33 2009
@@ -87,13 +87,36 @@
      * @param payload  the payload with the values
      */
     public static void unmarshal(Exchange exchange, DefaultExchangeHolder payload) {
-        exchange.getIn().setBody(payload.inBody);
-        exchange.getIn().setHeaders(payload.inHeaders);
-        if (payload.outBody != null) {
-            exchange.getOut().setBody(payload.outBody);
-            exchange.getOut().setHeaders(payload.outHeaders);
-            exchange.getOut().setFault(payload.outFaultFlag.booleanValue());
+        if (exchange.getIn() instanceof CopyOnWriteMessageFacade) {
+            // important to avoid re-entrant entering this for ever as the facade will do
a copy
+            // that this unmarshalling was highly invoked from in etc. a jms binding from
+            // create body while we are setting a body (mutating)
+            DefaultMessage in = new DefaultMessage();
+            in.setBody(payload.inBody);
+            if (payload.inHeaders != null) {
+                in.setHeaders(payload.inHeaders);
+            }
+            exchange.setIn(in);
+
+            if (payload.outBody != null) {
+                DefaultMessage out = new DefaultMessage();
+                out.setBody(payload.outBody);
+                if (payload.outHeaders != null) {
+                    out.setHeaders(payload.outHeaders);
+                }
+                out.setFault(payload.outFaultFlag);
+                exchange.setOut(out);
+            }
+        } else {
+            exchange.getIn().setBody(payload.inBody);
+            exchange.getIn().setHeaders(payload.inHeaders);
+            if (payload.outBody != null) {
+                exchange.getOut().setBody(payload.outBody);
+                exchange.getOut().setHeaders(payload.outHeaders);
+                exchange.getOut().setFault(payload.outFaultFlag);
+            }
         }
+
         for (String key : payload.properties.keySet()) {
             exchange.setProperty(key, payload.properties.get(key));
         }

Modified: camel/sandbox/tuning-experiment/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java?rev=802038&r1=802037&r2=802038&view=diff
==============================================================================
--- camel/sandbox/tuning-experiment/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
(original)
+++ camel/sandbox/tuning-experiment/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
Fri Aug  7 15:08:33 2009
@@ -102,9 +102,9 @@
                         // do not send a reply but wrap and rethrow the exception
                         rce = wrapRuntimeCamelException(exchange.getException());
                     }
-                } else if (exchange.getOut().getBody() != null) {
+                } else if (exchange.hasOut()) {
                     // a fault occurred while processing
-                    body = (JmsMessage) exchange.getOut();
+                    body = exchange.getOut();
                     sendReply = true;
                 }
             } else if (exchange.hasOut()) {

Modified: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/ConsumeJmsBytesMessageTest.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/ConsumeJmsBytesMessageTest.java?rev=802038&r1=802037&r2=802038&view=diff
==============================================================================
--- camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/ConsumeJmsBytesMessageTest.java
(original)
+++ camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/ConsumeJmsBytesMessageTest.java
Fri Aug  7 15:08:33 2009
@@ -112,7 +112,7 @@
                     public void process(Exchange exchange) throws Exception {
                         // This should be a JMS Exchange
                         assertNotNull(ExchangeHelper.getBinding(exchange, JmsBinding.class));
-                        JmsMessage in = (JmsMessage) exchange.getIn();
+                        JmsMessage in = ExchangeHelper.getInMessage(exchange, JmsMessage.class);
                         assertNotNull(in);
                         assertIsInstanceOf(BytesMessage.class, in.getJmsMessage());
                     }

Modified: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/ConsumeJmsMapMessageTest.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/ConsumeJmsMapMessageTest.java?rev=802038&r1=802037&r2=802038&view=diff
==============================================================================
--- camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/ConsumeJmsMapMessageTest.java
(original)
+++ camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/ConsumeJmsMapMessageTest.java
Fri Aug  7 15:08:33 2009
@@ -115,7 +115,7 @@
                     public void process(Exchange exchange) throws Exception {
                         // This should be a JMS Exchange
                         assertNotNull(ExchangeHelper.getBinding(exchange, JmsBinding.class));
-                        JmsMessage in = (JmsMessage) exchange.getIn();
+                        JmsMessage in = ExchangeHelper.getInMessage(exchange, JmsMessage.class);
                         assertNotNull(in);
                         assertIsInstanceOf(MapMessage.class, in.getJmsMessage());
                     }

Modified: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeadLetterQueueUsingTransferExchangeTest.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeadLetterQueueUsingTransferExchangeTest.java?rev=802038&r1=802037&r2=802038&view=diff
==============================================================================
--- camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeadLetterQueueUsingTransferExchangeTest.java
(original)
+++ camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsDeadLetterQueueUsingTransferExchangeTest.java
Fri Aug  7 15:08:33 2009
@@ -22,7 +22,6 @@
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -58,10 +57,6 @@
         template.sendBody("direct:start", "Kabom");
 
         assertMockEndpointsSatisfied();
-
-        Exchange dead = mock.getReceivedExchanges().get(0);
-        // caused exception is stored as a property
-        assertEquals("Kabom", dead.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class).getMessage());
     }
 
     protected CamelContext createCamelContext() throws Exception {
@@ -89,7 +84,13 @@
                     }
                 }).to("mock:result");
 
-                from(getUri()).to("mock:dead");
+                from(getUri()).process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        // caused exception is stored as a property
+                        assertEquals("Kabom", exchange.getIn().getBody());
+                        assertEquals("Kabom", exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
Exception.class).getMessage());
+                    }
+                }).to("mock:dead");
             }
         };
     }

Modified: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/ActiveMQPropagateHeadersTest.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/ActiveMQPropagateHeadersTest.java?rev=802038&r1=802037&r2=802038&view=diff
==============================================================================
--- camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/ActiveMQPropagateHeadersTest.java
(original)
+++ camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/ActiveMQPropagateHeadersTest.java
Fri Aug  7 15:08:33 2009
@@ -84,7 +84,7 @@
                     public void process(Exchange exchange) throws Exception {
                         // lets set the custom JMS headers using the JMS API
                         assertNotNull(ExchangeHelper.getBinding(exchange, JmsBinding.class));
-                        JmsMessage in = (JmsMessage) exchange.getIn();
+                        JmsMessage in = ExchangeHelper.getInMessage(exchange, JmsMessage.class);
                         assertNotNull(in);
                         Message inMessage = in.getJmsMessage();
                         inMessage.setJMSReplyTo(replyQueue);

Modified: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java?rev=802038&r1=802037&r2=802038&view=diff
==============================================================================
--- camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java
(original)
+++ camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BruceHandlingBeanExceptionTest.java
Fri Aug  7 15:08:33 2009
@@ -43,12 +43,11 @@
         assertEquals("This is a fault message", out);
     }
 
-    @Ignore
-    @Test    
-    public void xxxtestSendError() throws Exception {
-        // TODO: See CAMEL-585
+    @Test
+    public void testSendError() throws Exception {
         Object out = template.requestBody("activemq:queue:error", "Hello World");
-        assertEquals("Damm", out);
+        IllegalArgumentException e = assertIsInstanceOf(IllegalArgumentException.class, out);
+        assertEquals("Forced exception by unit test", e.getMessage());
     }
 
     protected CamelContext createCamelContext() throws Exception {
@@ -69,7 +68,7 @@
 
                 from("activemq:queue:fault").setFaultBody(constant("This is a fault message"));
 
-                from("activemq:queue:error").bean(MyExceptionBean.class);
+                from("activemq:queue:error?transferException=true").bean(MyExceptionBean.class);
             }
         };
     }

Modified: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java?rev=802038&r1=802037&r2=802038&view=diff
==============================================================================
--- camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java
(original)
+++ camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsGetHeaderKeyFormatIssueWithContentTypeHeaderTest.java
Fri Aug  7 15:08:33 2009
@@ -16,15 +16,15 @@
  */
 package org.apache.camel.component.jms.issues;
 
+import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
 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.component.mock.MockEndpoint;
 import org.apache.camel.component.jms.JmsMessage;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.CamelTestSupport;
-
-import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
+import org.apache.camel.util.ExchangeHelper;
 
 /**
  * Unit test to verify that we can route a JMS message and do header lookup by name
@@ -70,7 +70,7 @@
                             assertEquals("text/plain", exchange.getIn().getHeader("Content-Type"));
 
                             // do not mutate it
-                            JmsMessage msg = assertIsInstanceOf(JmsMessage.class, exchange.getIn());
+                            JmsMessage msg = ExchangeHelper.getInMessage(exchange, JmsMessage.class);
                             assertNotNull("javax.jms.Message should not be null", msg.getJmsMessage());
                             assertEquals("Should NOT have been muated", false, msg.shouldCreateNewMessage());
                         }

Modified: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsToFileMessageIdTest.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsToFileMessageIdTest.java?rev=802038&r1=802037&r2=802038&view=diff
==============================================================================
--- camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsToFileMessageIdTest.java
(original)
+++ camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsToFileMessageIdTest.java
Fri Aug  7 15:08:33 2009
@@ -26,6 +26,7 @@
 import org.apache.camel.component.jms.JmsMessage;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ExchangeHelper;
 import org.junit.Test;
 import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
 
@@ -68,7 +69,7 @@
                                 String camelId = exchange.getIn().getMessageId();
                                 assertNotNull(camelId);
 
-                                JmsMessage jms = (JmsMessage) exchange.getIn();
+                                JmsMessage jms = ExchangeHelper.getInMessage(exchange, JmsMessage.class);
                                 String jmsId = jms.getJmsMessage().getJMSMessageID();
                                 assertNotNull(jmsId);
 

Added: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteCountTest.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteCountTest.java?rev=802038&view=auto
==============================================================================
--- camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteCountTest.java
(added)
+++ camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteCountTest.java
Fri Aug  7 15:08:33 2009
@@ -0,0 +1,138 @@
+/**
+ * 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.jms.tuning;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+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.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+/**
+ * @version $Revision$
+ */
+public class PerformanceRouteCountTest extends CamelTestSupport {
+
+    private AtomicInteger gold = new AtomicInteger();
+    private AtomicInteger silver = new AtomicInteger();
+    private AtomicInteger bronze = new AtomicInteger();
+    private AtomicInteger audit = new AtomicInteger();
+
+    private int size = 1000;
+
+    @Test
+    public void testPerformance() throws Exception {
+        if (!canRunOnThisPlatform()) {
+            return;
+        }
+
+        long start = System.currentTimeMillis();
+
+        for (int i = 0; i < size; i++) {
+            String type;
+            if (i % 10 == 0) {
+                type = "silver";
+            } else if (i % 2 == 0) {
+                 type = "gold";
+            } else {
+                type = "bronze";
+            }
+            template.sendBodyAndHeader("activemq:queue:inbox", "Message " + i, "type", type);
+        }
+
+        long delta = System.currentTimeMillis() - start;
+        System.out.println("RoutePerformanceCountTest: Sent: " + size + " Took: " + delta
+ " ms");
+
+        // give time to finish
+        Thread.sleep(1000);
+
+        System.out.println("gold " + gold.intValue());
+        System.out.println("silver " + silver.intValue());
+        System.out.println("bronze " + bronze.intValue());
+        System.out.println("audit " + audit.intValue());
+    }
+
+    private boolean canRunOnThisPlatform() {
+        String os = System.getProperty("os.name");
+        // HP-UX is just to slow to run this test
+        return !os.toLowerCase().contains("hp-ux");
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+        camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
+
+        return camelContext;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("activemq:queue:inbox?concurrentConsumers=10")
+                    .wireTap("activemq:topic:audit")
+                    .choice()
+                        .when(header("type").isEqualTo("gold"))
+                            .to("direct:gold")
+                        .when(header("type").isEqualTo("silver"))
+                            .to("direct:silver")
+                        .otherwise()
+                            .to("direct:bronze")
+                        .end();
+
+                from("direct:gold")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            gold.incrementAndGet();
+                        }
+                    });
+
+                from("direct:silver")
+                    .delay(5)
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                silver.incrementAndGet();
+                            }
+                        });
+
+                from("direct:bronze")
+                    .delay(10)
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                bronze.incrementAndGet();
+                            }
+                        });
+
+                from("activemq:topic:audit")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            audit.incrementAndGet();
+                        }
+                    });
+            }
+        };
+    }
+}
\ No newline at end of file

Propchange: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteCountTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteCountTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteTest.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteTest.java?rev=802038&view=auto
==============================================================================
--- camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteTest.java
(added)
+++ camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteTest.java
Fri Aug  7 15:08:33 2009
@@ -0,0 +1,112 @@
+/**
+ * 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.jms.tuning;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+/**
+ * @version $Revision$
+ */
+public class PerformanceRouteTest extends CamelTestSupport {
+
+    private int size = 1000;
+
+    @Test
+    public void testPerformance() throws Exception {
+        if (!canRunOnThisPlatform()) {
+            return;
+        }
+
+        long start = System.currentTimeMillis();
+
+        getMockEndpoint("mock:audit").expectedMessageCount(size);
+        getMockEndpoint("mock:audit").expectsNoDuplicates().body();
+        
+        getMockEndpoint("mock:gold").expectedMessageCount((size / 2) - (size / 10));
+        getMockEndpoint("mock:silver").expectedMessageCount(size / 10);
+
+        for (int i = 0; i < size; i++) {
+            String type;
+            if (i % 10 == 0) {
+                type = "silver";
+            } else if (i % 2 == 0) {
+                 type = "gold";
+            } else {
+                type = "bronze";
+            }
+            template.sendBodyAndHeader("activemq:queue:inbox", "Message " + i, "type", type);
+        }
+        assertMockEndpointsSatisfied();
+
+        long delta = System.currentTimeMillis() - start;
+        System.out.println("RoutePerformanceTest: Sent: " + size + " Took: " + delta + "
ms");
+    }
+
+    private boolean canRunOnThisPlatform() {
+        String os = System.getProperty("os.name");
+        // HP-UX is just to slow to run this test
+        return !os.toLowerCase().contains("hp-ux");
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+        camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
+
+        return camelContext;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("activemq:queue:inbox?concurrentConsumers=10")
+                    .wireTap("activemq:topic:audit")
+                    .choice()
+                        .when(header("type").isEqualTo("gold"))
+                            .to("direct:gold")
+                        .when(header("type").isEqualTo("silver"))
+                            .to("direct:silver")
+                        .otherwise()
+                            .to("direct:bronze")
+                        .end();
+
+                from("direct:gold")
+                    .to("mock:gold");
+
+                from("direct:silver")
+                    .delay(5)
+                    .to("mock:silver");
+
+                from("direct:bronze")
+                    .delay(10)
+                    .to("mock:bronze");
+
+                from("activemq:topic:audit").to("mock:audit");
+            }
+        };
+    }
+}

Propchange: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/sandbox/tuning-experiment/components/camel-jms/src/test/java/org/apache/camel/component/jms/tuning/PerformanceRouteTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message