I am new to Camunda, trying to write unit test where i am trying to access the variable in the delegate which is configured AsyncBefore:true, I was able to access all the variables from DelegateExecution prior to this AsyncBefore service task but not after this async before. could you please let me know if there any options to retreive those values
I am using spring-boot and here is my sample code to get all the variable
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
“TestProcess”);
Map<String, Object> vars = runtimeService.getVariables(processInstance.getId());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("TestProcess");
String content = null;
while (!processInstance.isEnded()) {
Thread.sleep(500);
Map<String, Object> vars = runtimeService.getVariables(processInstance.getId());
content = (String) vars.get("CONTENT");
if (isNotBlank(content)) {
break;
}
}
When i access any variable after the serviceTask which is configured asyncBefore:true, I get null values…however i can access any delegates variables from different service task before this async flow.
@Niall@aravindhrs - could you please let me know what is missing in my test to read variables from asynchronous continuations (asyncBefore) service task? really appreciate your help
If this is a unit test, it is likely the job executor thread is not running. So the process job waits at the async before call, and does not execute the task until you “manually” progress it by something like -
Job job = engine.getManagementService().createJobQuery().singleResult();
assertNotNull(job);
engine.getManagementService().executeJob(job.getId());
After this call, the current thread will pick up the token and execute the task, stopping again at the next wait state. At that point, the variables should be stored again, and accessible.
I am trying to access the variable which is set in Confirm Transaction service task which is executed in background as there are asyncBefore = true tasks marked in the previous steps ( Loyalty , CC payment )
I am setting the variable in ConfirmTransactionWorker like this
ctx.setVariable( "SUCCESS", true );
System.out.println( "Ctx var SUCCESS set to " + (boolean) ctx.getVariable( "SUCCESS" ) );
And it is being set also , but the scope of this variable is not visible when i access in application thread where this processinstance is initiated
In the while loop above only the variable which is set during instantiation of process and one which was set in Start Transaction are visible but not the variable set in Confirm Transaction