DataSet ComponentTesting of distributed and asynchronous processing is notoriously difficult. The Mock, Test and DataSet endpoints work great with the Camel Testing Framework to simplify your unit and integration testing using Enterprise Integration Patterns and Camel's large range of Components together with the powerful Bean Integration. The DataSet component (available since 1.3.0) provides a mechanism to easily perform load & soak testing of your system. It works by allowing you to create DataSet instances Camel will use the throughput logger when sending dataset's. URI formatdataset:name[?options] Where name is used to find the DataSet instance Camel ships with a support implementation of org.apache.camel.component.dataset.DataSet, the org.apache.camel.component.dataset.DataSetSupport class, that can be used as a base for implementing your own DataSet. Camel also ships with a default implementation, the org.apache.camel.component.dataset.SimpleDataSet that can be used for testing. Options
You can append query options to the URI in the following format, ?option=value&option=value&... Configuring DataSetCamel will lookup in the Registry for a bean implementing the DataSet interface. So you can register your own DataSet as: <bean id="myDataSet" class="com.mycompany.MyDataSet"> <property name="size" value="100"/> </bean> ExampleFor example, to test that a set of messages are sent to a queue and then consumed from the queue without losing any messages: // send the dataset to a queue from("dataset:foo").to("activemq:SomeQueue"); // now lets test that the messages are consumed correctly from("activemq:SomeQueue").to("dataset:foo"); The above would look in the Registry to find the foo DataSet instance which is used to create the messages. Then you create a DataSet implementation, such as using the SimpleDataSet as described below, configuring things like how big the data set is and what the messages look like etc. Properties on SimpleDataSet
Load testing ActiveMQ with CamelThere is an example of load testing an ActiveMQ queue using Camel in the ActiveMQ You can grab the code as follows: svn co https://svn.apache.org/repos/asf/activemq/trunk/activemq-camel-loadtest/
Then try running the test case: cd activemq-camel-loadtest mvn clean install To see how the test is defined, see the Spring XML file <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-2.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd "> <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <!-- sends messages every 10 milliseconds --> <from uri="dataset:myDataSet?produceDelay=10"/> <to uri="activemq:test.queue"/> </route> <route> <from uri="activemq:test.queue"/> <to uri="dataset:myDataSet?produceDelay=10"/> </route> </camelContext> <bean id="myDataSet" class="org.apache.camel.component.dataset.SimpleDataSet"> <property name="size" value="10000"/> <property name="reportCount" value="100"/> </bean> <!-- lets create an embedded broker for this test --> <broker xmlns="http://activemq.apache.org/schema/core" dataDirectory="target/activemq"> <transportConnectors> <transportConnector uri="tcp://localhost:61616"/> </transportConnectors> </broker> <!-- Lets connect the Camel ActiveMQ component to the embedded broker. See http://activemq.apache.org/camel/activemq.html for more information. --> <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="brokerURL" value="tcp://localhost:61616" /> </bean> </beans> See Also |