📄 concurrencytest.java
字号:
package org.jbpm.service;
import java.util.*;
import junit.framework.*;
import org.jbpm.*;
import org.jbpm.model.definition.*;
import org.jbpm.model.execution.*;
import org.jbpm.model.execution.impl.*;
import org.jbpm.model.log.*;
public class ConcurrencyTest extends TestCase {
public static TestHelper helper = new TestHelper();
private ExecutionService executionService = helper.getExecutionService();
static {
helper.deployProcess( "process/concurrencyprocess.xml" );
}
public void testSimpleConcurrentScenario() throws Exception {
// retrieve the definition
Definition definition = executionService.getLatestDefinition( "the concurrency process" );
// start a process instance
InvocationLog invocationLog = executionService.startProcessInstance( "testrunner", definition.getId() );
ProcessInstanceImpl pi = (ProcessInstanceImpl) invocationLog.getProcessInstance();
// check if the root-flow is not in a state (its positioned on the fork)
assertNull( pi.getRoot().getState() );
Map childTokens = pi.getRoot().getChildren();
assertNotNull( childTokens );
assertEquals( 3, childTokens.size() );
// the names of the tokens should be the default names...
Collection expectedTokenNames = new HashSet( Arrays.asList( new String[]{ "first", "second", "third" } ) );
assertEquals( expectedTokenNames, new HashSet( childTokens.keySet() ) );
// all the child-tokens should be assigned to the testrunner (=initiator)
Collection expectedStateNames = new HashSet( Arrays.asList( new String[]{ "one", "two", "three" } ) );
Iterator iter = childTokens.values().iterator();
while (iter.hasNext()) {
Token child = (Token) iter.next();
assertNotNull( child.getState().getName() );
assertTrue( expectedStateNames.remove( child.getState().getName() ) );
assertEquals( "testrunner", child.getActorId() );
assertNotNull( child.getStart() );
assertNull( child.getEnd() );
}
assertEquals( "expected state names should be empty", 0, expectedStateNames.size() );
// end all the (concurrent-token-) states
iter = childTokens.values().iterator();
while (iter.hasNext()) {
Token child = (Token) iter.next();
executionService.endOfState( "testrunner", child.getId() );
}
Assembler assembler = new PropertyAssembler( "root.children[ITERATE][RECURSIVE]" );
pi = (ProcessInstanceImpl) executionService.getProcessInstance( pi.getId(), assembler );
// check if the child tokens were ended as expected
iter = pi.getRoot().getChildren().values().iterator();
while (iter.hasNext()) {
Token child = (Token) iter.next();
assertNull( child.getActorId() );
assertNotNull( child.getStart() );
assertNotNull( child.getEnd() );
}
// check if the process instance ended
assertNotNull( pi.getEnd() );
assertNotNull( pi.getRoot().getEnd() );
assertNull( pi.getRoot().getState() );
assertNull( pi.getRoot().getActorId() );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -