Search in sources :

Example 46 with Batch

use of org.camunda.bpm.engine.batch.Batch in project camunda-bpm-platform by camunda.

the class RuntimeServiceAsyncOperationsTest method cleanBatch.

@After
public void cleanBatch() {
    List<Batch> batches = managementService.createBatchQuery().list();
    if (batches.size() > 0) {
        for (Batch batch : batches) managementService.deleteBatch(batch.getId(), true);
    }
    HistoricBatch historicBatch = historyService.createHistoricBatchQuery().singleResult();
    if (historicBatch != null) {
        historyService.deleteHistoricBatch(historicBatch.getId());
    }
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) After(org.junit.After)

Example 47 with Batch

use of org.camunda.bpm.engine.batch.Batch in project camunda-bpm-platform by camunda.

the class RuntimeServiceAsyncOperationsTest method testDeleteProcessInstancesAsyncWithSkipCustomListeners.

@Test
public void testDeleteProcessInstancesAsyncWithSkipCustomListeners() {
    // given
    IncrementCounterListener.counter = 0;
    BpmnModelInstance instance = ProcessModels.newModel(ONE_TASK_PROCESS).startEvent().userTask().camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, IncrementCounterListener.class.getName()).endEvent().done();
    testRule.deploy(instance);
    List<String> processIds = startTestProcesses(1);
    // when
    Batch batch = runtimeService.deleteProcessInstancesAsync(processIds, null, TESTING_INSTANCE_DELETE, true);
    executeSeedJob(batch);
    executeBatchJobs(batch);
    // then
    assertThat(IncrementCounterListener.counter, is(0));
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) IncrementCounterListener(org.camunda.bpm.engine.test.api.runtime.util.IncrementCounterListener) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) AbstractAsyncOperationsTest(org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest) Test(org.junit.Test)

Example 48 with Batch

use of org.camunda.bpm.engine.batch.Batch in project camunda-bpm-platform by camunda.

