Search in sources :

Example 6 with ManagementServiceImpl

use of org.camunda.bpm.engine.impl.ManagementServiceImpl in project camunda-bpm-platform by camunda.

the class PurgeDatabaseTest method testPurgeWithAsyncProcessInstance.

@Test
public void testPurgeWithAsyncProcessInstance() {
    // given process with variable and async process instance
    BpmnModelInstance test = Bpmn.createExecutableProcess(PROCESS_DEF_KEY).startEvent().camundaAsyncBefore().userTask().userTask().endEvent().done();
    engineRule.getRepositoryService().createDeployment().addModelInstance(PROCESS_MODEL_NAME, test).deploy();
    VariableMap variables = Variables.createVariables();
    variables.put("key", "value");
    engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEF_KEY, variables);
    Job job = engineRule.getManagementService().createJobQuery().singleResult();
    engineRule.getManagementService().executeJob(job.getId());
    Task task = engineRule.getTaskService().createTaskQuery().singleResult();
    engineRule.getTaskService().complete(task.getId());
    // when purge is executed
    ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService();
    managementService.purge();
    // then no more data exist
    assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true);
}
Also used : ManagementServiceImpl(org.camunda.bpm.engine.impl.ManagementServiceImpl) Task(org.camunda.bpm.engine.task.Task) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) VariableMap(org.camunda.bpm.engine.variable.VariableMap) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Job(org.camunda.bpm.engine.runtime.Job) Test(org.junit.Test)

Example 7 with ManagementServiceImpl

use of org.camunda.bpm.engine.impl.ManagementServiceImpl in project camunda-bpm-platform by camunda.

the class TestHelper method assertAndEnsureCleanDbAndCache.

/**
 * Ensures that the deployment cache and database is clean after a test. If not the cache
 * and database will be cleared.
 *
 * @param processEngine the {@link ProcessEngine} to test
 * @param fail if true the method will throw an {@link AssertionError} if the deployment cache or database is not clean
 * @throws AssertionError if the deployment cache or database was not clean
 */
public static String assertAndEnsureCleanDbAndCache(ProcessEngine processEngine, boolean fail) {
    ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
    // clear user operation log in case some operations are
    // executed with an authenticated user
    clearUserOperationLog(processEngineConfiguration);
    LOG.debug("verifying that db is clean after test");
    PurgeReport purgeReport = ((ManagementServiceImpl) processEngine.getManagementService()).purge();
    String paRegistrationMessage = assertAndEnsureNoProcessApplicationsRegistered(processEngine);
    StringBuilder message = new StringBuilder();
    CachePurgeReport cachePurgeReport = purgeReport.getCachePurgeReport();
    if (!cachePurgeReport.isEmpty()) {
        message.append("Deployment cache is not clean:\n").append(cachePurgeReport.getPurgeReportAsString());
    } else {
        LOG.debug("Deployment cache was clean.");
    }
    DatabasePurgeReport databasePurgeReport = purgeReport.getDatabasePurgeReport();
    if (!databasePurgeReport.isEmpty()) {
        message.append("Database is not clean:\n").append(databasePurgeReport.getPurgeReportAsString());
    } else {
        LOG.debug("Database was clean.");
    }
    if (paRegistrationMessage != null) {
        message.append(paRegistrationMessage);
    }
    if (fail && message.length() > 0) {
        Assert.fail(message.toString());
    }
    return message.toString();
}
Also used : ManagementServiceImpl(org.camunda.bpm.engine.impl.ManagementServiceImpl) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessEngineImpl(org.camunda.bpm.engine.impl.ProcessEngineImpl) PurgeReport(org.camunda.bpm.engine.impl.management.PurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport)

Example 8 with ManagementServiceImpl

use of org.camunda.bpm.engine.impl.ManagementServiceImpl in project camunda-bpm-platform by camunda.

the class PurgeDatabaseTest method testPurgeComplexProcess.

