private DatabasePurgeReport PurgeDatabase(CommandContext commandContext)
        {
            //var dbEntityManager = commandContext.DbEntityManager;
            // For MySQL and MariaDB we have to disable foreign key check,
            // to delete the table data as bulk operation (execution, incident etc.)
            // The flag will be reset by the DBEntityManager after flush.
            //dbEntityManager.IgnoreForeignKeysForNextFlush = true;
            //var tablesNames = dbEntityManager.TableNamesPresentInDatabase;
            var databaseTablePrefix = commandContext.ProcessEngineConfiguration.DatabaseTablePrefix.Trim();

            //for each table
            var databasePurgeReport = new DatabasePurgeReport();

            //foreach (var tableName in tablesNames)
            //{
            //    var tableNameWithoutPrefix = tableName.Replace(databaseTablePrefix, EmptyString);
            //    if (!TablenamesExcludedFromDbCleanCheck.Contains(tableNameWithoutPrefix))
            //    {
            //        // Check if table contains data
            //        IDictionary<string, string> param = new Dictionary<string, string>();
            //        param[TableName] = tableName;
            //        var count = (long?) dbEntityManager.SelectOne(SelectTableCount, param);

            //        if (count > 0)
            //            databasePurgeReport.AddPurgeInformation(tableName, count);
            //    }
            //}
            return(databasePurgeReport);
        }
Beispiel #2
0
        public virtual PurgeReport execute(CommandContext commandContext)
        {
            PurgeReport purgeReport = new PurgeReport();

            // purge the database
            DatabasePurgeReport databasePurgeReport = purgeDatabase(commandContext);

            purgeReport.DatabasePurgeReport = databasePurgeReport;

            // purge the deployment cache
            DeploymentCache  deploymentCache  = commandContext.ProcessEngineConfiguration.DeploymentCache;
            CachePurgeReport cachePurgeReport = deploymentCache.purgeCache();

            purgeReport.CachePurgeReport = cachePurgeReport;

            return(purgeReport);
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("resource") @Override public void postProcessApplicationUndeploy(org.camunda.bpm.application.ProcessApplicationInterface processApplication)
        public virtual void postProcessApplicationUndeploy(ProcessApplicationInterface processApplication)
        {
            // some tests deploy multiple PAs. => only clean DB after last PA is undeployed
            // if the deployment fails for example during parsing the deployment counter was not incremented
            // so we have to check if the counter is already zero otherwise we go into the negative values
            // best example is TestWarDeploymentWithBrokenBpmnXml in integration-test-engine test suite
            if (counter.get() == 0 || counter.decrementAndGet() == 0)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.ProcessEngine defaultProcessEngine = org.camunda.bpm.BpmPlatform.getDefaultProcessEngine();
                ProcessEngine defaultProcessEngine = BpmPlatform.DefaultProcessEngine;
                try
                {
                    logger.log(Level.INFO, "=== Ensure Clean Database ===");
                    ManagementServiceImpl managementService = (ManagementServiceImpl)defaultProcessEngine.ManagementService;
                    PurgeReport           report            = managementService.purge();

                    if (report.Empty)
                    {
                        logger.log(Level.INFO, "Clean DB and cache.");
                    }
                    else
                    {
                        StringBuilder builder = new StringBuilder();

                        DatabasePurgeReport databasePurgeReport = report.DatabasePurgeReport;
                        if (!databasePurgeReport.Empty)
                        {
                            builder.Append(DATABASE_NOT_CLEAN).Append(databasePurgeReport.PurgeReportAsString);
                        }

                        CachePurgeReport cachePurgeReport = report.CachePurgeReport;
                        if (!cachePurgeReport.Empty)
                        {
                            builder.Append(CACHE_IS_NOT_CLEAN).Append(cachePurgeReport.PurgeReportAsString);
                        }
                        logger.log(Level.INFO, builder.ToString());
                    }
                }
                catch (Exception e)
                {
                    logger.log(Level.SEVERE, "Could not clean DB:", e);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Ensures that the deployment cache and database is clean after a test. If not the cache
        /// and database will be cleared.
        /// </summary>
        /// <param name="processEngine"> the <seealso cref="ProcessEngine"/> to test </param>
        /// <param name="fail"> if true the method will throw an <seealso cref="AssertionError"/> if the deployment cache or database is not clean </param>
        /// <exception cref="AssertionError"> if the deployment cache or database was not clean </exception>
        public static string assertAndEnsureCleanDbAndCache(ProcessEngine processEngine, bool fail)
        {
            ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl)processEngine).ProcessEngineConfiguration;

            // 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.ManagementService).purge();

            string paRegistrationMessage = assertAndEnsureNoProcessApplicationsRegistered(processEngine);

            StringBuilder    message          = new StringBuilder();
            CachePurgeReport cachePurgeReport = purgeReport.CachePurgeReport;

            if (!cachePurgeReport.Empty)
            {
                message.Append("Deployment cache is not clean:\n").Append(cachePurgeReport.PurgeReportAsString);
            }
            else
            {
                LOG.debug("Deployment cache was clean.");
            }
            DatabasePurgeReport databasePurgeReport = purgeReport.DatabasePurgeReport;

            if (!databasePurgeReport.Empty)
            {
                message.Append("Database is not clean:\n").Append(databasePurgeReport.PurgeReportAsString);
            }
            else
            {
                LOG.debug("Database was clean.");
            }
            if (!string.ReferenceEquals(paRegistrationMessage, null))
            {
                message.Append(paRegistrationMessage);
            }

            if (fail && message.Length > 0)
            {
                Assert.fail(message.ToString());
            }
            return(message.ToString());
        }
Beispiel #5
0
        private DatabasePurgeReport purgeDatabase(CommandContext commandContext)
        {
            DbEntityManager dbEntityManager = commandContext.DbEntityManager;

            // For MySQL and MariaDB we have to disable foreign key check,
            // to delete the table data as bulk operation (execution, incident etc.)
            // The flag will be reset by the DBEntityManager after flush.
            dbEntityManager.IgnoreForeignKeysForNextFlush = true;
            IList <string> tablesNames         = dbEntityManager.TableNamesPresentInDatabase;
            string         databaseTablePrefix = commandContext.ProcessEngineConfiguration.DatabaseTablePrefix.Trim();

            // for each table
            DatabasePurgeReport databasePurgeReport = new DatabasePurgeReport();

            foreach (string tableName in tablesNames)
            {
                string tableNameWithoutPrefix = tableName.Replace(databaseTablePrefix, EMPTY_STRING);
                if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.Contains(tableNameWithoutPrefix))
                {
                    // Check if table contains data
                    IDictionary <string, string> param = new Dictionary <string, string>();
                    param[TABLE_NAME] = tableName;
                    long?count = (long?)dbEntityManager.selectOne(SELECT_TABLE_COUNT, param);

                    if (count > 0)
                    {
                        databasePurgeReport.addPurgeInformation(tableName, count);
                        // Get corresponding entity classes for the table, which contains data
                        IList <Type> entities = commandContext.TableDataManager.getEntities(tableName);

                        if (entities.Count == 0)
                        {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                            throw new ProcessEngineException("No mapped implementation of " + typeof(DbEntity).FullName + " was found for: " + tableName);
                        }

                        // Delete the table data as bulk operation with the first entity
                        Type            entity       = entities[0];
                        DbBulkOperation deleteBulkOp = new DbBulkOperation(DbOperationType.DELETE_BULK, entity, DELETE_TABLE_DATA, param);
                        dbEntityManager.DbOperationManager.addOperation(deleteBulkOp);
                    }
                }
            }
            return(databasePurgeReport);
        }
