Camunda Cleanup between tests?

We run Camunda (latest version) in a multi tenancy environment, we don’t use the Camunda Spring boot, but have created our own Spring boot as Camunda Spring boot does not support multi tenancy.

However, we noticed that we get the following error when using the @DirtiesContext annotation on camunda tests:

Caused by: org.camunda.bpm.engine.ProcessEngineException: Cannot register service org.camunda.bpm.platform.job-executor.process-application:type=CWF Camunda Process Application with MBeans Container, service with same name already registered.

Any idea how to solve that? It seems that on Spring context refresh, the Camunda application, which is a child class of SpringProcessApplication, is not correctly removed/undeployed, such that when the Spring Context is created, the Camunda application is still present in the MBeanServer, such that Camunda throws an exception.
How to solve this? How to ensure that the Camunda application is correctly removed during a Spring Context refresh during tests?
(The error only occurs when running all tests, when the failing test is run alone, is runs with success)

Hi @edbras ,

If you are using java based configuration you can add this:

@EnableMBeanExport(registration=RegistrationPolicy.REPLACE_EXISTING)

OR

@EnableMBeanExport(registration=RegistrationPolicy.IGNORE_EXISTING)

XML Config:

<context:mbean-export registration="ignoreExisting"/>

Or if you prefer the annotation way:

@Autowired
MBeanExporter mBeanExporter;

And then set the policy to ignore :

mBeanExporter.setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);

By default the policy is set to FAIL_ON_EXISTING . You can also set it to REPLACE_EXISTING or IGNORE_EXISTING .

Also, you can refer the below posts:

Thanks, that works like a charm :slight_smile: (I just added some code that did about the same, replaced it with this annotation)

@edbras you’re welcome.

See also https://docs.camunda.org/manual/7.11/user-guide/spring-boot-integration/testing/

Cheers,
Thorben

See also https://docs.camunda.org/manual/7.11/user-guide/spring-boot-integration/testing/
Cheers,
Thorben

Thanks for the link, however is it very useful as it doesn’t include the above annotation and we do create our own processengines (multi tenancy) with specified names.