[jboss-user] [jBPM Users] - Re: workflow design about wait states

mmusaji do-not-reply at jboss.com
Mon Sep 14 07:49:17 EDT 2009


Okay so I took your advice and went back to basics. What I'm finding is if i have a node after the join (in my my case a custom node), the Unit test fails to find the execution in this. With a join going straight to an end it is ok.

My 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">
  |       <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>
  | 

I can't figure out how to test the custom four node. Without this things are working as expected but to me it seems like my unit test stops at the join and doesn't signal the workflow to carry on?


  | 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.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() throws Exception {
  |         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(2, jobs.size());
  |         
  |         Job job = jobs.get(0);
  | 
  |         managementService.executeJob(job.getId());
  |         
  |         job = jobs.get(1);
  | 
  |         managementService.executeJob(job.getId());
  |         
  |         Execution executionInFour = processInstance.findActiveExecutionIn("custom four");
  |         assertNotNull(executionInFour);
  |         processInstance = executionService.signalExecutionById(executionInFour.getId());
  |     }
  | 
  |     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 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 CustomThree 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 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);
  |         }
  |     }
  | 
  | }
  | 
  | 

Output:

  | 12:44:53,841 FIN | [BaseJbpmTestCase] === starting testProcess =============================
  | 12:44:53,981 FIN | [BaseJbpmTestCase] using ProcessEngine 78236
  | log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
  | log4j:WARN Please initialize the log4j system properly.
  | 12:44:55,122 FIN | [ProcessDefinitionImpl] creating new execution for process 'process'
  | 12:44:55,122 FIN | [DefaultIdGenerator] generated execution id process.149
  | Executing
  | custom one
  | 12:44:55,122 FIN | [ExecuteActivity] executing activity(12319324)
  | 12:44:55,122 FIN | [ExecuteActivity] executing activity(custom one)
  | 12:44:55,137 FIN | [Signal] signalling activity(custom one), signalName=null
  | 12:44:55,137 FIN | [ExecuteActivity] executing activity(fork)
  | 12:44:55,137 FIN | [DefaultIdGenerator] generated execution id process.149.custom two
  | 12:44:55,137 FIN | [ExecutionImpl] created execution[process.149.custom two]
  | 12:44:55,137 FIN | [JobExecutorMessageSession] sending message ExecuteActivityMessage
  | 12:44:55,153 INF   | [JobExecutorThread] starting...
  | 12:44:55,153 INF     | [JobExecutorThread] starting...
  | 12:44:55,153 INF       | [JobExecutorThread] starting...
  | 12:44:55,153 INF         | [DispatcherThread] starting...
  | 12:44:55,153 FIN | [DefaultIdGenerator] generated execution id process.149.custom three
  | 12:44:55,153 FIN | [ExecutionImpl] created execution[process.149.custom three]
  | 12:44:55,153 FIN | [JobExecutorMessageSession] sending message ExecuteActivityMessage
  | 12:44:55,153 FIN         | [AcquireJobsCmd] start querying first acquirable job...
  | 12:44:55,153 FIN         | [AcquireJobsCmd] locking jobs []
  | 12:44:55,153 FIN         | [GetNextDueDateCmd] getting next due date...
  | 12:44:55,153 FIN         | [GetNextDueDateCmd] next due date is null
  | 12:44:55,153 FIN         | [DispatcherThread] DispatcherThread will wait for max 600ms on org.jbpm.pvm.internal.jobexecutor.JobExecutor at 1d27069
  | 12:44:55,153 FIN         | [DispatcherThread] DispatcherThread woke up
  | 12:44:55,153 FIN         | [AcquireJobsCmd] start querying first acquirable job...
  | 12:44:55,169 FIN         | [AcquireJobsCmd] locking jobs [184]
  | 12:44:55,169 FIN | [ExecuteJobCmd] executing job ExecuteActivityMessage[184]...
  | 12:44:55,169 FIN         | [DispatcherThread] pushing jobs on the queue [184]
  | 12:44:55,169 FIN         | [DispatcherThread] added jobs [184] to the queue
  | 12:44:55,169 FIN         | [AcquireJobsCmd] start querying first acquirable job...
  | Executing
  | custom two
  | 12:44:55,169 FIN   | [JobExecutorThread] took job(s) [184] from queue
  | 12:44:55,169 FIN         | [AcquireJobsCmd] locking jobs [185]
  | 12:44:55,184 FIN | [ExecuteActivity] execution[process.149.custom two] executes activity(custom two)
  | 12:44:55,184 FIN         | [DispatcherThread] pushing jobs on the queue [185]
  | 12:44:55,184 FIN         | [DispatcherThread] added jobs [185] to the queue
  | 12:44:55,184 FIN         | [AcquireJobsCmd] start querying first acquirable job...
  | 12:44:55,184 FIN | [ExecuteJobCmd] executed job ExecuteActivityMessage[184]
  | 12:44:55,184 FIN         | [AcquireJobsCmd] locking jobs []
  | 12:44:55,184 FIN         | [GetNextDueDateCmd] getting next due date...
  | 12:44:55,184 FIN         | [GetNextDueDateCmd] next due date is null
  | 12:44:55,184 FIN         | [DispatcherThread] DispatcherThread will wait for max 600ms on org.jbpm.pvm.internal.jobexecutor.JobExecutor at 1d27069
  | 12:44:55,184 FIN       | [JobExecutorThread] took job(s) [185] from queue
  | 12:44:55,231 FIN       | [ExecuteJobCmd] executing job ExecuteActivityMessage[185]...
  | Executing
  | custom three
  | 12:44:55,231 FIN   | [ExecuteJobCmd] executing job ExecuteActivityMessage[184]...
  | 12:44:55,231 FIN       | [ExecuteActivity] execution[process.149.custom three] executes activity(custom three)
  | 12:44:55,231 FIN       | [ExecuteJobCmd] executed job ExecuteActivityMessage[185]
  | 12:44:55,247 FIN | [ExecuteJobCmd] executing job ExecuteActivityMessage[184]...
  | Executing
  | custom two
  | 12:44:55,247 FIN   | [ExecuteActivity] execution[process.149.custom two] executes activity(custom two)
  | 12:44:55,247 FIN   | [ExecuteJobCmd] executed job ExecuteActivityMessage[184]
  | 12:44:55,247 FIN | [ExecuteActivity] execution[process.149.custom two] executes activity(custom two)
  | Executing
  | custom two
  | 12:44:55,247 FIN | [ExecuteJobCmd] executed job ExecuteActivityMessage[184]
  | 12:44:55,450 FIN | [ExecuteJobCmd] job 184 no longer exists
  | 12:44:55,450 FIN | [ExecuteJobCmd] job 185 no longer exists
  | 12:44:55,450 SEV | [BaseJbpmTestCase] 
  | ### EXCEPTION ###########################################
  | 12:44:55,466 SEV | [BaseJbpmTestCase] ASSERTION FAILURE: null
  | junit.framework.AssertionFailedError
  | 	at junit.framework.Assert.fail(Assert.java:47)
  | 	at junit.framework.Assert.assertTrue(Assert.java:20)
  | 	at junit.framework.Assert.assertNotNull(Assert.java:220)
  | 	at junit.framework.Assert.assertNotNull(Assert.java:213)
  | 	at org.workflow.test.forum.ProcessTest.testProcess(ProcessTest.java:51)
  | 	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 junit.framework.TestCase.runTest(TestCase.java:154)
  | 	at org.jbpm.test.BaseJbpmTestCase.runTest(BaseJbpmTestCase.java:80)
  | 	at junit.framework.TestCase.runBare(TestCase.java:127)
  | 	at junit.framework.TestResult$1.protect(TestResult.java:106)
  | 	at junit.framework.TestResult.runProtected(TestResult.java:124)
  | 	at junit.framework.TestResult.run(TestResult.java:109)
  | 	at junit.framework.TestCase.run(TestCase.java:118)
  | 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
  | 	at junit.framework.TestSuite.run(TestSuite.java:203)
  | 	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
  | 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  | 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
  | 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
  | 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
  | 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
  | ### EXCEPTION ###########################################
  | 12:44:55,466 SEV | [BaseJbpmTestCase] 
  | 12:44:55,481 FIN | [DbSessionImpl] deleting history process instance process.149
  | 12:44:55,497 FIN | [DbSessionImpl] deleting process instance process.149
  | 12:44:55,497 FIN | [DeleteDeploymentCmd] deleting deployment 87
  | 12:44:55,528 FIN | [BaseJbpmTestCase] === ending testProcess =============================
  | 

Also are the classes being called twice? Is it once by the startProcessInstanceByKey and then again my the job in the unit tests?


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4255065#4255065

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4255065



More information about the jboss-user mailing list