AnsweredAssumed Answered

Database Exceptions in Unittest

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

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="com.company.processes.ServiceTaskImpl"></serviceTask>

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

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

      <serviceTask id="CalculateTask" name="Calculate Task"
         activiti:async="true" activiti:class="com.company.processes.CalculateTaskImpl">
      </serviceTask>

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

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


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"
      class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
      <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" />
   </bean>


my unittest is basically the provided template:

public class ProcessTest_randomCalculator {

   @Rule
   public ActivitiRule activitiRule = new ActivitiRule();
   

   @Test
   @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());
      assertNotNull(processInstance.getId());

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

      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!

Outcomes