You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2011/11/02 19:48:29 UTC
svn commit: r1196758 - in /camel/trunk/components/camel-spring/src/test:
java/org/apache/camel/spring/processor/aggregator/
resources/org/apache/camel/spring/processor/aggregator/
Author: janstey
Date: Wed Nov 2 18:48:28 2011
New Revision: 1196758
URL: http://svn.apache.org/viewvc?rev=1196758&view=rev
Log:
CAMEL-4606 - add test for using timeoutCheckerExecutorServiceRef in Spring config
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.xml
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.java?rev=1196758&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.java Wed Nov 2 18:48:28 2011
@@ -0,0 +1,68 @@
+/**
+ * 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.spring.processor.aggregator;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.processor.aggregate.AggregateProcessor;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+/**
+ * @version
+ */
+public class SpringAggregateTimeoutWithExecutorServiceRefTest extends ContextTestSupport {
+
+ private static final int NUM_AGGREGATORS = 4;
+
+ public void testThreadNotUsedForEveryAggregatorWithCustomExecutorService() throws Exception {
+ assertTrue("There should not be a thread for every aggregator when using a shared thread pool",
+ aggregateThreadsCount() < NUM_AGGREGATORS);
+
+ // sanity check to make sure were testing routes that work
+ for (int i = 0; i < NUM_AGGREGATORS; ++i) {
+ MockEndpoint result = getMockEndpoint("mock:result" + i);
+ // by default the use latest aggregation strategy is used so we get message 4
+ result.expectedBodiesReceived("Message 4");
+ }
+ for (int i = 0; i < NUM_AGGREGATORS; ++i) {
+ for (int j = 0; j < 5; j++) {
+ template.sendBodyAndHeader("direct:start" + i, "Message " + j, "id", "1");
+ }
+ }
+ assertMockEndpointsSatisfied();
+ }
+
+ public static int aggregateThreadsCount() {
+ int count = 0;
+ ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
+ Thread[] threads = new Thread[threadGroup.activeCount()];
+ threadGroup.enumerate(threads);
+ for (Thread thread : threads) {
+ if (thread.getName().contains(AggregateProcessor.AGGREGATE_TIMEOUT_CHECKER)) {
+ ++count;
+ }
+ }
+ return count;
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.xml");
+ }
+
+}
\ No newline at end of file
Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.xml?rev=1196758&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregateTimeoutWithExecutorServiceRefTest.xml Wed Nov 2 18:48:28 2011
@@ -0,0 +1,71 @@
+<?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
+ ">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <!-- define a shared thread pool profile -->
+ <threadPoolProfile id="threadPool" poolSize="1" maxPoolSize="1" rejectedPolicy="Abort"/>
+
+ <route>
+ <from uri="direct:start0"/>
+ <!-- use the custom thread pool profile in this aggregate EIP, by referring to it -->
+ <aggregate strategyRef="aggregatorStrategy" completionTimeout="3000" timeoutCheckerExecutorServiceRef="threadPool">
+ <correlationExpression>
+ <simple>header.id</simple>
+ </correlationExpression>
+ <to uri="mock:result0"/>
+ </aggregate>
+ </route>
+ <route>
+ <from uri="direct:start1"/>
+ <aggregate strategyRef="aggregatorStrategy" completionTimeout="3000" timeoutCheckerExecutorServiceRef="threadPool">
+ <correlationExpression>
+ <simple>header.id</simple>
+ </correlationExpression>
+ <to uri="mock:result1"/>
+ </aggregate>
+ </route>
+ <route>
+ <from uri="direct:start2"/>
+ <aggregate strategyRef="aggregatorStrategy" completionTimeout="3000" timeoutCheckerExecutorServiceRef="threadPool">
+ <correlationExpression>
+ <simple>header.id</simple>
+ </correlationExpression>
+ <to uri="mock:result2"/>
+ </aggregate>
+ </route>
+ <route>
+ <from uri="direct:start3"/>
+ <aggregate strategyRef="aggregatorStrategy" completionTimeout="3000" timeoutCheckerExecutorServiceRef="threadPool">
+ <correlationExpression>
+ <simple>header.id</simple>
+ </correlationExpression>
+ <to uri="mock:result3"/>
+ </aggregate>
+ </route>
+ </camelContext>
+
+ <bean id="aggregatorStrategy" class="org.apache.camel.processor.aggregate.UseLatestAggregationStrategy"/>
+
+</beans>