Service task does not execute even when process engine "JobExecutorActivate" is true

Hey there
I’m trying to write unit test for a bpmn process and I have to set “jobExecutorActivate” true for some reason. the problem is when I’m trying to test an async service task(http-connector), process instance is waiting at service task but it does not execute(despite I have configuration.setJobExecutorActivate(true) in my configuration). and when I try to execute it like execute(job()) I get this error

org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of ‘INSERT VariableInstanceEntity[222]’ failed. Entity was updated by another transaction concurrently.

I would appreciate any help

2 Likes

Service tasks use pull method instead push method. You cannot force execute it. You just tell external worker here is a task. And wait for worker commit.

So you are saying I should not use execute(job()) right?
When I get to the service task I use assertThat(processInstance).isWaitingAt(serviceTaskId) to make sure it’s waiting there, and when I use assertThat(processInstance).hasPassed(serviceTaskId) the assertion fails cause it’s still waiting there, any idea why?

1 Like

Can you upload the model?
Testing connectors is generally quite hard. It’s not easy to mock.

purge_version.bpmn (11.5 KB)
This is the model. I’m using wiremock server to mock connectors and it’s ok when
configuration.setJobExecutorActivate(false) and use execute(job()) command, but when I set configuration like configuration.setJobExecutorActivate(true), I expect that the async service task execute without running execute(job()) command, but process instance is waiting at service task without execute it.
Sorry for English mistakes!

1 Like

Generally when unit testing your process you shouldn’t have the jobexecutor turned on at all. It’s better to have complete control over the test. So is there a specific reason you’d like to have it on?

1 Like

Yes. In some of my bpmn processes I have subprocesses and when I want to test an async multi instance subprocess I should execute it manually and I don’t know the size of collection to execute it per item

1 Like