Search in sources :

Example 1 with Cache

use of org.camunda.commons.utils.cache.Cache in project camunda-bpm-platform by camunda.

the class DeleteProcessDefinitionTest method testDeleteProcessDefinitionAndRefillDeploymentCache.

@Test
public void testDeleteProcessDefinitionAndRefillDeploymentCache() {
    // given a deployment with two process definitions in one xml model file
    deployment = repositoryService.createDeployment().addClasspathResource("org/camunda/bpm/engine/test/repository/twoProcesses.bpmn20.xml").deploy();
    ProcessDefinition processDefinitionOne = repositoryService.createProcessDefinitionQuery().processDefinitionKey("one").singleResult();
    ProcessDefinition processDefinitionTwo = repositoryService.createProcessDefinitionQuery().processDefinitionKey("two").singleResult();
    String idOne = processDefinitionOne.getId();
    // one is deleted from the deployment
    repositoryService.deleteProcessDefinition(idOne);
    // when clearing the deployment cache
    processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache();
    // then creating process instance from the existing process definition
    ProcessInstanceWithVariables procInst = runtimeService.createProcessInstanceByKey("two").executeWithVariablesInReturn();
    assertNotNull(procInst);
    assertTrue(procInst.getProcessDefinitionId().contains("two"));
    // should refill the cache
    Cache cache = processEngineConfiguration.getDeploymentCache().getProcessDefinitionCache();
    assertNotNull(cache.get(processDefinitionTwo.getId()));
    // The deleted process definition should not be recreated after the cache is refilled
    assertNull(cache.get(processDefinitionOne.getId()));
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) Cache(org.camunda.commons.utils.cache.Cache) Test(org.junit.Test)

Example 2 with Cache

use of org.camunda.commons.utils.cache.Cache in project camunda-bpm-platform by camunda.

the class DeploymentRegistrationTest method testNoRegistrationCheckIfNoProcessApplicationIsDeployed.

public void testNoRegistrationCheckIfNoProcessApplicationIsDeployed() {
    // create two deployments; both contain a process with the same key
    Deployment deployment1 = repositoryService.createDeployment().name(DEPLOYMENT_NAME).addModelInstance(BPMN_RESOURCE, createProcessWithServiceTask(PROCESS_KEY)).deploy();
    Deployment deployment2 = repositoryService.createDeployment().name(DEPLOYMENT_NAME).addDeploymentResources(deployment1.getId()).deploy();
    // assume an empty deployment cache (e.g. on a different engine)
    processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache();
    // then starting a process instance for the latest version
    // 
    // The context switch mechanism for process definitions in redeployments
    // is to look up the process application registration from a previous version
    // of the same process. This can trigger fetching these process definitions
    // from the database.
    // 
    // In case where there are no process application registrations anyway (e.g. embedded engine),
    // this logic should not be executed.
    runtimeService.startProcessInstanceByKey(PROCESS_KEY);
    ProcessDefinition version1 = repositoryService.createProcessDefinitionQuery().deploymentId(deployment1.getId()).singleResult();
    ProcessDefinition version2 = repositoryService.createProcessDefinitionQuery().deploymentId(deployment2.getId()).singleResult();
    // accordingly the process definition cache should only contain the latest version now
    Cache cache = processEngineConfiguration.getDeploymentCache().getProcessDefinitionCache();
    assertNotNull(cache.get(version2.getId()));
    assertNull(cache.get(version1.getId()));
    deleteDeployments(deployment1, deployment2);
}
Also used : Deployment(org.camunda.bpm.engine.repository.Deployment) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Cache(org.camunda.commons.utils.cache.Cache)

Aggregations

ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)2 Cache (org.camunda.commons.utils.cache.Cache)2 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)1 Deployment (org.camunda.bpm.engine.repository.Deployment)1 ProcessInstanceWithVariables (org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables)1 Test (org.junit.Test)1