forked from camunda/camunda-bpm-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engine): provide SPI for custom deployment cache implementation
* sets maximum cache capacity as well related to #CAM-6397,#CAM-6393
- Loading branch information
Johannes Heinemann
committed
Sep 26, 2016
1 parent
847cbaa
commit 61c0bdd
Showing
15 changed files
with
556 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
240 changes: 53 additions & 187 deletions
240
engine/src/main/java/org/camunda/bpm/engine/impl/cfg/ProcessEngineConfigurationImpl.java
Large diffs are not rendered by default.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
engine/src/main/java/org/camunda/bpm/engine/impl/persistence/deploy/CacheFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.camunda.bpm.engine.impl.persistence.deploy; | ||
|
||
import org.camunda.commons.utils.cache.Cache; | ||
|
||
/** | ||
* <p>Builds the caches for the {@link DeploymentCache}.</p> | ||
*/ | ||
public interface CacheFactory { | ||
|
||
/** | ||
* Creates a cache that does not exceed a specified number of elements. | ||
* | ||
* @param maxNumberOfElementsInCache | ||
* The maximum number of elements that is allowed within the cache at the same time. | ||
* @return | ||
* The cache to be created. | ||
*/ | ||
public Cache createCache(int maxNumberOfElementsInCache); | ||
} |
19 changes: 19 additions & 0 deletions
19
engine/src/main/java/org/camunda/bpm/engine/impl/persistence/deploy/DefaultCacheFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.camunda.bpm.engine.impl.persistence.deploy; | ||
|
||
|
||
import org.camunda.bpm.engine.impl.db.DbEntity; | ||
import org.camunda.commons.utils.cache.Cache; | ||
import org.camunda.commons.utils.cache.ConcurrentLruCache; | ||
|
||
/** | ||
* <p>Provides the default cache implementation for the deployment caches see {@link DeploymentCache}.</p> | ||
* | ||
* @author Johannes Heinemann | ||
*/ | ||
public class DefaultCacheFactory implements CacheFactory{ | ||
|
||
@Override | ||
public Cache createCache(int maxNumberOfElementsInCache) { | ||
return new ConcurrentLruCache<String, DbEntity>(maxNumberOfElementsInCache); | ||
} | ||
} |
314 changes: 165 additions & 149 deletions
314
engine/src/main/java/org/camunda/bpm/engine/impl/persistence/deploy/DeploymentCache.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
engine/src/test/java/org/camunda/bpm/engine/test/api/cfg/DeploymentCacheCfgTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.camunda.bpm.engine.test.api.cfg; | ||
|
||
import org.camunda.bpm.engine.impl.persistence.deploy.DeploymentCache; | ||
import org.camunda.bpm.engine.impl.test.ResourceProcessEngineTestCase; | ||
import org.camunda.bpm.engine.test.Deployment; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Johannes Heinemann | ||
*/ | ||
public class DeploymentCacheCfgTest extends ResourceProcessEngineTestCase { | ||
|
||
|
||
public DeploymentCacheCfgTest() { | ||
super("org/camunda/bpm/engine/test/api/cfg/customized.cacheFactory.camunda.cfg.xml"); | ||
} | ||
|
||
@Test | ||
@Deployment(resources = | ||
{"org/camunda/bpm/engine/test/api/cfg/MaxCacheSizeCfgTest.testDefaultCacheRemovesLRUElementWhenMaxSizeIsExceeded.bpmn20.xml"}) | ||
public void testPlugInOwnCacheImplementation() { | ||
// The 'customized.cacheFactory.camunda.cfg.xml' sets a customized cache factory that uses the | ||
// default cache implementation, but limits the maximum number of elements within the cache to 2. | ||
// According to the least recently used principle of the default implementation should the first | ||
// process not be contained in the cache anymore. | ||
|
||
// given | ||
String processDefinitionIdOne = repositoryService.createProcessDefinitionQuery() | ||
.processDefinitionKey("one") | ||
.singleResult() | ||
.getId(); | ||
String processDefinitionIdTwo = repositoryService.createProcessDefinitionQuery() | ||
.processDefinitionKey("two") | ||
.singleResult() | ||
.getId(); | ||
String processDefinitionIdThree = repositoryService.createProcessDefinitionQuery() | ||
.processDefinitionKey("three") | ||
.singleResult() | ||
.getId(); | ||
|
||
|
||
// when | ||
DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache(); | ||
|
||
// then | ||
assertNotNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionIdTwo)); | ||
assertNotNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionIdThree)); | ||
|
||
assertNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionIdOne)); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
engine/src/test/java/org/camunda/bpm/engine/test/api/cfg/MaxCacheSizeCfgTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.camunda.bpm.engine.test.api.cfg; | ||
|
||
import org.camunda.bpm.engine.impl.persistence.deploy.DeploymentCache; | ||
import org.camunda.bpm.engine.impl.test.ResourceProcessEngineTestCase; | ||
import org.camunda.bpm.engine.test.Deployment; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Johannes Heinemann | ||
*/ | ||
public class MaxCacheSizeCfgTest extends ResourceProcessEngineTestCase { | ||
|
||
public MaxCacheSizeCfgTest() { | ||
super("org/camunda/bpm/engine/test/api/cfg/cacheSize.reduced.camunda.cfg.xml"); | ||
} | ||
|
||
@Test | ||
@Deployment | ||
public void testDefaultCacheRemovesLRUElementWhenMaxSizeIsExceeded() { | ||
// The 'cacheSize.reduced.camunda.cfg.xml' sets the maximum number of elements of the | ||
// to 2. Accordingly, one process should not be contained in the cache anymore. | ||
|
||
// given | ||
String processDefinitionIdOne = repositoryService.createProcessDefinitionQuery() | ||
.processDefinitionKey("one") | ||
.singleResult() | ||
.getId(); | ||
String processDefinitionIdTwo = repositoryService.createProcessDefinitionQuery() | ||
.processDefinitionKey("two") | ||
.singleResult() | ||
.getId(); | ||
String processDefinitionIdThree = repositoryService.createProcessDefinitionQuery() | ||
.processDefinitionKey("three") | ||
.singleResult() | ||
.getId(); | ||
|
||
// when | ||
DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache(); | ||
|
||
// then | ||
int numberOfProcessesInCache = 0; | ||
numberOfProcessesInCache += | ||
deploymentCache.getProcessDefinitionCache().get(processDefinitionIdOne) == null ? 0 : 1; | ||
numberOfProcessesInCache += | ||
deploymentCache.getProcessDefinitionCache().get(processDefinitionIdTwo) == null ? 0 : 1; | ||
numberOfProcessesInCache += | ||
deploymentCache.getProcessDefinitionCache().get(processDefinitionIdThree) == null ? 0 : 1; | ||
|
||
assertTrue(numberOfProcessesInCache == 2); | ||
} | ||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
engine/src/test/java/org/camunda/bpm/engine/test/api/cfg/MyCacheFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.camunda.bpm.engine.test.api.cfg; | ||
|
||
import org.camunda.bpm.engine.impl.db.DbEntity; | ||
import org.camunda.bpm.engine.impl.persistence.deploy.DefaultCacheFactory; | ||
import org.camunda.commons.utils.cache.Cache; | ||
import org.camunda.commons.utils.cache.ConcurrentLruCache; | ||
|
||
/** | ||
* Cache that has a maximum capacity two elements. | ||
* | ||
* @author Johannes Heinemann | ||
*/ | ||
public class MyCacheFactory extends DefaultCacheFactory { | ||
|
||
@Override | ||
public Cache createCache(int maxNumberOfElementsInCache) { | ||
return new MyMostRecentlyUsedCache<String, DbEntity>(maxNumberOfElementsInCache); | ||
} | ||
|
||
private class MyMostRecentlyUsedCache<K, V> extends ConcurrentLruCache<K, V> { | ||
|
||
public MyMostRecentlyUsedCache(int capacity) { | ||
super(2); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.