camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1043354 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ tests/camel-itest/ tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/ tests/camel-itest/src/test/resources/ tests/camel-itest/src/test/resources/org/apa...
Date Wed, 08 Dec 2010 11:08:06 GMT
Author: davsclaus
Date: Wed Dec  8 11:08:06 2010
New Revision: 1043354

URL: http://svn.apache.org/viewvc?rev=1043354&view=rev
Log:
CAMEL-3317: Added unit test to test issue with hawtdb.

Added:
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.java
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/JmsToHawtDBRoute.java
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/MyConcatAggregatationStrategy.java
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/hawtdb/
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
    camel/trunk/tests/camel-itest/   (props changed)
    camel/trunk/tests/camel-itest/pom.xml
    camel/trunk/tests/camel-itest/src/test/resources/log4j.properties

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java?rev=1043354&r1=1043353&r2=1043354&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
Wed Dec  8 11:08:06 2010
@@ -203,12 +203,15 @@ public class DefaultExchangeHolder imple
 
         Map<String, Object> result = new LinkedHashMap<String, Object>();
         for (Map.Entry<String, Object> entry : map.entrySet()) {
-            Serializable converted = exchange.getContext().getTypeConverter().convertTo(Serializable.class,
exchange, entry.getValue());
-            if (converted != null) {
-                result.put(entry.getKey(), converted);
-            } else {
-                LOG.warn(type + " containing object: " + entry.getValue() + " with key: "
+ entry.getKey()
-                        + " cannot be serialized, it will be excluded by the holder.");
+            // silently skip any values which is null
+            if (entry.getValue() != null) {
+                Serializable converted = exchange.getContext().getTypeConverter().convertTo(Serializable.class,
exchange, entry.getValue());
+                if (converted != null) {
+                    result.put(entry.getKey(), converted);
+                } else {
+                    LOG.warn(type + " containing object: " + entry.getValue() + " with key:
" + entry.getKey()
+                            + " cannot be serialized, it will be excluded by the holder.");
+                }
             }
         }
 

Propchange: camel/trunk/tests/camel-itest/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Dec  8 11:08:06 2010
@@ -8,3 +8,5 @@ eclipse-classes
 *.i??
 activemq-data
 res
+
+data

Modified: camel/trunk/tests/camel-itest/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/pom.xml?rev=1043354&r1=1043353&r2=1043354&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/pom.xml (original)
+++ camel/trunk/tests/camel-itest/pom.xml Wed Dec  8 11:08:06 2010
@@ -90,6 +90,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel</groupId>
+            <artifactId>camel-hawtdb</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
             <artifactId>camel-jaxb</artifactId>
             <scope>test</scope>
         </dependency>

Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.java?rev=1043354&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.java
(added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.java
Wed Dec  8 11:08:06 2010
@@ -0,0 +1,80 @@
+/**
+ * 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.itest.hawtdb;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class JmsToHawtDBAggregateTest extends CamelSpringTestSupport {
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.xml");
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        // you can disable this to keep the data file on next test
+        deleteDirectory("data");
+        super.setUp();
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testJmsToHawtDBAggregateTest() throws Exception {
+        // number of rounds can be adjusted
+        int count = 30;
+
+        getMockEndpoint("mock:input").expectedMessageCount(10 * count);
+        getMockEndpoint("mock:out").expectedMessageCount(count);
+        getMockEndpoint("mock:result").expectedMessageCount(count);;
+        getMockEndpoint("mock:result").allMessages().body().isEqualTo("ABCDEFGHIJ");
+        getMockEndpoint("mock:result").expectsNoDuplicates(header("counter"));
+
+        for (int i = 0; i < count; i++) {
+            Map map = new HashMap();
+            map.put("counter", i);
+            map.put("group", "foo");
+
+            template.sendBodyAndHeaders("activemq:queue:foo", "A", map);
+            template.sendBodyAndHeaders("activemq:queue:foo", "B", map);
+            template.sendBodyAndHeaders("activemq:queue:foo", "C", map);
+            template.sendBodyAndHeaders("activemq:queue:foo", "D", map);
+            template.sendBodyAndHeaders("activemq:queue:foo", "E", map);
+            template.sendBodyAndHeaders("activemq:queue:foo", "F", map);
+            template.sendBodyAndHeaders("activemq:queue:foo", "G", map);
+            template.sendBodyAndHeaders("activemq:queue:foo", "H", map);
+            template.sendBodyAndHeaders("activemq:queue:foo", "I", map);
+            template.sendBodyAndHeaders("activemq:queue:foo", "J", map);
+
+            // sleep 1 sec before sending next batch
+            Thread.sleep(1000);
+        }
+
+        // adjust timeout if you do a very long test
+        assertMockEndpointsSatisfied(60, TimeUnit.SECONDS);
+    }
+}

Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/JmsToHawtDBRoute.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/JmsToHawtDBRoute.java?rev=1043354&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/JmsToHawtDBRoute.java
(added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/JmsToHawtDBRoute.java
Wed Dec  8 11:08:06 2010
@@ -0,0 +1,43 @@
+/**
+ * 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.itest.hawtdb;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hawtdb.HawtDBAggregationRepository;
+
+/**
+ * @version $Revision$
+ */
+public class JmsToHawtDBRoute extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        from("activemq:queue:foo")
+            .transacted()
+                .to("mock:input")
+                //.log("Incoming ${header.group} with body ${body}")
+                .aggregate(header("group"), new MyConcatAggregatationStrategy())
+                    .aggregationRepository(new HawtDBAggregationRepository("events", "data/hawtdb.dat"))
+                    .completionSize(10)
+                    .log("Aggregated #${header.counter} ${header.group} with body ${body}")
+                    .to("activemq:queue:out")
+                    .to("mock:out");
+
+        from("activemq:queue:out")
+            .to("mock:result");
+    }
+}

Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/MyConcatAggregatationStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/MyConcatAggregatationStrategy.java?rev=1043354&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/MyConcatAggregatationStrategy.java
(added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/hawtdb/MyConcatAggregatationStrategy.java
Wed Dec  8 11:08:06 2010
@@ -0,0 +1,40 @@
+/**
+ * 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.itest.hawtdb;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+
+/**
+ * @version $Revision$
+ */
+public class MyConcatAggregatationStrategy implements AggregationStrategy {
+
+    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+        if (oldExchange == null) {
+            return newExchange;
+        }
+
+        String body1 = oldExchange.getIn().getBody(String.class);
+        String body2 = newExchange.getIn().getBody(String.class);
+        String body = body1 + body2;
+
+        oldExchange.getIn().setBody(body);
+        return oldExchange;
+    }
+
+}

