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()));
}
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);
}
Aggregations