From dbc8247f4e7f3465946b5164d8c2b2b8997de664 Mon Sep 17 00:00:00 2001 From: Tijs Rademakers Date: Tue, 2 Apr 2024 13:59:51 +0200 Subject: [PATCH] Fix deployment issue with getting a definition from the cache --- .../app/engine/impl/deployer/AppDeployer.java | 1 + .../impl/deployer/AppDeploymentManager.java | 2 +- .../entity/AppDeploymentEntity.java | 5 + .../entity/AppDeploymentEntityImpl.java | 12 +++ .../engine/impl/deployer/CmmnDeployer.java | 1 + .../impl/deployer/CmmnDeploymentManager.java | 2 +- .../entity/CmmnDeploymentEntity.java | 5 + .../entity/CmmnDeploymentEntityImpl.java | 12 +++ .../test/cache/CaseDefinitionCacheTest.java | 97 +++++++++++++++++++ .../src/test/resources/flowable.cache.cfg.xml | 46 +++++++++ .../org/flowable/cmmn/test/cache/case1.cmmn | 17 ++++ .../org/flowable/cmmn/test/cache/case2.cmmn | 17 ++++ .../org/flowable/cmmn/test/cache/case3.cmmn | 17 ++++ .../org/flowable/cmmn/test/cache/case4.cmmn | 17 ++++ .../org/flowable/cmmn/test/cache/case5.cmmn | 17 ++++ .../org/flowable/cmmn/test/cache/case6.cmmn | 17 ++++ .../org/flowable/cmmn/test/cache/case7.cmmn | 17 ++++ .../org/flowable/cmmn/test/cache/case8.cmmn | 17 ++++ .../org/flowable/cmmn/test/cache/case9.cmmn | 17 ++++ .../deployer/CachingAndArtifactsManager.java | 1 + .../persistence/deploy/DeploymentManager.java | 2 +- .../persistence/entity/DeploymentEntity.java | 5 + .../entity/DeploymentEntityImpl.java | 12 +++ .../cache/ProcessDefinitionCacheTest.java | 70 +++++++++++++ .../standalone/cache/flowable.cfg.xml | 46 +++++++++ .../flowable/standalone/cache/process1.bpmn | 53 ++++++++++ .../flowable/standalone/cache/process2.bpmn | 53 ++++++++++ .../flowable/standalone/cache/process3.bpmn | 53 ++++++++++ .../flowable/standalone/cache/process4.bpmn | 53 ++++++++++ .../flowable/standalone/cache/process5.bpmn | 53 ++++++++++ .../flowable/standalone/cache/process6.bpmn | 53 ++++++++++ .../flowable/standalone/cache/process7.bpmn | 53 ++++++++++ .../flowable/standalone/cache/process8.bpmn | 53 ++++++++++ .../flowable/standalone/cache/process9.bpmn | 53 ++++++++++ 34 files changed, 946 insertions(+), 3 deletions(-) create mode 100644 modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/cache/CaseDefinitionCacheTest.java create mode 100644 modules/flowable-cmmn-engine/src/test/resources/flowable.cache.cfg.xml create mode 100644 modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case1.cmmn create mode 100644 modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case2.cmmn create mode 100644 modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case3.cmmn create mode 100644 modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case4.cmmn create mode 100644 modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case5.cmmn create mode 100644 modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case6.cmmn create mode 100644 modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case7.cmmn create mode 100644 modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case8.cmmn create mode 100644 modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case9.cmmn create mode 100644 modules/flowable-engine/src/test/java/org/flowable/standalone/cache/ProcessDefinitionCacheTest.java create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/flowable.cfg.xml create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process1.bpmn create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process2.bpmn create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process3.bpmn create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process4.bpmn create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process5.bpmn create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process6.bpmn create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process7.bpmn create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process8.bpmn create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process9.bpmn diff --git a/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/deployer/AppDeployer.java b/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/deployer/AppDeployer.java index 60215af66cb..3c15f671c31 100644 --- a/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/deployer/AppDeployer.java +++ b/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/deployer/AppDeployer.java @@ -120,5 +120,6 @@ protected void updateCachingAndArtifacts(AppDefinitionEntity appDefinition, AppM appDefinitionCache.add(appDefinition.getId(), cacheEntry); deployment.addDeployedArtifact(appDefinition); + deployment.addAppDefinitionCacheEntry(appDefinition.getId(), cacheEntry); } } diff --git a/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/deployer/AppDeploymentManager.java b/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/deployer/AppDeploymentManager.java index 14eea0f71a8..40a32ff6594 100644 --- a/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/deployer/AppDeploymentManager.java +++ b/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/deployer/AppDeploymentManager.java @@ -106,7 +106,7 @@ public AppDefinitionCacheEntry resolveAppDefinition(AppDefinition appDefinition) AppDeploymentEntity deployment = deploymentEntityManager.findById(deploymentId); deployment.setNew(false); deploy(deployment, null); - cachedAppDefinition = appDefinitionCache.get(appDefinitionId); + cachedAppDefinition = deployment.getAppDefinitionCacheEntry(appDefinitionId); if (cachedAppDefinition == null) { throw new FlowableException("deployment '" + deploymentId + "' didn't put app definition '" + appDefinitionId + "' in the cache"); diff --git a/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/persistence/entity/AppDeploymentEntity.java b/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/persistence/entity/AppDeploymentEntity.java index b56ff055579..58e35395a56 100644 --- a/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/persistence/entity/AppDeploymentEntity.java +++ b/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/persistence/entity/AppDeploymentEntity.java @@ -18,6 +18,7 @@ import java.util.Map; import org.flowable.app.api.repository.AppDeployment; +import org.flowable.app.engine.impl.persistence.entity.deploy.AppDefinitionCacheEntry; import org.flowable.common.engine.api.repository.EngineResource; import org.flowable.common.engine.impl.persistence.entity.Entity; @@ -32,6 +33,10 @@ public interface AppDeploymentEntity extends AppDeployment, Entity { void addDeployedArtifact(Object deployedArtifact); List getDeployedArtifacts(Class clazz); + + void addAppDefinitionCacheEntry(String appDefinitionId, AppDefinitionCacheEntry appDefinitionCacheEntry); + + AppDefinitionCacheEntry getAppDefinitionCacheEntry(String appDefinitionId); void setName(String name); diff --git a/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/persistence/entity/AppDeploymentEntityImpl.java b/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/persistence/entity/AppDeploymentEntityImpl.java index d3bc0c2288a..feb270fa75a 100644 --- a/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/persistence/entity/AppDeploymentEntityImpl.java +++ b/modules/flowable-app-engine/src/main/java/org/flowable/app/engine/impl/persistence/entity/AppDeploymentEntityImpl.java @@ -22,6 +22,7 @@ import java.util.Map; import org.flowable.app.engine.AppEngineConfiguration; +import org.flowable.app.engine.impl.persistence.entity.deploy.AppDefinitionCacheEntry; import org.flowable.app.engine.impl.util.CommandContextUtil; import org.flowable.common.engine.api.repository.EngineResource; @@ -45,6 +46,7 @@ public class AppDeploymentEntityImpl extends AbstractAppEngineNoRevisionEntity i * Will only be used during actual deployment to pass deployed artifacts (eg process definitions). Will be null otherwise. */ protected Map, List> deployedArtifacts; + protected Map appDefinitionCache = new HashMap<>(); public AppDeploymentEntityImpl() { @@ -106,6 +108,16 @@ public List getDeployedArtifacts(Class clazz) { } return null; } + + @Override + public void addAppDefinitionCacheEntry(String appDefinitionId, AppDefinitionCacheEntry appDefinitionCacheEntry) { + appDefinitionCache.put(appDefinitionId, appDefinitionCacheEntry); + } + + @Override + public AppDefinitionCacheEntry getAppDefinitionCacheEntry(String appDefinitionId) { + return appDefinitionCache.get(appDefinitionId); + } // getters and setters //////////////////////////////////////////////////////// diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeployer.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeployer.java index 2b2068bd2f0..8acaae42066 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeployer.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeployer.java @@ -333,6 +333,7 @@ protected void updateCachingAndArtifacts(CmmnParseResult parseResult) { caseDefinitionCache.add(caseDefinitionEntity.getId(), cacheEntry); deployment.addDeployedArtifact(caseDefinitionEntity); + deployment.addCaseDefinitionCacheEntry(caseDefinitionEntity.getId(), cacheEntry); } } diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeploymentManager.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeploymentManager.java index 5098eff19d4..65b80f75826 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeploymentManager.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/deployer/CmmnDeploymentManager.java @@ -106,7 +106,7 @@ public CaseDefinitionCacheEntry resolveCaseDefinition(CaseDefinition caseDefinit CmmnDeploymentEntity deployment = deploymentEntityManager.findById(deploymentId); deployment.setNew(false); deploy(deployment, null); - cachedCaseDefinition = caseDefinitionCache.get(caseDefinitionId); + cachedCaseDefinition = deployment.getCaseDefinitionCacheEntry(caseDefinitionId); if (cachedCaseDefinition == null) { throw new FlowableException("deployment '" + deploymentId + "' didn't put case definition '" + caseDefinitionId + "' in the cache"); diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/persistence/entity/CmmnDeploymentEntity.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/persistence/entity/CmmnDeploymentEntity.java index 07c0d9e2412..cf7d50267a9 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/persistence/entity/CmmnDeploymentEntity.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/persistence/entity/CmmnDeploymentEntity.java @@ -18,6 +18,7 @@ import java.util.Map; import org.flowable.cmmn.api.repository.CmmnDeployment; +import org.flowable.cmmn.engine.impl.persistence.entity.deploy.CaseDefinitionCacheEntry; import org.flowable.common.engine.api.repository.EngineResource; import org.flowable.common.engine.impl.persistence.entity.Entity; @@ -32,6 +33,10 @@ public interface CmmnDeploymentEntity extends CmmnDeployment, Entity { void addDeployedArtifact(Object deployedArtifact); List getDeployedArtifacts(Class clazz); + + void addCaseDefinitionCacheEntry(String caseDefinitionId, CaseDefinitionCacheEntry caseDefinitionCacheEntry); + + CaseDefinitionCacheEntry getCaseDefinitionCacheEntry(String caseDefinitionId); void setName(String name); diff --git a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/persistence/entity/CmmnDeploymentEntityImpl.java b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/persistence/entity/CmmnDeploymentEntityImpl.java index f94b04eab54..d8db0df0b6e 100644 --- a/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/persistence/entity/CmmnDeploymentEntityImpl.java +++ b/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/persistence/entity/CmmnDeploymentEntityImpl.java @@ -21,6 +21,7 @@ import java.util.Map; import org.flowable.cmmn.engine.CmmnEngineConfiguration; +import org.flowable.cmmn.engine.impl.persistence.entity.deploy.CaseDefinitionCacheEntry; import org.flowable.cmmn.engine.impl.util.CommandContextUtil; import org.flowable.common.engine.api.repository.EngineResource; @@ -45,6 +46,7 @@ public class CmmnDeploymentEntityImpl extends AbstractCmmnEngineNoRevisionEntity * Will only be used during actual deployment to pass deployed artifacts (eg process definitions). Will be null otherwise. */ protected Map, List> deployedArtifacts; + protected Map caseDefinitionCache = new HashMap<>(); public CmmnDeploymentEntityImpl() { @@ -107,6 +109,16 @@ public List getDeployedArtifacts(Class clazz) { } return null; } + + @Override + public void addCaseDefinitionCacheEntry(String caseDefinitionId, CaseDefinitionCacheEntry caseDefinitionCacheEntry) { + caseDefinitionCache.put(caseDefinitionId, caseDefinitionCacheEntry); + } + + @Override + public CaseDefinitionCacheEntry getCaseDefinitionCacheEntry(String caseDefinitionId) { + return caseDefinitionCache.get(caseDefinitionId); + } // getters and setters //////////////////////////////////////////////////////// diff --git a/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/cache/CaseDefinitionCacheTest.java b/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/cache/CaseDefinitionCacheTest.java new file mode 100644 index 00000000000..8bd88621551 --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/java/org/flowable/cmmn/test/cache/CaseDefinitionCacheTest.java @@ -0,0 +1,97 @@ +/* Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.flowable.cmmn.test.cache; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.flowable.cmmn.api.CmmnHistoryService; +import org.flowable.cmmn.api.CmmnManagementService; +import org.flowable.cmmn.api.CmmnRepositoryService; +import org.flowable.cmmn.api.CmmnRuntimeService; +import org.flowable.cmmn.api.repository.CmmnDeployment; +import org.flowable.cmmn.api.repository.CmmnDeploymentBuilder; +import org.flowable.cmmn.engine.CmmnEngine; +import org.flowable.cmmn.engine.CmmnEngineConfiguration; +import org.flowable.cmmn.engine.test.FlowableCmmnTestCase; +import org.flowable.cmmn.engine.test.impl.CmmnHistoryTestHelper; +import org.flowable.cmmn.engine.test.impl.CmmnJobTestHelper; +import org.flowable.common.engine.api.FlowableException; +import org.flowable.common.engine.impl.history.HistoryLevel; +import org.junit.Test; + +/** + * @author Joram Barrez + */ +public class CaseDefinitionCacheTest { + + @Test + public void testCaseDefinitionCache() { + CmmnEngine cmmnEngine = null; + String flowableCmmnCfgXml = "flowable.cache.cfg.xml"; + try (InputStream inputStream = FlowableCmmnTestCase.class.getClassLoader().getResourceAsStream(flowableCmmnCfgXml)) { + cmmnEngine = CmmnEngineConfiguration.createCmmnEngineConfigurationFromInputStream(inputStream).buildCmmnEngine(); + CmmnEngineConfiguration cmmnEngineConfiguration = cmmnEngine.getCmmnEngineConfiguration(); + CmmnManagementService cmmnManagementService = cmmnEngine.getCmmnManagementService(); + CmmnRepositoryService cmmnRepositoryService = cmmnEngine.getCmmnRepositoryService(); + CmmnRuntimeService cmmnRuntimeService = cmmnEngine.getCmmnRuntimeService(); + CmmnHistoryService cmmnHistoryService = cmmnEngine.getCmmnHistoryService(); + + List deploymentIds = new ArrayList<>(); + int nrOfModels = 9; + for (int nrOfIterations = 0; nrOfIterations < 10; nrOfIterations++) { + CmmnDeploymentBuilder deploymentBuilder = cmmnRepositoryService.createDeployment(); + for (int i = 1; i <= nrOfModels; i++) { + deploymentBuilder.addClasspathResource("org/flowable/cmmn/test/cache/case" + i + ".cmmn"); + } + CmmnDeployment deployment = deploymentBuilder.deploy(); + deploymentIds.add(0, deployment.getId()); + + assertThat(cmmnRepositoryService.createCaseDefinitionQuery().count()).isEqualTo((nrOfIterations + 1) * nrOfModels); + + for (int i = 1; i <= nrOfModels; i++) { + cmmnRuntimeService.createCaseInstanceBuilder().caseDefinitionKey("case" + i).start(); + } + + assertThat(cmmnManagementService.createJobQuery().count()).isEqualTo((nrOfIterations + 1) * nrOfModels); + } + + CmmnJobTestHelper.waitForJobExecutorToProcessAllJobs(cmmnEngine, 30000, 200, true); + + assertThat(cmmnManagementService.createJobQuery().count()).isEqualTo(0); + + if (CmmnHistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, cmmnEngineConfiguration)) { + for (int i = 1; i <= nrOfModels; i++) { + assertThat(cmmnHistoryService.createHistoricCaseInstanceQuery().caseDefinitionKey("case" + i).count()).isEqualTo(10); + } + } + + for (String deploymentId : deploymentIds) { + cmmnRepositoryService.deleteDeployment(deploymentId, true); + } + + } catch (IOException e) { + throw new FlowableException("Could not create CMMN engine", e); + + } finally { + if (cmmnEngine != null) { + cmmnEngine.close(); + } + } + } + +} diff --git a/modules/flowable-cmmn-engine/src/test/resources/flowable.cache.cfg.xml b/modules/flowable-cmmn-engine/src/test/resources/flowable.cache.cfg.xml new file mode 100644 index 00000000000..563b047cc14 --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/resources/flowable.cache.cfg.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case1.cmmn b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case1.cmmn new file mode 100644 index 00000000000..25e72f25aef --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case1.cmmn @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case2.cmmn b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case2.cmmn new file mode 100644 index 00000000000..1fcc74d2b8f --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case2.cmmn @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case3.cmmn b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case3.cmmn new file mode 100644 index 00000000000..48d05ad0335 --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case3.cmmn @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case4.cmmn b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case4.cmmn new file mode 100644 index 00000000000..010b0a3ac34 --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case4.cmmn @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case5.cmmn b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case5.cmmn new file mode 100644 index 00000000000..81ea6113ec2 --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case5.cmmn @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case6.cmmn b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case6.cmmn new file mode 100644 index 00000000000..c6a7130d6fc --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case6.cmmn @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case7.cmmn b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case7.cmmn new file mode 100644 index 00000000000..ed3e9248579 --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case7.cmmn @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case8.cmmn b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case8.cmmn new file mode 100644 index 00000000000..c42ecf0e862 --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case8.cmmn @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case9.cmmn b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case9.cmmn new file mode 100644 index 00000000000..23ac349f630 --- /dev/null +++ b/modules/flowable-cmmn-engine/src/test/resources/org/flowable/cmmn/test/cache/case9.cmmn @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/deployer/CachingAndArtifactsManager.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/deployer/CachingAndArtifactsManager.java index da2ea6a1562..987ad45a60f 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/deployer/CachingAndArtifactsManager.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/bpmn/deployer/CachingAndArtifactsManager.java @@ -55,6 +55,7 @@ public void updateCachingAndArtifacts(ParsedDeployment parsedDeployment) { // Add to deployment for further usage deployment.addDeployedArtifact(processDefinition); + deployment.addProcessDefinitionCacheEntry(processDefinition.getId(), cacheEntry); } } diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/deploy/DeploymentManager.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/deploy/DeploymentManager.java index 0903df9d257..57b7048d632 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/deploy/DeploymentManager.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/deploy/DeploymentManager.java @@ -128,7 +128,7 @@ public ProcessDefinitionCacheEntry resolveProcessDefinition(ProcessDefinition pr DeploymentEntity deployment = deploymentEntityManager.findById(deploymentId); deployment.setNew(false); deploy(deployment, null); - cachedProcessDefinition = processDefinitionCache.get(processDefinitionId); + cachedProcessDefinition = deployment.getProcessDefinitionCacheEntry(processDefinitionId); if (cachedProcessDefinition == null) { throw new FlowableException("deployment '" + deploymentId + "' didn't put process definition '" + processDefinitionId + "' in the cache"); diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/DeploymentEntity.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/DeploymentEntity.java index cbed93c8e5c..ee6dce1f0bb 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/DeploymentEntity.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/DeploymentEntity.java @@ -19,6 +19,7 @@ import org.flowable.common.engine.api.repository.EngineResource; import org.flowable.common.engine.impl.persistence.entity.Entity; +import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionCacheEntry; import org.flowable.engine.repository.Deployment; /** @@ -32,7 +33,11 @@ public interface DeploymentEntity extends Deployment, Entity { void addDeployedArtifact(Object deployedArtifact); List getDeployedArtifacts(Class clazz); + + void addProcessDefinitionCacheEntry(String processDefinitionId, ProcessDefinitionCacheEntry processDefinitionCacheEntry); + ProcessDefinitionCacheEntry getProcessDefinitionCacheEntry(String processDefinitionId); + void setName(String name); void setCategory(String category); diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/DeploymentEntityImpl.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/DeploymentEntityImpl.java index ca920684207..2fdaaf21b74 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/DeploymentEntityImpl.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/DeploymentEntityImpl.java @@ -22,6 +22,7 @@ import org.flowable.common.engine.api.repository.EngineResource; import org.flowable.engine.ProcessEngineConfiguration; +import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionCacheEntry; import org.flowable.engine.impl.util.CommandContextUtil; /** @@ -50,6 +51,7 @@ public class DeploymentEntityImpl extends AbstractBpmnEngineNoRevisionEntity imp * Will only be used during actual deployment to pass deployed artifacts (eg process definitions). Will be null otherwise. */ protected Map, List> deployedArtifacts; + protected Map processDefinitionCache = new HashMap<>(); public DeploymentEntityImpl() { @@ -119,6 +121,16 @@ public List getDeployedArtifacts(Class clazz) { return null; } + @Override + public void addProcessDefinitionCacheEntry(String processDefinitionId, ProcessDefinitionCacheEntry processDefinitionCacheEntry) { + processDefinitionCache.put(processDefinitionId, processDefinitionCacheEntry); + } + + @Override + public ProcessDefinitionCacheEntry getProcessDefinitionCacheEntry(String processDefinitionId) { + return processDefinitionCache.get(processDefinitionId); + } + // getters and setters //////////////////////////////////////////////////////// @Override diff --git a/modules/flowable-engine/src/test/java/org/flowable/standalone/cache/ProcessDefinitionCacheTest.java b/modules/flowable-engine/src/test/java/org/flowable/standalone/cache/ProcessDefinitionCacheTest.java new file mode 100644 index 00000000000..daf18e6e460 --- /dev/null +++ b/modules/flowable-engine/src/test/java/org/flowable/standalone/cache/ProcessDefinitionCacheTest.java @@ -0,0 +1,70 @@ +/* Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.flowable.standalone.cache; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import org.flowable.common.engine.impl.history.HistoryLevel; +import org.flowable.engine.impl.test.HistoryTestHelper; +import org.flowable.engine.impl.test.ResourceFlowableTestCase; +import org.flowable.engine.repository.Deployment; +import org.flowable.engine.repository.DeploymentBuilder; +import org.junit.jupiter.api.Test; + +public class ProcessDefinitionCacheTest extends ResourceFlowableTestCase { + + public ProcessDefinitionCacheTest() { + super("org/flowable/standalone/cache/flowable.cfg.xml"); + } + + @Test + public void testProcessDefinitionCache() { + List deploymentIds = new ArrayList<>(); + int nrOfModels = 9; + for (int nrOfIterations = 0; nrOfIterations < 10; nrOfIterations++) { + DeploymentBuilder deploymentBuilder = repositoryService.createDeployment(); + for (int i = 1; i <= nrOfModels; i++) { + deploymentBuilder.addClasspathResource("org/flowable/standalone/cache/process" + i + ".bpmn"); + } + Deployment deployment = deploymentBuilder.deploy(); + deploymentIds.add(0, deployment.getId()); + + assertThat(repositoryService.createProcessDefinitionQuery().count()).isEqualTo((nrOfIterations + 1) * nrOfModels); + + for (int i = 1; i <= nrOfModels; i++) { + runtimeService.startProcessInstanceByKey("process" + i); + } + + assertThat(managementService.createJobQuery().count()).isEqualTo((nrOfIterations + 1) * nrOfModels); + } + + waitForJobExecutorToProcessAllJobs(30000, 200); + + assertThat(managementService.createJobQuery().count()).isEqualTo(0); + + if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) { + for (int i = 1; i <= nrOfModels; i++) { + assertThat(historyService.createHistoricProcessInstanceQuery().processDefinitionKey("process" + i).count()).isEqualTo(10); + } + } + + for (String deploymentId : deploymentIds) { + repositoryService.deleteDeployment(deploymentId, true); + } + } + +} diff --git a/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/flowable.cfg.xml b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/flowable.cfg.xml new file mode 100644 index 00000000000..fac54104aeb --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/flowable.cfg.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process1.bpmn b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process1.bpmn new file mode 100644 index 00000000000..9e50b2e475b --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process1.bpmn @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process2.bpmn b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process2.bpmn new file mode 100644 index 00000000000..10dc22a5d06 --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process2.bpmn @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process3.bpmn b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process3.bpmn new file mode 100644 index 00000000000..55d49347580 --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process3.bpmn @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process4.bpmn b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process4.bpmn new file mode 100644 index 00000000000..c34dd6929f0 --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process4.bpmn @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process5.bpmn b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process5.bpmn new file mode 100644 index 00000000000..d81a7e9fab3 --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process5.bpmn @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process6.bpmn b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process6.bpmn new file mode 100644 index 00000000000..a938036c17f --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process6.bpmn @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process7.bpmn b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process7.bpmn new file mode 100644 index 00000000000..7411bb86151 --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process7.bpmn @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process8.bpmn b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process8.bpmn new file mode 100644 index 00000000000..d7597ab5cf2 --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process8.bpmn @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process9.bpmn b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process9.bpmn new file mode 100644 index 00000000000..e6762218565 --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/standalone/cache/process9.bpmn @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file