[jboss-user] [jBPM Users] - Re: workflow design about wait states
mmusaji
do-not-reply at jboss.com
Tue Sep 15 11:11:20 EDT 2009
For completion purposes I'll post my unittest and processdefinition again:
My unit test with changes suggested.
| package org.workflow.test.forum;
|
| import java.util.List;
| import java.util.Map;
|
| import org.jbpm.api.Execution;
| import org.jbpm.api.ProcessInstance;
| import org.jbpm.api.activity.ActivityBehaviour;
| import org.jbpm.api.activity.ActivityExecution;
| import org.jbpm.api.activity.ExternalActivityBehaviour;
| import org.jbpm.api.job.Job;
| import org.jbpm.test.JbpmTestCase;
|
| public class ProcessTest extends JbpmTestCase {
| String deploymentDbid;
|
| protected void setUp() throws Exception {
| super.setUp();
| deploymentDbid = repositoryService.createDeployment()
| .addResourceFromClasspath("org/workflow/test/forum/process.jpdl.xml")
| .deploy();
| }
|
| protected void tearDown() throws Exception {
| repositoryService.deleteDeploymentCascade(deploymentDbid);
| super.tearDown();
| }
|
| public void testProcess() {
| ProcessInstance processInstance = executionService.startProcessInstanceByKey("process");
| Execution executionInOne = processInstance.findActiveExecutionIn("custom one");
| assertNotNull(executionInOne);
| processInstance = executionService.signalExecutionById(executionInOne.getId());
|
| String processInstanceId = processInstance.getId();
|
| List<Job> jobs = managementService.createJobQuery()
| .processInstanceId(processInstanceId)
| .list();
|
| assertEquals("Job size doesn't equal 2",2, jobs.size());
|
| Job job = jobs.get(0);
|
| managementService.executeJob(job.getId());
|
| job = jobs.get(1);
|
| managementService.executeJob(job.getId());
|
| processInstance = executionService.findProcessInstanceById(processInstanceId);
|
| Execution executionInFour = processInstance.findActiveExecutionIn("custom four");
| assertNotNull("ExecutionInFour Is Null",executionInFour);
| processInstance = executionService.signalExecutionById(executionInFour.getId());
|
|
| if(executionService.findProcessInstanceById(processInstanceId) != null) {
| assertFalse("ProcessInstance.isEnded() is not false",processInstance.isEnded());
| }else {
| assertNull("processInstanceID not null",executionService.findProcessInstanceById(processInstanceId));
| }
|
| }
|
| public static class CustomOne implements ExternalActivityBehaviour {
| private static final long serialVersionUID = 1L;
|
| public void execute(ActivityExecution execution) throws Exception {
| System.out.println("Executing");
|
| System.out.println(execution.getActivityName());
|
| execution.waitForSignal();
| }
|
| public void signal(ActivityExecution execution,
| String signalName,
| Map<String, ?> parameters) {
| execution.take(signalName);
| }
| }
|
| public static class CustomTwo implements ActivityBehaviour {
| private static final long serialVersionUID = 1L;
|
| public void execute(ActivityExecution execution) throws Exception {
| System.out.println("Executing");
|
| System.out.println(execution.getActivityName());
|
| execution.takeDefaultTransition();
| }
|
| public void signal(ActivityExecution execution,
| String signalName,
| Map<String, ?> parameters) {
| execution.take(signalName);
| }
| }
|
| public static class CustomThree implements ActivityBehaviour {
| private static final long serialVersionUID = 1L;
|
| public void execute(ActivityExecution execution) throws Exception {
| System.out.println("Executing");
|
| System.out.println(execution.getActivityName());
|
| execution.takeDefaultTransition();
| }
|
| public void signal(ActivityExecution execution,
| String signalName,
| Map<String, ?> parameters) {
| execution.take(signalName);
| }
| }
|
| public static class CustomFour implements ExternalActivityBehaviour {
| private static final long serialVersionUID = 1L;
|
| public void execute(ActivityExecution execution) throws Exception {
| System.out.println("Executing");
|
| System.out.println(execution.getActivityName());
|
| execution.waitForSignal();
| }
|
| public void signal(ActivityExecution execution,
| String signalName,
| Map<String, ?> parameters) {
| execution.take(signalName);
| }
| }
|
| }
|
|
Workflow
| <?xml version="1.0" encoding="UTF-8"?>
|
| <process name="process" xmlns="http://jbpm.org/4.0/jpdl">
| <start>
| <transition to="custom one"/>
| </start>
|
| <custom class="org.workflow.test.forum.ProcessTest$CustomOne" name="custom one">
| <transition to="fork"/>
| </custom>
|
| <fork name="fork">
| <transition name="custom two" to="custom two"/>
| <transition name="custom three" to="custom three"/>
| </fork>
|
| <custom continue="async" name="custom two" class="org.workflow.test.forum.ProcessTest$CustomTwo">
| <transition to="join"/>
| </custom>
|
| <custom continue="async" name="custom three" class="org.workflow.test.forum.ProcessTest$CustomThree">
| <transition to="join"/>
| </custom>
|
| <join name="join" continue="exclusive" >
| <transition name="custom four" to="custom four"/>
| </join>
|
| <custom name="custom four" class="org.workflow.test.forum.ProcessTest$CustomFour">
| <transition to="end"/>
| </custom>
|
| <task name="end">
| <transition name="to complete" to="end process"/>
| </task>
|
| <end name="end process" state="complete"/>
|
| </process>
|
Sometimes this runs to completion and sometimes it fails. Its very similiar to the issue I had when the unit test thread was completing ahead of the workflow. I suspect putting a small sleep in there will fix this but this is what I (we) are trying to fix. The join should ensure is only continues once all have joined from the fork.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4255324#4255324
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4255324
More information about the jboss-user
mailing list