AnsweredAssumed Answered

Database Exceptions in Unittest

Question asked by billdoor on Aug 7, 2014
Latest reply on Aug 8, 2014 by billdoor

I am currently evaluating Activiti for a new project and keep running into seemingly random, database related exceptions like
ProcessInstance was updated by another transaction concurrently,
Deadlock detected,
Variable was concurrently updated in another Procesinstance

in Unittests.

My Process is quite simple:

<process id="randomCalculator" name="Random Calculator" isExecutable="true">
      <startEvent id="theStart" name="Start"></startEvent>

      <serviceTask id="generateRandomTask" name="generate Random Task"
         activiti:async="true" activiti:class=""></serviceTask>

      <userTask id="defineRules" name="Rule definition"
            <activiti:formProperty id="min" required="true"
               type="long" />
            <activiti:formProperty id="max" type="long"
               required="true" />

      <parallelGateway id="valuesAndBoundariesPresent" name="Parallel Gateway"></parallelGateway>

      <serviceTask id="CalculateTask" name="Calculate Task"
         activiti:async="true" activiti:class="">

      <endEvent id="theEnd"></endEvent>

      <!– FLOW –>
      <sequenceFlow id="startGeneratingValues" sourceRef="theStart"
      <sequenceFlow id="startGettingUserInput" sourceRef="theStart"
      <sequenceFlow id="UserInputRecieved" sourceRef="defineRules"
      <sequenceFlow id="RandomValuesRecieved" sourceRef="generateRandomTask"
      <sequenceFlow id="startCalculation" sourceRef="valuesAndBoundariesPresent"
      <sequenceFlow id="finish" sourceRef="CalculateTask"

the ServiceTask generates two random numbers
the user then has to submit 2 values in a form

then the flow is buffered with a paralell gateway to ensure both randoms and userinput are present as procesvariables.

the calculatetask then checks if both random values are in between the user provides values (min, max) and if they are, it adds the two randoms and prints the result into a file.

my activiti.cfg.xml is used and reads this:

<bean id="processEngineConfiguration"
      <property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
      <property name="jdbcDriver" value="org.h2.Driver" />
      <property name="jdbcUsername" value="sa" />
      <property name="jdbcPassword" value="" />
      <property name="databaseSchemaUpdate" value="drop-create" /> <!– also tried true and false –>
      <property name="jobExecutorActivate" value="true" />

my unittest is basically the provided template:

public class ProcessTest_randomCalculator {

   public ActivitiRule activitiRule = new ActivitiRule();

   @Deployment (resources={"bpmn/randomCalculator.bpmn20.xml"})
   public void startProcess() throws Exception {
      RuntimeService runtimeService = activitiRule.getRuntimeService();
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("randomCalculator");
      assertTrue(!processInstance.isEnded() && !processInstance.isSuspended());

      List<Task> taskList = activitiRule.getTaskService().createTaskQuery().taskAssignee("kermit").list();

      Map<String, String> params = new HashMap<String, String>();
      params.put("min", "-100");
      params.put("max", "100");
      activitiRule.getFormService().submitTaskFormData(taskList.get(0).getId(), params);

For what i gather, the problem is that the test crashed in some executions and kept processinstances in the database that clutter up some ids, and lead to random problems, even sometimes working fine. Sometimes the engine stops logging at
shutting down Job Executor
processing resource randomCalculator.bpmn20.xml
and does nothing, neither execute the process, nor log exceptions, errors or warnings.

Is there a way to tell the engine to completely drop the database when using the ActivitiRule class in tests? Or is there any other configuration i messed up and cannot see?

Thanks in advance for help!