For unit testing scenarios it is cumbersome to work with this background component. Therefore the Java API offers to query for ( ManagementService.createJobQuery ) and execute jobs ( ManagementService.executeJob ) by hand , which allows to control job execution from within a unit test.
But I’m not sure exactly how to configure that. I’ve tried the following code but it’s still running jobs in background.
public void preInit(ProcessEngineConfigurationImpl cfg) {
cfg.setJobExecutorActivate( false );
}
How can I disable any async execution and force jobs to be executed manually?
It seems like you are still starting the server. Are you testing from within jUnit4 as described here: Testing | docs.camunda.org ?
Then the job executor is already disabled. You don’t need to configure anything in the camunda.cfg.xml under src/test/resources
Indeed, today I’m not using this technique but my tests start like this:
RunWith(SpringRunner.class)
@SpringBootTest(classes = { HunterCommanderTestApp.class,
TestConfigurations.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MyTest {
....
}
That’s because, besides the whole engine, I’m still have some spring beans that must be available for the tests to succeed… Would them be loaded using the example you mentioned?
Besides the fact that I’m probably not using the best way to test, shouldn’t the configuration I mentioned disable job executions anyway?
In the first stage you want to keep the test environment as lean as possible and focus on testing the process. in the second stage you would bootstrap the Spring environment and include the actual services in the test, but have the job executor running (aspects related to it have already been tested in stage 1).
This article explains the different stages of testing and how to deal with spring beans, business services, job executor, etc.
if you absolutely must do so, the job executor can be disabled in your application.yaml / properties using the property: camunda.bpm.job-execution.enabled=false