Skip to content

Commit

Permalink
chore(merge): release-10.2.0 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bonita-ci committed Aug 29, 2024
2 parents ff115f2 + b4e2bfa commit 6726cdf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
testAnnotationProcessor libs.lombok
testImplementation libs.lombok
testImplementation "org.awaitility:awaitility:${Deps.awaitilityVersion}"
testImplementation "com.github.stefanbirkner:system-lambda:${Deps.systemLambdaVersion}"
}

tasks.register("testsJar", Jar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
**/
package org.bonitasoft.engine.cache;

import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOut;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.*;

import java.util.ArrayList;
Expand Down Expand Up @@ -161,19 +163,19 @@ public void eternalCacheTest() throws Exception {
assertEquals("Object should still be in cache", value, object);
}

@Test(expected = SCacheException.class)
public void cacheNotDefined() throws Exception {
@Test
public void cache_store_should_log_when_cache_not_found() throws Exception {
// given
final String key = "defaultTimeout";
final String anotherCacheName = "Should_use_default_config";
cacheService.store(anotherCacheName, key, new String());
}

@Test(expected = SCacheException.class)
public void defaultConfigNotSerializablePutObject() throws SCacheException {
final String cacheName = "Should_use_default_config";
final String key = "someObjectCacheKey";
// We cannot store non-Serializable objects if copyOnRead or copyOnWrite is set to true:
cacheService.store(cacheName, key, new Object());
// when
final String log = tapSystemOut(() -> cacheService.store(anotherCacheName, key, ""));

// then
assertThat(log)
.containsPattern("WARN.*No specific cache configuration found for cache 'Should_use_default_config'");

}

@Test
Expand Down
4 changes: 4 additions & 0 deletions services/bonita-cache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ dependencies {
api project(':services:bonita-commons')
api project(':services:bonita-session')
api libs.springContext

annotationProcessor libs.lombok
compileOnly libs.lombok

testImplementation "junit:junit:${Deps.junit4Version}"
testImplementation "org.mockito:mockito-core:${Deps.mockitoVersion}"
testImplementation libs.logback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
package org.bonitasoft.engine.cache.ehcache;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

import lombok.extern.slf4j.Slf4j;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
Expand All @@ -43,6 +40,7 @@
@Order(2)
@Component
@ConditionalOnSingleCandidate(CacheService.class)
@Slf4j
public class EhCacheCacheService implements CacheService, PlatformLifecycleService {

protected CacheManager cacheManager;
Expand Down Expand Up @@ -114,22 +112,25 @@ public void resume() throws SCacheException {
}
}

protected synchronized Cache createCache(final String cacheName, final String internalCacheName)
protected synchronized Cache createCache(final String cacheName)
throws SCacheException {
if (cacheManager == null) {
throw new SCacheException("The cache is not started, call start() on the cache service");
}
Cache cache = cacheManager.getCache(internalCacheName);
Cache cache = cacheManager.getCache(cacheName);
if (cache == null) {
final CacheConfiguration cacheConfiguration = cacheConfigurations.get(cacheName);
final CacheConfiguration newCacheConfig;
if (cacheConfiguration != null) {
final CacheConfiguration newCacheConfig = cacheConfiguration.clone();
newCacheConfig.setName(internalCacheName);
cache = new Cache(newCacheConfig);
cacheManager.addCache(cache);
newCacheConfig = cacheConfiguration.clone();
} else {
throw new SCacheException("No configuration found for the cache " + cacheName);
log.warn("No specific cache configuration found for cache '{}'. Using default configuration",
cacheName);
newCacheConfig = defaultCacheConfiguration.clone();
}
newCacheConfig.setName(cacheName);
cache = new Cache(newCacheConfig);
cacheManager.addCache(cache);
}
return cache;
}
Expand All @@ -142,7 +143,7 @@ public void store(final String cacheName, final Serializable key, final Object v
try {
Cache cache = cacheManager.getCache(cacheName);
if (cache == null) {
cache = createCache(cacheName, cacheName);
cache = createCache(cacheName);
}
if (value instanceof Serializable) {
cache.put(new Element(key, (Serializable) value));
Expand Down

0 comments on commit 6726cdf

Please sign in to comment.