use of org.cache2k.Cache in project cache2k by cache2k.
the class IntegrationTest method ignoreMissingCacheConfiguration.
@Test
public void ignoreMissingCacheConfiguration() {
Cache c = new Cache2kBuilder<String, String>() {
}.manager(CacheManager.getInstance("specialCases")).name("missingConfiguration").build();
c.close();
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class IntegrationTest method typeMismatch.
@Test(expected = ConfigurationException.class)
public void typeMismatch() {
Cache c = new Cache2kBuilder<String, String>() {
}.manager(CacheManager.getInstance("specialCases")).name("typeMismatch").build();
c.close();
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class CacheManagerImpl method close.
/**
* The shutdown takes place in two phases. First all caches are notified to
* cancel their scheduled timer jobs, after that the shutdown is done. Cancelling
* the timer jobs first is needed, because there may be cache stacking and
* a timer job of one cache may call an already closed cache.
*
* <p>Rationale exception handling: Exceptions on shutdown just could silently
* ignored, because a shutdown is done any way. Exceptions could be happened
* long before in a parallel task, shutdown is the last point where this could
* be propagated to the application. Silently ignoring is bad anyway, because
* this will cause that serious problems keep undetected. The exception and
* error handling within the cache tries everything that exceptions will be
* routed through as early and directly as possible.
*/
@Override
public void close() {
Iterable<Cache> _caches;
synchronized (lock) {
if (closing) {
return;
}
_caches = cachesCopy();
closing = true;
}
logPhase("close");
List<Throwable> _suppressedExceptions = new ArrayList<Throwable>();
for (Cache c : _caches) {
((InternalCache) c).cancelTimerJobs();
}
for (Cache c : _caches) {
try {
c.close();
} catch (Throwable t) {
_suppressedExceptions.add(t);
}
}
try {
for (CacheManagerLifeCycleListener lc : cacheManagerLifeCycleListeners) {
lc.managerDestroyed(this);
}
} catch (Throwable t) {
_suppressedExceptions.add(t);
}
((Cache2kCoreProviderImpl) PROVIDER).removeManager(this);
synchronized (lock) {
for (Cache c : cacheNames.values()) {
log.warn("unable to close cache: " + c.getName());
}
}
eventuallyThrowException(_suppressedExceptions);
cacheNames = null;
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class OsgiIT method testEventPackage.
/**
* Simple test to see whether event package is exported.
*/
@Test
public void testEventPackage() {
CacheManager m = CacheManager.getInstance("testEventPackage");
final AtomicInteger _count = new AtomicInteger();
Cache<String, String> c = new Cache2kBuilder<String, String>() {
}.manager(m).eternal(true).addListener(new CacheEntryCreatedListener<String, String>() {
@Override
public void onEntryCreated(final Cache<String, String> cache, final CacheEntry<String, String> entry) {
_count.incrementAndGet();
}
}).build();
c.put("abc", "123");
assertTrue(c.containsKey("abc"));
assertEquals("123", c.peek("abc"));
assertEquals(1, _count.get());
c.close();
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class IllegalNamesTest method testCache.
@Test
public void testCache() {
try {
Cache c = Cache2kBuilder.forUnknownTypes().name(IllegalNamesTest.class.getName() + "-test-with-char-" + aChar).build();
c.close();
fail("expected exception for cache name with " + aChar);
} catch (IllegalArgumentException expected) {
/* expected */
}
}
Aggregations