use of org.cache2k.Cache2kBuilder in project cache2k by cache2k.
the class Cache2kBuilderTest method cacheClosedEventFired.
private void cacheClosedEventFired(boolean _wiredCache) {
final AtomicBoolean _FIRED = new AtomicBoolean();
Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes();
_builder.addCacheClosedListener(new CacheClosedListener() {
@Override
public void onCacheClosed(final Cache cache) {
_FIRED.set(true);
}
});
if (_wiredCache) {
StaticUtil.enforceWiredCache(_builder);
}
Cache c = _builder.build();
c.close();
assertTrue(_FIRED.get());
}
use of org.cache2k.Cache2kBuilder in project cache2k by cache2k.
the class Cache2kBuilderTest method cacheRemovedAfterClose_WiredCache.
@Test
public void cacheRemovedAfterClose_WiredCache() {
final String _NAME = this.getClass().getSimpleName() + "-cacheRemovedAfterCloseWiredCache";
CacheManager cm = CacheManager.getInstance(_NAME);
Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes().manager(cm).name(_NAME);
StaticUtil.enforceWiredCache(_builder);
Cache c = _builder.build();
assertEquals(c, cm.getActiveCaches().iterator().next());
c.close();
assertFalse(cm.getActiveCaches().iterator().hasNext());
}
use of org.cache2k.Cache2kBuilder in project cache2k by cache2k.
the class Cache2kBuilderTest method anonymousWithObjectObject.
@Test(expected = IllegalArgumentException.class)
public void anonymousWithObjectObject() {
Cache c = new Cache2kBuilder<Object, Object>() {
}.eternal(true).build();
c.clear();
}
use of org.cache2k.Cache2kBuilder in project cache2k by cache2k.
the class CacheManagerLifeCycleTest method onlyOneCacheForWired.
@Test
public void onlyOneCacheForWired() {
String _uniqueName = this.getClass().getName() + ".onlyOneCacheForWired";
CacheManager cm = CacheManager.getInstance(_uniqueName);
Cache2kBuilder b = Cache2kBuilder.forUnknownTypes().manager(cm);
StaticUtil.enforceWiredCache(b);
Cache c = b.build();
assertEquals("one cache active", 1, StaticUtil.count(cm.getActiveCaches()));
cm.close();
}
use of org.cache2k.Cache2kBuilder in project cache2k by cache2k.
the class CacheRule method buildCache.
Cache<K, V> buildCache() {
String _name = description.getTestClass().getName();
Cache2kBuilder b = getInitialBuilder();
for (Specialization sp : configurationSpecialization) {
sp.extend(b);
}
if (shared) {
b.name(description.getTestClass());
sharedCache.put(_name, _name);
} else {
if (sharedCache.containsKey(_name)) {
throw new IllegalArgumentException("Shared cache usage: Method rule must be identical instance.");
}
b.name(description.getTestClass(), description.getMethodName());
}
return b.build();
}
Aggregations