protected void discardDefinitionCache() { processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); processEngineConfiguration.getDeploymentCache().discardCaseDefinitionCache(); processEngineConfiguration.getDeploymentCache().discardDecisionDefinitionCache(); processEngineConfiguration.getDeploymentCache().discardDecisionRequirementsDefinitionCache(); }
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/scripttask/ExternalScriptTaskTest.testScriptInDeployment.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/scripttask/greeting.py" }) public void testScriptInDeploymentAfterCacheWasCleaned() { processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process"); String greeting = (String) runtimeService.getVariable(processInstance.getId(), "greeting"); assertNotNull(greeting); assertEquals("Greetings camunda BPM speaking", greeting); }
public void testDeployAndRemoveAsyncActivity() { Set<String> deployments = new HashSet<String>(); try { // given a deployment that contains a process called "process" with an async task "task" org.camunda.bpm.engine.repository.Deployment deployment1 = repositoryService .createDeployment() .addClasspathResource("org/camunda/bpm/engine/test/bpmn/async/AsyncTaskTest.testDeployAndRemoveAsyncActivity.v1.bpmn20.xml") .deploy(); deployments.add(deployment1.getId()); // when redeploying the process where that task is not contained anymore org.camunda.bpm.engine.repository.Deployment deployment2 = repositoryService .createDeployment() .addClasspathResource("org/camunda/bpm/engine/test/bpmn/async/AsyncTaskTest.testDeployAndRemoveAsyncActivity.v2.bpmn20.xml") .deploy(); deployments.add(deployment2.getId()); // and clearing the deployment cache (note that the equivalent of this in a real-world // scenario would be making the deployment with a different engine processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); // then it should be possible to load the latest process definition ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process"); assertNotNull(processInstance); } finally { for (String deploymentId : deployments) { repositoryService.deleteDeployment(deploymentId, true); } } }
@Deployment public void testTimerShouldNotBeRecreatedOnDeploymentCacheReboot() { // Just to be sure, I added this test. Sounds like something that could // easily happen // when the order of deploy/parsing is altered. // After process start, there should be timer created JobQuery jobQuery = managementService.createJobQuery(); assertEquals(1, jobQuery.count()); // Reset deployment cache processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); // Start one instance of the process definition, this will trigger a cache // reload runtimeService.startProcessInstanceByKey("startTimer"); // No new jobs should have been created assertEquals(1, jobQuery.count()); }
@Test public void testGetProcessDiagramAfterCacheWasCleaned() { if (1 == processDefinitionQuery.count()) { activitiRule.getProcessEngineConfiguration().getDeploymentCache().discardProcessDefinitionCache(); // given ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); // when InputStream stream = repositoryService.getProcessDiagram(processDefinition.getId()); // then assertNotNull(processDefinition.getDiagramResourceName()); assertNotNull(stream); } else { // some test diagrams do not contain executable processes // and are therefore ignored by the engine } }
@Test public void testMigrationPlanCreationWithEmptyDeploymentCache() { // given ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); rule.getProcessEngineConfiguration().getDeploymentCache().discardProcessDefinitionCache(); // when MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()) .mapEqualActivities() .build(); // then assertNotNull(migrationPlan); }
@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())); }
@Test public void testJobDefinitionsAfterRedeploment() { // initially there are no job definitions: assertEquals(0, managementService.createJobDefinitionQuery().count()); // initial deployment String deploymentId = repositoryService.createDeployment() .addClasspathResource(processDefinitionResource) .deploy() .getId(); ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertNotNull(processDefinition); // this parses the process and created the Job definitions: List<JobDefinition> jobDefinitions = managementService.createJobDefinitionQuery().list(); Set<String> jobDefinitionIds = getJobDefinitionIds(jobDefinitions); // now clear the cache: processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); // if we start an instance of the process, the process will be parsed again: runtimeService.startProcessInstanceByKey(processDefinition.getKey()); // no new definitions were created assertEquals(jobDefinitions.size(), managementService.createJobDefinitionQuery().count()); // the job has the correct definitionId set: List<Job> jobs = managementService.createJobQuery().list(); for (Job job : jobs) { assertTrue(jobDefinitionIds.contains(job.getJobDefinitionId())); } // delete the deployment repositoryService.deleteDeployment(deploymentId, true); }
processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache();
protected void discardDefinitionCache() { processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); processEngineConfiguration.getDeploymentCache().discardCaseDefinitionCache(); processEngineConfiguration.getDeploymentCache().discardDecisionDefinitionCache(); processEngineConfiguration.getDeploymentCache().discardDecisionRequirementsDefinitionCache(); }
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/scripttask/ExternalScriptTaskTest.testScriptInDeployment.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/scripttask/greeting.py" }) public void testScriptInDeploymentAfterCacheWasCleaned() { processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process"); String greeting = (String) runtimeService.getVariable(processInstance.getId(), "greeting"); assertNotNull(greeting); assertEquals("Greetings camunda BPM speaking", greeting); }
public void testDeployAndRemoveAsyncActivity() { Set<String> deployments = new HashSet<String>(); try { // given a deployment that contains a process called "process" with an async task "task" org.camunda.bpm.engine.repository.Deployment deployment1 = repositoryService .createDeployment() .addClasspathResource("org/camunda/bpm/engine/test/bpmn/async/AsyncTaskTest.testDeployAndRemoveAsyncActivity.v1.bpmn20.xml") .deploy(); deployments.add(deployment1.getId()); // when redeploying the process where that task is not contained anymore org.camunda.bpm.engine.repository.Deployment deployment2 = repositoryService .createDeployment() .addClasspathResource("org/camunda/bpm/engine/test/bpmn/async/AsyncTaskTest.testDeployAndRemoveAsyncActivity.v2.bpmn20.xml") .deploy(); deployments.add(deployment2.getId()); // and clearing the deployment cache (note that the equivalent of this in a real-world // scenario would be making the deployment with a different engine processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); // then it should be possible to load the latest process definition ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process"); assertNotNull(processInstance); } finally { for (String deploymentId : deployments) { repositoryService.deleteDeployment(deploymentId, true); } } }
@Deployment public void testTimerShouldNotBeRecreatedOnDeploymentCacheReboot() { // Just to be sure, I added this test. Sounds like something that could // easily happen // when the order of deploy/parsing is altered. // After process start, there should be timer created JobQuery jobQuery = managementService.createJobQuery(); assertEquals(1, jobQuery.count()); // Reset deployment cache processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); // Start one instance of the process definition, this will trigger a cache // reload runtimeService.startProcessInstanceByKey("startTimer"); // No new jobs should have been created assertEquals(1, jobQuery.count()); }
@Test public void testGetProcessDiagramAfterCacheWasCleaned() { if (1 == processDefinitionQuery.count()) { activitiRule.getProcessEngineConfiguration().getDeploymentCache().discardProcessDefinitionCache(); // given ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); // when InputStream stream = repositoryService.getProcessDiagram(processDefinition.getId()); // then assertNotNull(processDefinition.getDiagramResourceName()); assertNotNull(stream); } else { // some test diagrams do not contain executable processes // and are therefore ignored by the engine } }
@Test public void testMigrationPlanCreationWithEmptyDeploymentCache() { // given ProcessDefinition sourceDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); ProcessDefinition targetDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS); rule.getProcessEngineConfiguration().getDeploymentCache().discardProcessDefinitionCache(); // when MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceDefinition.getId(), targetDefinition.getId()) .mapEqualActivities() .build(); // then assertNotNull(migrationPlan); }
@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())); }
@Test public void testJobDefinitionsAfterRedeploment() { // initially there are no job definitions: assertEquals(0, managementService.createJobDefinitionQuery().count()); // initial deployment String deploymentId = repositoryService.createDeployment() .addClasspathResource(processDefinitionResource) .deploy() .getId(); ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertNotNull(processDefinition); // this parses the process and created the Job definitions: List<JobDefinition> jobDefinitions = managementService.createJobDefinitionQuery().list(); Set<String> jobDefinitionIds = getJobDefinitionIds(jobDefinitions); // now clear the cache: processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); // if we start an instance of the process, the process will be parsed again: runtimeService.startProcessInstanceByKey(processDefinition.getKey()); // no new definitions were created assertEquals(jobDefinitions.size(), managementService.createJobDefinitionQuery().count()); // the job has the correct definitionId set: List<Job> jobs = managementService.createJobQuery().list(); for (Job job : jobs) { assertTrue(jobDefinitionIds.contains(job.getJobDefinitionId())); } // delete the deployment repositoryService.deleteDeployment(deploymentId, true); }
processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache();