提交 bcbf8a45 编写于 作者: T tijsrademakers

Async Camel test

上级 a8164b6a
/* Licensed 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.activiti.camel;
import java.util.List;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.test.Deployment;
import org.activiti.spring.impl.test.SpringActivitiTestCase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration("classpath:camel-activiti-context.xml")
public class AsyncProcessTest extends SpringActivitiTestCase {
@Autowired
RuntimeService runtimeService;
@Deployment(resources = {"process/async.bpmn20.xml"})
public void testRunProcess() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("asyncCamelProcess");
List<Execution> executionList = runtimeService.createExecutionQuery().list();
assertEquals(3, executionList.size());
Thread.sleep(4000);
assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());
}
}
package org.activiti.camel;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
public class InitDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
execution.setVariable(ActivitiProducer.PROCESS_ID_PROPERTY, execution.getProcessInstanceId());
}
}
package org.activiti.camel;
import org.apache.camel.Exchange;
public class SleepBean {
public void sleep(String body, Exchange exchange) throws Exception {
Thread.sleep(1500);
}
}
/* Licensed 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.activiti.camel.route;
import org.apache.camel.builder.RouteBuilder;
public class AsyncCamelRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("activiti:asyncCamelProcess:serviceTaskAsync1?copyVariablesToProperties=true").setHeader("destination", constant("activiti:asyncCamelProcess:receive1")).to("seda:asyncQueue");
from("seda:asyncQueue").to("bean:sleepBean?method=sleep").to("seda:receiveQueue");
from("activiti:asyncCamelProcess:serviceTaskAsync2?copyVariablesToProperties=true").setHeader("destination", constant("activiti:asyncCamelProcess:receive2")).to("seda:asyncQueue2");
from("seda:asyncQueue2").to("bean:sleepBean?method=sleep").to("seda:receiveQueue");
from("seda:receiveQueue").recipientList(header("destination"));
}
}
......@@ -50,8 +50,14 @@
<constructor-arg index="0" value="camelProcess"/>
<constructor-arg index="1" ref="camelProcess"/>
</bean>
<bean class="org.activiti.camel.SimpleContextProvider">
<constructor-arg index="0" value="asyncCamelProcess"/>
<constructor-arg index="1" ref="camelProcess"/>
</bean>
</list>
</constructor-arg>
</bean>
<bean id="sleepBean" class="org.activiti.camel.SleepBean"/>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="Examples" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.omg.org/spec/BPMN/20100524/MODEL http://www.omg.org/spec/BPMN/2.0/20100501/BPMN20.xsd">
<process id="asyncCamelProcess">
<startEvent id="start"/>
<sequenceFlow sourceRef="start" targetRef="serviceTaskInit"/>
<serviceTask id="serviceTaskInit" activiti:class="org.activiti.camel.InitDelegate"/>
<sequenceFlow sourceRef="serviceTaskInit" targetRef="parallelSplit"/>
<parallelGateway id="parallelSplit"/>
<sequenceFlow sourceRef="parallelSplit" targetRef="serviceTaskAsync1"/>
<sequenceFlow sourceRef="parallelSplit" targetRef="serviceTaskAsync2"/>
<serviceTask id="serviceTaskAsync1" activiti:delegateExpression="${camel}"/>
<sequenceFlow sourceRef="serviceTaskAsync1" targetRef="receive1"/>
<receiveTask id="receive1" name="Wait State" />
<sequenceFlow sourceRef="receive1" targetRef="parallelJoin"/>
<serviceTask id="serviceTaskAsync2" activiti:delegateExpression="${camel}"/>
<sequenceFlow sourceRef="serviceTaskAsync2" targetRef="receive2"/>
<receiveTask id="receive2" name="Wait State" />
<sequenceFlow sourceRef="receive2" targetRef="parallelJoin"/>
<parallelGateway id="parallelJoin"/>
<sequenceFlow sourceRef="parallelJoin" targetRef="end"/>
<endEvent id="end"/>
</process>
</definitions>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册