Hi,
I start with the main question:
Is there a best practice how to integrate the Asynchronous Before functionality of a task as part of our unit tests?
We are using Camunda within a Spring Boot environment, running on a PostgreSQL database and use the Spring Boot environment also for our unit tests.
We want to make use of Asynchronous Before on a Service Task using a JavaDelegate instance, so we are able to throw an exception in the delegate without stopping the whole workflow and the engine performing a retry after some time.
We therefore set up a retry time cycle for failed jobs that execute the jobs again after some seconds/minutes.
So the setup will look something like this:
Start Event → Asynchronous Service Task → End Event
- Running the instance will work and we can execute the workflow from the modeler or the tasklist. If the task throws an exception, it will retry it again after some time, which is perfect for us.
- Running the same workflow in a unit test looks something like this:
runtimeService.startProcessInstance…
execute(jobs(processInstance))
assertThat(…)
The problem with case 2 is, that the execute() method is mandatory and it doesn’t seem to start the Service Task without it. If we run the command, the outcome of this is unpredictable:
- It ignores the exception and just continues the workflow (I was not able to check the retry counter, because the counter is either set to the default value of 3 or the job doesn’t exist)
- We receive a
org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of 'DELETE MessageEntity[98bc1cc6-82f3-11ea-89ff-127de0c35778]' failed. Entity was updated by another transaction concurrently.
- We receive a
org.camunda.bpm.engine.impl.pvm.PvmException: couldn't execute activity <serviceTask id="MyServiceTask" ...>: Our exception message from the delegate
The probability of the event seems to be depending on the time that elapses, before the execute()
method is invoked.
Thank you,
Andreas