You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by hbellat <hb...@gmail.com> on 2011/06/01 11:48:49 UTC

Re: Unit test camel with activeMQ

I followed some examples in camel-jms package but still have problem.

I wrote my camel.xml 

<beans
   xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
   http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

  	<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
        
        <packageScan>
           <package>org.foo.bar</package>
        </packageScan>
        
    <route>
          <from uri="activemq:start"/>
          <bean ref="MyBean" method="route" />
           <to uri="activemq:finish"/>
    </route>
    </camelContext>
    <bean id="mybean" class="com.testBeans.MyBean" />
    <bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent" >
        <property name="connectionFactory">
          <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL"
value="vm://localhost?create=false&amp;waitForStart=10000" />
            <property name="userName" value="${activemq.username}"/>
            <property name="password" value="${activemq.password}"/>
          </bean>
        </property>
    </bean>
</beans>



MyBean class still the same in the last post.

I create a class MyBeanTest.java :

public class MyBeanTest  extends CamelTestSupport{

	
	protected MockEndpoint resultEndpoint;
	protected String componentName = "activemq";
	 protected String startEndpointUri;

	    @Before
	    public void setUp() throws Exception {
	        startEndpointUri = componentName + ":start";

	        super.setUp();

	        resultEndpoint = (MockEndpoint) context.getEndpoint("mock:result");
	    }

	    protected AbstractXmlApplicationContext createApplicationContext() {
			// TODO Auto-generated method stub
			return new ClassPathXmlApplicationContext("ressource/camel.xml");
		}
   
	    
	    @Test
	    public void testRoute() throws Exception {
	        Object requestBody = template.requestBody(startEndpointUri,
"toto");
	        assertEquals("test", requestBody);        
	    }    


	}


I create the jar and put it in lib directory for activeMQ and I copy the
content of local file camel.xml to the camel.xml in ActiveMQ.

I started ActiveMQ and the unit Test MyBeanTest but I go into an exception:

org.apache.camel.CamelExecutionException: Exception occurred during
execution on the exchange: Exchange[Message: toto]
	at
org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1156)
	at
org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:456)
	at
org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:441)
	at
org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:119)
	at
org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:135)
	at
org.apache.camel.impl.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:283)
	at com.testBeans.MyBeanTest.testRoute(MyBeanTest.java:41)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at
org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.camel.ExchangeTimedOutException: The OUT message was
not received within: 20000 millis. Exchange[Message: toto]
	at
org.apache.camel.component.jms.reply.ReplyManagerSupport.processReply(ReplyManagerSupport.java:109)
	at
org.apache.camel.component.jms.reply.TemporaryQueueReplyHandler.onTimeout(TemporaryQueueReplyHandler.java:59)
	at
org.apache.camel.component.jms.reply.CorrelationMap.onEviction(CorrelationMap.java:34)
	at
org.apache.camel.component.jms.reply.CorrelationMap.onEviction(CorrelationMap.java:26)
	at
org.apache.camel.util.DefaultTimeoutMap.purge(DefaultTimeoutMap.java:202)
	at org.apache.camel.util.DefaultTimeoutMap.run(DefaultTimeoutMap.java:154)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)

 
Any idea please ?

Many thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Unit-test-camel-with-activeMQ-tp4438580p4444718.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Unit test camel with activeMQ

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

Your unit test is incorrectly defined.

You are using a request-reply model with a route that is defined to be
in-only.
          Object requestBody = template.requestBody(startEndpointUri,
"toto")

Sine your route is in-only and sends a message to another queue
activemq:finish, your unit test should read the message from activemQ:finish
to determine whether the message arrived on the queue.

Also you need to change the API to 
           template.sendBody(startEndpointUri, "toto");

This should get rid of the error and get your unit test working. 

Cheers,

Ashwin...

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com 
CamelOne 2011: http://fusesource.com/camel2011 
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/Unit-test-camel-with-activeMQ-tp4438580p4447730.html
Sent from the Camel - Users mailing list archive at Nabble.com.