Search in sources :

Example 1 with CachePurgeReport

use of org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport in project camunda-bpm-platform by camunda.

the class EnsureCleanDbPlugin method postProcessApplicationUndeploy.

@SuppressWarnings("resource")
@Override
public void postProcessApplicationUndeploy(ProcessApplicationInterface processApplication) {
    // best example is TestWarDeploymentWithBrokenBpmnXml in integration-test-engine test suite
    if (counter.get() == 0 || counter.decrementAndGet() == 0) {
        final ProcessEngine defaultProcessEngine = BpmPlatform.getDefaultProcessEngine();
        try {
            logger.log(Level.INFO, "=== Ensure Clean Database ===");
            ManagementServiceImpl managementService = (ManagementServiceImpl) defaultProcessEngine.getManagementService();
            PurgeReport report = managementService.purge();
            if (report.isEmpty()) {
                logger.log(Level.INFO, "Clean DB and cache.");
            } else {
                StringBuilder builder = new StringBuilder();
                DatabasePurgeReport databasePurgeReport = report.getDatabasePurgeReport();
                if (!databasePurgeReport.isEmpty()) {
                    builder.append(DATABASE_NOT_CLEAN).append(databasePurgeReport.getPurgeReportAsString());
                }
                CachePurgeReport cachePurgeReport = report.getCachePurgeReport();
                if (!cachePurgeReport.isEmpty()) {
                    builder.append(CACHE_IS_NOT_CLEAN).append(cachePurgeReport.getPurgeReportAsString());
                }
                logger.log(Level.INFO, builder.toString());
            }
        } catch (Throwable e) {
            logger.log(Level.SEVERE, "Could not clean DB:", e);
        }
    }
}
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) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) PurgeReport(org.camunda.bpm.engine.impl.management.PurgeReport) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Example 2 with CachePurgeReport

use of org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport in project camunda-bpm-platform by camunda.

the class PurgeDatabaseTest method testPurgeCmmnProcess.

// CMMN //////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Test
public void testPurgeCmmnProcess() {
    // given cmmn process which is not managed by process engine rule
    engineRule.getRepositoryService().createDeployment().addClasspathResource("org/camunda/bpm/engine/test/standalone/db/entitymanager/PurgeDatabaseTest.testPurgeCmmnProcess.cmmn").deploy();
    VariableMap variables = Variables.createVariables();
    variables.put("key", "value");
    engineRule.getCaseService().createCaseInstanceByKey(PROCESS_DEF_KEY, variables);
    // when purge is executed
    ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService();
    PurgeReport purge = managementService.purge();
    // then database and cache is cleaned
    assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true);
    // and report contains deleted entities
    assertFalse(purge.isEmpty());
    CachePurgeReport cachePurgeReport = purge.getCachePurgeReport();
    assertEquals(1, cachePurgeReport.getReportValue(CachePurgeReport.CASE_DEF_CACHE).size());
    DatabasePurgeReport databasePurgeReport = purge.getDatabasePurgeReport();
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_DEPLOYMENT"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_TASK"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_GE_BYTEARRAY"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_CASE_DEF"));
    assertEquals(3, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_CASE_EXECUTION"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_VARIABLE"));
    assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_CASE_SENTRY_PART"));
    if (processEngineConfiguration.getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_FULL)) {
        assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_DETAIL"));
        assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_TASKINST"));
        assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_VARINST"));
        assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_CASEINST"));
        assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_CASEACTINST"));
    }
}
Also used : ManagementServiceImpl(org.camunda.bpm.engine.impl.ManagementServiceImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) 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 3 with CachePurgeReport

use of org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport in project camunda-bpm-platform by camunda.

the class PurgeDatabaseTest method testPurgeDmnProcess.

// DMN ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Test
public void testPurgeDmnProcess() {
    // given dmn process which is not managed by process engine rule
    engineRule.getRepositoryService().createDeployment().addClasspathResource("org/camunda/bpm/engine/test/standalone/db/entitymanager/PurgeDatabaseTest.testPurgeDmnProcess.dmn").deploy();
    VariableMap variables = Variables.createVariables().putValue("key", "value").putValue("season", "Test");
    engineRule.getDecisionService().evaluateDecisionByKey("decisionId").variables(variables).evaluate();
    // when purge is executed
    ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService();
    PurgeReport purge = managementService.purge();
    // then database and cache is cleaned
    assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true);
    // and report contains deleted entities
    assertFalse(purge.isEmpty());
    CachePurgeReport cachePurgeReport = purge.getCachePurgeReport();
    assertEquals(2, cachePurgeReport.getReportValue(CachePurgeReport.DMN_DEF_CACHE).size());
    assertEquals(1, cachePurgeReport.getReportValue(CachePurgeReport.DMN_REQ_DEF_CACHE).size());
    DatabasePurgeReport databasePurgeReport = purge.getDatabasePurgeReport();
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_DEPLOYMENT"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_GE_BYTEARRAY"));
    assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_DECISION_REQ_DEF"));
    assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_DECISION_DEF"));
    if (processEngineConfiguration.getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_FULL)) {
        assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_DECINST"));
        assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_DEC_IN"));
        assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_DEC_OUT"));
    }
}
Also used : ManagementServiceImpl(org.camunda.bpm.engine.impl.ManagementServiceImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) 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 4 with CachePurgeReport

use of org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport in project camunda-bpm-platform by camunda.

the class PurgeDatabaseAndCacheCmd method execute.

@Override
public PurgeReport execute(CommandContext commandContext) {
    PurgeReport purgeReport = new PurgeReport();
    // purge the database
    DatabasePurgeReport databasePurgeReport = purgeDatabase(commandContext);
    purgeReport.setDatabasePurgeReport(databasePurgeReport);
    // purge the deployment cache
    DeploymentCache deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentCache();
    CachePurgeReport cachePurgeReport = deploymentCache.purgeCache();
    purgeReport.setCachePurgeReport(cachePurgeReport);
    return purgeReport;
}
Also used : DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) PurgeReport(org.camunda.bpm.engine.impl.management.PurgeReport)

Example 5 with CachePurgeReport

use of org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport 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)

Aggregations

CachePurgeReport (org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport)7 DatabasePurgeReport (org.camunda.bpm.engine.impl.management.DatabasePurgeReport)6 PurgeReport (org.camunda.bpm.engine.impl.management.PurgeReport)6 ManagementServiceImpl (org.camunda.bpm.engine.impl.ManagementServiceImpl)5 Test (org.junit.Test)3 ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)2 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)2 VariableMap (org.camunda.bpm.engine.variable.VariableMap)2 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)1 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)1