Can't receive tasklist after asynchronous service task

Hello,

i’am trying to understand the behaviour of asynchronous tasks. I have already read the transaction section in the Camunda docs. This is my simple process with one asychronous service task: asynchron_test.bpmn (4.1 KB). I’am testing the process behaviour in a Unit-Test (Standard H2 Database). After the asynchronous service task started, i can not receive any process instance’s tasks. This is my testing code:

@Test
    @Deployment(resources = {"asynchron_test.bpmn"})
    public void testHappyPath() throws InterruptedException {
        final String asynchronProcessKey = "asynchronTestProcessKey";
        ProcessInstance piAsynch = processEngine().getRuntimeService().startProcessInstanceByKey(asynchronProcessKey);

        Map<String, Object> variables = processEngine().getRuntimeService().getVariables(piAsynch.getId());

// once i define the service task as asynchronous, the taskList is empty. 
// In synchronous mode it is working well and i receive the "Say hello" task.
// Despite the fact the service task is asynchronous I'am expecting one task in the list.             
List<Task> tasks = processEngine().getTaskService().createTaskQuery().processInstanceId(piAsynch.getId()).list();

This is my delegation code:

public class SomeLongTaskDelegate implements JavaDelegate{
    @Override
    public void execute(DelegateExecution execution) throws Exception {
        Thread.sleep(6000);
        execution.setVariable("var1","hello");
    }
}

Now i have the following questions:

  1. Why i’am not able to receive the task after the service is called asynchronously? Is this the behaviour you are expecting?
  2. I have understood, that you can influence the transaction’s behaviour with “asynchronous Before/After”. What is the meaning of the “exclusive” checkbox in the Camunda-Modeler? it appears, if you mark an service task as asynchronous.

I would be really grateful for your help.

Thanks a lot! :slight_smile:

Hi @Andy,

in test environment job executor is not enabled, so you have to take care of execution on your own, please refer to https://docs.camunda.org/manual/7.6/user-guide/process-engine/the-job-executor/#job-executor-in-a-unit-test

And here is some information to exclusive jobs: https://docs.camunda.org/manual/7.6/user-guide/process-engine/the-job-executor/#exclusive-jobs

Hope that helps,
Askar

Hi @Andy,

in a unit test you can either call managementService.executeJob(jobId),

or if you use the camunda-bpm-assert library (https://github.com/camunda/camunda-bpm-assert, user guide at https://github.com/camunda/camunda-bpm-assert/blob/master/camunda-bpm-assert/README.md) simply execute(job()).

Hope this helps,

Ingo

I have started the job manually and i see the task in the list. But if i call managementService.executeJob(jobId) i have to wait 6 seconds, although it is marked as “asynchronous Before”. Is that right?

Thank you for the quick reply and the information!