@Test
public void testPurgeComplexProcess() {
    // given complex process with authentication
    // process is executed two times
    // metrics are reported
    BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(PROCESS_DEF_KEY).startEvent().camundaAsyncBefore().parallelGateway("parallel").serviceTask("external").camundaType("external").camundaTopic("external").boundaryEvent().message("message").moveToNode("parallel").serviceTask().camundaAsyncBefore().camundaExpression("${1/0}").moveToLastGateway().userTask().done();
    createAuthenticationData();
    engineRule.getRepositoryService().createDeployment().addModelInstance(PROCESS_MODEL_NAME, modelInstance).deploy();
    executeComplexBpmnProcess(true);
    executeComplexBpmnProcess(false);
    processEngineConfiguration.getDbMetricsReporter().reportNow();
    // when purge is executed
    ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService();
    PurgeReport purge = managementService.purge();
    // then database and cache are empty
    assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true);
    // and report contains deleted data
    assertFalse(purge.isEmpty());
    CachePurgeReport cachePurgeReport = purge.getCachePurgeReport();
    assertEquals(1, cachePurgeReport.getReportValue(CachePurgeReport.PROCESS_DEF_CACHE).size());
    DatabasePurgeReport databasePurgeReport = purge.getDatabasePurgeReport();
    assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_ID_TENANT_MEMBER"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_EVENT_SUBSCR"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_DEPLOYMENT"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_EXT_TASK"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_ID_MEMBERSHIP"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_TASK"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_JOB"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_GE_BYTEARRAY"));
    assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_JOBDEF"));
    assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_ID_USER"));
    assertEquals(5, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_EXECUTION"));
    assertEquals(10, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_METER_LOG"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_VARIABLE"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_PROCDEF"));
    assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_ID_TENANT"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_ID_GROUP"));
    assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_AUTHORIZATION"));
    if (processEngineConfiguration.getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_FULL)) {
        assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_INCIDENT"));
        assertEquals(9, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_ACTINST"));
        assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_PROCINST"));
        assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_DETAIL"));
        assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_TASKINST"));
        assertEquals(7, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_JOB_LOG"));
        assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_VARINST"));
        assertEquals(3, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_OP_LOG"));
    }
}
Also used : ManagementServiceImpl(org.camunda.bpm.engine.impl.ManagementServiceImpl) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) PurgeReport(org.camunda.bpm.engine.impl.management.PurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) Test(org.junit.Test)

Example 9 with ManagementServiceImpl

use of org.camunda.bpm.engine.impl.ManagementServiceImpl in project camunda-bpm-platform by camunda.

the class PurgeDatabaseTest method testPurgeWithExistingProcessInstance.

@Test
public void testPurgeWithExistingProcessInstance() {
    // given process with variable and staying process instance in second user task
    BpmnModelInstance test = Bpmn.createExecutableProcess(PROCESS_DEF_KEY).startEvent().userTask().userTask().endEvent().done();
    engineRule.getRepositoryService().createDeployment().addModelInstance(PROCESS_MODEL_NAME, test).deploy();
    VariableMap variables = Variables.createVariables();
    variables.put("key", "value");
    engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEF_KEY, variables);
    Task task = engineRule.getTaskService().createTaskQuery().singleResult();
    engineRule.getTaskService().complete(task.getId());
    // when purge is executed
    ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService();
    managementService.purge();
    // then no more data exist
    assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true);
}
Also used : ManagementServiceImpl(org.camunda.bpm.engine.impl.ManagementServiceImpl) Task(org.camunda.bpm.engine.task.Task) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) VariableMap(org.camunda.bpm.engine.variable.VariableMap) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) Test(org.junit.Test)

Aggregations

ManagementServiceImpl (org.camunda.bpm.engine.impl.ManagementServiceImpl)9 Test (org.junit.Test)7 DatabasePurgeReport (org.camunda.bpm.engine.impl.management.DatabasePurgeReport)5 PurgeReport (org.camunda.bpm.engine.impl.management.PurgeReport)5 CachePurgeReport (org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport)5 VariableMap (org.camunda.bpm.engine.variable.VariableMap)5 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)4 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)2 Task (org.camunda.bpm.engine.task.Task)2 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1 ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)1 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)1 Job (org.camunda.bpm.engine.runtime.Job)1 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)1