Modified: camel/trunk/tests/camel-itest/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/log4j.properties?rev=1043354&r1=1043353&r2=1043354&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/log4j.properties (original)
+++ camel/trunk/tests/camel-itest/src/test/resources/log4j.properties Wed Dec  8 11:08:06
2010
@@ -20,8 +20,8 @@
 #
 log4j.rootLogger=INFO, file
 
-log4j.logger.org.springframework=WARN
-log4j.logger.org.apache.activemq=WARN
+#log4j.logger.org.springframework=WARN
+#log4j.logger.org.apache.activemq=WARN
 #log4j.logger.org.apache.camel=TRACE
 #log4j.logger.org.apache.camel=DEBUG
 #log4j.logger.org.apache.camel.component.file=TRACE

Added: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.xml?rev=1043354&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.xml
(added)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/hawtdb/JmsToHawtDBAggregateTest.xml
Wed Dec  8 11:08:06 2010
@@ -0,0 +1,53 @@
+<?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"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+    <!-- ActiveMQ connection factory -->
+    <bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
+        <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
+    </bean>
+
+    <!-- Spring JMX TX manager -->
+    <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
+        <property name="connectionFactory" ref="jmsFactory"/>
+    </bean>
+
+    <!-- Jms configuration -->
+    <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
+        <property name="connectionFactory" ref="jmsFactory"/>
+        <property name="transactionManager" ref="jmsTransactionManager"/>
+        <property name="transacted" value="true"/>
+    </bean>
+
+    <!-- ActiveMQ component to be used in Camel -->
+    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
+        <property name="connectionFactory" ref="jmsFactory"/>
+        <property name="configuration" ref="jmsConfig"/>
+    </bean>
+
+    <bean id="route" class="org.apache.camel.itest.hawtdb.JmsToHawtDBRoute"/>
+
+    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+        <routeBuilder ref="route"/>
+    </camelContext>
+
+</beans>



Mime
View raw message