cancel
Showing results for 
Search instead for 
Did you mean: 

parallel service tasks stuck on join gateway

tonyado
Champ in-the-making
Champ in-the-making
FYI. I am trying async service tasks with parallel gateway, below is my xml:
<blockcode>
<?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="ActivitiDemo">

    <process id="test_Parallel" name="The simple group deploy process">

        <startEvent id="test_Parallel_start"/>

        <sequenceFlow sourceRef='test_Parallel_start'
                      targetRef='fork_gateway'/>

        <parallelGateway id="fork_gateway" name="Fork"/>

        <serviceTask id="parallel_task1" name="Task1" activiti:class="com.westudio.activiti.OffTrafficService"
                     activiti:async="true" activiti:exclusive="false"/>
        <sequenceFlow sourceRef="fork_gateway" targetRef="parallel_task1"/>

        <serviceTask id="parallel_task2" name="Task2"
                     activiti:class="com.alipay.westudio.DownloadBundleService" activiti:async="true"
                     activiti:exclusive="false"/>
        <sequenceFlow sourceRef="fork_gateway" targetRef="parallel_task2"/>

        <parallelGateway id="join_gateway" name="Join"/>
        <sequenceFlow sourceRef="parallel_task1" targetRef="join_gateway"/>
        <sequenceFlow sourceRef="parallel_task2" targetRef="join_gateway"/>

        <endEvent id="test_Parallel_end"/>
        <sequenceFlow sourceRef="join_gateway" targetRef="test_Parallel_end"/>

    </process>

</definitions>
</blockcode>

I am test this with spring, below is my spring configuration:
<blockcode>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:tx="http://www.springframework.org/schema/tx"
       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.xsd
                           http://www.springframework.org/schema/tx      http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean id="dataSource"
          class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/activiti?autoReconnect=true"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
    </bean>

    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="dataSource" ref="dataSource"/>
        <property name="transactionManager" ref="transactionManager"/>
        <property name="databaseSchemaUpdate" value="true"/>
        <property name="jobExecutorActivate" value="true"/>
        <property name="processDefinitionCacheLimit" value="10"/>
        <property name="jobExecutor" ref="springJobExecutor">
        </property>
    </bean>

    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration"/>
    </bean>

    <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
    <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService"/>

    <bean id="springJobExecutor" class="org.activiti.spring.SpringJobExecutor">
        <property name="taskExecutor">
            <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
        </property>
    </bean>

</beans>
</blockcode>

I am using spring job executor, and set jobExecutorActivate to true. Below is my test case:
<blockcode>
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/activiti-context.xml" })
public class ParallelServiceTasksWithXML extends SpringActivitiTestCase {

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private RuntimeService    runtimeService;

    @Autowired
    private HistoryService    historyService;

    @Test
    public void testParallelWithXML() throws Exception {
        Thread workThread = new Thread(new Runnable() {
            public void run() {
                final String deploymentId = repositoryService.createDeployment().addClasspathResource("ParallelServiceTask.bpmn20.xml")
                    .deploy().getId();
                System.out.println("deployment id: " + deploymentId);
                ProcessInstance pi = runtimeService.startProcessInstanceByKey("test_Parallel");
                System.out.println("pid: " + pi.getId());
                System.out.println("end: " + pi.isEnded());
            }
        });
        workThread.start();

        while (true) {
            ProcessInstance runningPi = runtimeService.createProcessInstanceQuery().processDefinitionId("test_Parallel").singleResult();
            if (runningPi != null && runningPi.isEnded()) {
                break;
            }
            Thread.sleep(3 * 1000);
            System.out.println("still running");
        }
    }
}
</blockcode>
And the delegate java class is quite simple:
<blockcode>
public class OffTrafficService implements JavaDelegate {
    public void execute(DelegateExecution execution) throws Exception {
        System.out.println("start off traffic service task: " + Calendar.getInstance().get(Calendar.SECOND));
        Thread.sleep(10 * 1000);
        System.out.println("off traffic get executed");
    }
}
</blockcode>

From the test output, I can see both service tasks get executed in parallel, but the process instance can not get to the end point, this has really block me several hours, hope someone can help me Smiley Happy Thanks a lot.
4 REPLIES 4

tonyado
Champ in-the-making
Champ in-the-making
Also I want to know what is the correct way to unit test activiti with spring, I am using activiti 5.15.1 and use mysql as datasource.

tonyado
Champ in-the-making
Champ in-the-making
can someone help me with this? Would really appreciate your help Smiley Happy

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Tony,

Would it be possible to reproduce the issue on H2 DB and "standard" activiti jUnit test?
https://forums.activiti.org/content/sticky-how-write-unit-test

Thank,

Regards
Martin

tonyado
Champ in-the-making
Champ in-the-making
I have not test with h2 db, will try this.