@Test
public void testJmsAuditCacheInstance() throws Exception {

    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.jms", "kjar-jms-audit", "1.0.0");
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
    customDescriptor.getBuilder()
                    .auditMode(AuditMode.JMS);
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
    installKjar(releaseId, kJar1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get()
                                                                      .newDefaultBuilder(releaseId)
                                                                      .classLoader(this.getClass().getClassLoader())
                                                                      .get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    assertNotNull(engine);
    AsyncAuditLogProducer asyncAuditLogProducer = null;
    KieSession kieSession = engine.getKieSession();
    for (ProcessEventListener listener : kieSession.getProcessEventListeners()) {
        if (listener instanceof AsyncAuditLogProducer) {
            asyncAuditLogProducer = (AsyncAuditLogProducer) listener;
            break;
        }
    }
    assertNotNull(asyncAuditLogProducer);
    manager.close();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession kieSession2 = engine2.getKieSession();
    AsyncAuditLogProducer asyncAuditLogProducer2 = null;
    for (ProcessEventListener listener : kieSession2.getProcessEventListeners()) {
        if (listener instanceof AsyncAuditLogProducer) {
            asyncAuditLogProducer2 = (AsyncAuditLogProducer) listener;
            break;
        }
    }
    assertNotNull(asyncAuditLogProducer2);
    // check if the instance is the same (cached)
    assertEquals(asyncAuditLogProducer, asyncAuditLogProducer2);
}