Beispiel #6
0
        // CMMN //////////////////////////////////////////////////////////////////////////////////////////////////////////////

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPurgeCmmnProcess()
        public virtual void testPurgeCmmnProcess()
        {
            // given cmmn process which is not managed by process engine rule

            engineRule.RepositoryService.createDeployment().addClasspathResource("org/camunda/bpm/engine/test/standalone/db/entitymanager/PurgeDatabaseTest.testPurgeCmmnProcess.cmmn").deploy();
            VariableMap variables = Variables.createVariables();

            variables.put("key", "value");
            engineRule.CaseService.createCaseInstanceByKey(PROCESS_DEF_KEY, variables);

            // when purge is executed
            ManagementServiceImpl managementService = (ManagementServiceImpl)engineRule.ManagementService;
            PurgeReport           purge             = managementService.purge();

            // then database and cache is cleaned
            assertAndEnsureCleanDbAndCache(engineRule.ProcessEngine, true);

            // and report contains deleted entities
            assertFalse(purge.Empty);
            CachePurgeReport cachePurgeReport = purge.CachePurgeReport;

            assertEquals(1, cachePurgeReport.getReportValue(CachePurgeReport.CASE_DEF_CACHE).Count);

            DatabasePurgeReport databasePurgeReport = purge.DatabasePurgeReport;

            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.HistoryLevel.Equals(org.camunda.bpm.engine.impl.history.HistoryLevel_Fields.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"));
            }
        }
Beispiel #7
0
        // DMN ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPurgeDmnProcess()
        public virtual void testPurgeDmnProcess()
        {
            // given dmn process which is not managed by process engine rule
            engineRule.RepositoryService.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.DecisionService.evaluateDecisionByKey("decisionId").variables(variables).evaluate();

            // when purge is executed
            ManagementServiceImpl managementService = (ManagementServiceImpl)engineRule.ManagementService;
            PurgeReport           purge             = managementService.purge();

            // then database and cache is cleaned
            assertAndEnsureCleanDbAndCache(engineRule.ProcessEngine, true);

            // and report contains deleted entities
            assertFalse(purge.Empty);
            CachePurgeReport cachePurgeReport = purge.CachePurgeReport;

            assertEquals(2, cachePurgeReport.getReportValue(CachePurgeReport.DMN_DEF_CACHE).Count);
            assertEquals(1, cachePurgeReport.getReportValue(CachePurgeReport.DMN_REQ_DEF_CACHE).Count);

            DatabasePurgeReport databasePurgeReport = purge.DatabasePurgeReport;

            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.HistoryLevel.Equals(org.camunda.bpm.engine.impl.history.HistoryLevel_Fields.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"));
            }
        }
Beispiel #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPurgeComplexProcess()
        public virtual 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.RepositoryService.createDeployment().addModelInstance(PROCESS_MODEL_NAME, modelInstance).deploy();

            executeComplexBpmnProcess(true);
            executeComplexBpmnProcess(false);

            processEngineConfiguration.DbMetricsReporter.reportNow();

            // when purge is executed
            ManagementServiceImpl managementService = (ManagementServiceImpl)engineRule.ManagementService;
            PurgeReport           purge             = managementService.purge();

            // then database and cache are empty
            assertAndEnsureCleanDbAndCache(engineRule.ProcessEngine, true);

            // and report contains deleted data
            assertFalse(purge.Empty);
            CachePurgeReport cachePurgeReport = purge.CachePurgeReport;

            assertEquals(1, cachePurgeReport.getReportValue(CachePurgeReport.PROCESS_DEF_CACHE).Count);

            DatabasePurgeReport databasePurgeReport = purge.DatabasePurgeReport;

            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.HistoryLevel.Equals(org.camunda.bpm.engine.impl.history.HistoryLevel_Fields.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(8, (long)databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_OP_LOG"));
            }
        }