the class RuntimeServiceAsyncOperationsTest method testDeleteProcessInstancesAsyncWithQuery.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
@Test
public void testDeleteProcessInstancesAsyncWithQuery() throws Exception {
    // given
    List<String> processIds = startTestProcesses(2);
    ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processInstanceIds(new HashSet<String>(processIds));
    // when
    Batch batch = runtimeService.deleteProcessInstancesAsync(null, processInstanceQuery, TESTING_INSTANCE_DELETE);
    executeSeedJob(batch);
    executeBatchJobs(batch);
    // then
    assertHistoricTaskDeletionPresent(processIds, TESTING_INSTANCE_DELETE, testRule);
    assertHistoricBatchExists(testRule);
    assertProcessInstancesAreDeleted();
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) AbstractAsyncOperationsTest(org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 49 with Batch

use of org.camunda.bpm.engine.batch.Batch in project camunda-bpm-platform by camunda.

the class RuntimeServiceAsyncOperationsTest method testDeleteProcessInstancesAsyncWithQueryOnly.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" })
@Test
public void testDeleteProcessInstancesAsyncWithQueryOnly() throws Exception {
    // given
    List<String> processIds = startTestProcesses(2);
    ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processInstanceIds(new HashSet<String>(processIds));
    // when
    Batch batch = runtimeService.deleteProcessInstancesAsync(processInstanceQuery, TESTING_INSTANCE_DELETE);
    executeSeedJob(batch);
    executeBatchJobs(batch);
    // then
    assertHistoricTaskDeletionPresent(processIds, TESTING_INSTANCE_DELETE, testRule);
    assertHistoricBatchExists(testRule);
    assertProcessInstancesAreDeleted();
}
Also used : ProcessInstanceQuery(org.camunda.bpm.engine.runtime.ProcessInstanceQuery) HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) AbstractAsyncOperationsTest(org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 50 with Batch

use of org.camunda.bpm.engine.batch.Batch in project camunda-bpm-platform by camunda.

the class RuntimeServiceAsyncOperationsTest method testDeleteProcessInstancesAsyncWithListInDifferentDeployments.

@Test
public void testDeleteProcessInstancesAsyncWithListInDifferentDeployments() {
    // given
    ProcessDefinition sourceDefinition1 = testRule.deployAndGetDefinition(modify(ProcessModels.ONE_TASK_PROCESS).changeElementId(ProcessModels.PROCESS_KEY, "ONE_TASK_PROCESS"));
    ProcessDefinition sourceDefinition2 = testRule.deployAndGetDefinition(modify(ProcessModels.TWO_TASKS_PROCESS).changeElementId(ProcessModels.PROCESS_KEY, "TWO_TASKS_PROCESS"));
    List<String> processInstanceIds = createProcessInstances(sourceDefinition1, sourceDefinition2, 15, 10);
    final String firstDeploymentId = sourceDefinition1.getDeploymentId();
    final String secondDeploymentId = sourceDefinition2.getDeploymentId();
    List<String> processInstanceIdsFromFirstDeployment = getProcessInstanceIdsByDeploymentId(firstDeploymentId);
    List<String> processInstanceIdsFromSecondDeployment = getProcessInstanceIdsByDeploymentId(secondDeploymentId);
    engineRule.getProcessEngineConfiguration().setInvocationsPerBatchJob(2);
    engineRule.getProcessEngineConfiguration().setBatchJobsPerSeed(3);
    // when
    Batch batch = runtimeService.deleteProcessInstancesAsync(processInstanceIds, null, "test_reason");
    String seedJobDefinitionId = batch.getSeedJobDefinitionId();
    // seed jobs
    int expectedSeedJobsCount = 5;
    createAndExecuteSeedJobs(seedJobDefinitionId, expectedSeedJobsCount);
    // then
    List<Job> jobs = managementService.createJobQuery().jobDefinitionId(batch.getBatchJobDefinitionId()).list();
    // execute jobs related to the first deployment
    List<String> jobIdsForFirstDeployment = getJobIdsByDeployment(jobs, firstDeploymentId);
    assertNotNull(jobIdsForFirstDeployment);
    for (String jobId : jobIdsForFirstDeployment) {
        managementService.executeJob(jobId);
    }
    // the process instances related to the first deployment should be deleted
    assertEquals(0, runtimeService.createProcessInstanceQuery().deploymentId(firstDeploymentId).count());
    assertHistoricTaskDeletionPresent(processInstanceIdsFromFirstDeployment, "test_reason", testRule);
    // and process instances related to the second deployment should not be deleted
    assertEquals(processInstanceIdsFromSecondDeployment.size(), runtimeService.createProcessInstanceQuery().deploymentId(secondDeploymentId).count());
    assertHistoricTaskDeletionPresent(processInstanceIdsFromSecondDeployment, null, testRule);
    // execute jobs related to the second deployment
    List<String> jobIdsForSecondDeployment = getJobIdsByDeployment(jobs, secondDeploymentId);
    assertNotNull(jobIdsForSecondDeployment);
    for (String jobId : jobIdsForSecondDeployment) {
        managementService.executeJob(jobId);
    }
    // all of the process instances should be deleted
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
}
Also used : HistoricBatch(org.camunda.bpm.engine.batch.history.HistoricBatch) Batch(org.camunda.bpm.engine.batch.Batch) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Job(org.camunda.bpm.engine.runtime.Job) AbstractAsyncOperationsTest(org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest) Test(org.junit.Test)

Aggregations

Batch (org.camunda.bpm.engine.batch.Batch)324 Test (org.junit.Test)286 HistoricBatch (org.camunda.bpm.engine.batch.history.HistoricBatch)125 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)95 Job (org.camunda.bpm.engine.runtime.Job)78 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)64 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)32 Date (java.util.Date)28 JobDefinition (org.camunda.bpm.engine.management.JobDefinition)28 AbstractAsyncOperationsTest (org.camunda.bpm.engine.test.api.AbstractAsyncOperationsTest)26 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)24 ArrayList (java.util.ArrayList)23 ProcessInstanceQuery (org.camunda.bpm.engine.runtime.ProcessInstanceQuery)19 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)18 HistoricDecisionInstanceQuery (org.camunda.bpm.engine.history.HistoricDecisionInstanceQuery)17 ExternalTask (org.camunda.bpm.engine.externaltask.ExternalTask)16 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)15 Deployment (org.camunda.bpm.engine.test.Deployment)15 ExpectedException (org.junit.rules.ExpectedException)14 Matchers.anyString (org.mockito.Matchers.anyString)14