use of org.cache2k.CacheManager in project cache2k by cache2k.
the class OsgiIT method testSimple.
@Test
public void testSimple() {
CacheManager m = CacheManager.getInstance("testSimple");
Cache<String, String> c = Cache2kBuilder.of(String.class, String.class).manager(m).eternal(true).build();
c.put("abc", "123");
assertTrue(c.containsKey("abc"));
assertEquals("123", c.peek("abc"));
c.close();
}
use of org.cache2k.CacheManager in project cache2k by cache2k.
the class OsgiIT method testWithAnonBuilder.
@Test
public void testWithAnonBuilder() {
CacheManager m = CacheManager.getInstance("testWithAnonBuilder");
Cache<String, String> c = new Cache2kBuilder<String, String>() {
}.manager(m).eternal(true).build();
c.put("abc", "123");
assertTrue(c.containsKey("abc"));
assertEquals("123", c.peek("abc"));
c.close();
}
use of org.cache2k.CacheManager 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.CacheManager in project cache2k by cache2k.
the class JmxSupportTest method multipleWarnings.
/**
* Construct three caches with multiple issues and check the health string of the manager JMX.
*/
@Test
public void multipleWarnings() throws Exception {
final String _MANAGER_NAME = getClass().getName() + ".multipleWarnings";
final String _CACHE_NAME_BAD_HASHING = "cacheWithBadHashing";
final String _CACHE_NAME_KEY_MUTATION = "cacheWithKeyMutation";
final String _CACHE_NAME_MULTIPLE_ISSUES = "cacheWithMultipleIssues";
final String _SUPPRESS1 = "org.cache2k.Cache/" + _MANAGER_NAME + ":" + _CACHE_NAME_KEY_MUTATION;
final String _SUPPRESS2 = "org.cache2k.Cache/" + _MANAGER_NAME + ":" + _CACHE_NAME_MULTIPLE_ISSUES;
Log.registerSuppression(_SUPPRESS1, new Log.SuppressionCounter());
Log.registerSuppression(_SUPPRESS2, new Log.SuppressionCounter());
CacheManager m = CacheManager.getInstance(_MANAGER_NAME);
Cache _cacheWithBadHashing = Cache2kBuilder.of(Object.class, Object.class).manager(m).name(_CACHE_NAME_BAD_HASHING).eternal(true).build();
Cache _cacheWithKeyMutation = Cache2kBuilder.of(Object.class, Object.class).manager(m).name(_CACHE_NAME_KEY_MUTATION).eternal(true).entryCapacity(50).build();
Cache _cacheWithMultipleIssues = Cache2kBuilder.of(Object.class, Object.class).manager(m).name(_CACHE_NAME_MULTIPLE_ISSUES).entryCapacity(50).eternal(true).build();
for (int i = 0; i < 9; i++) {
_cacheWithBadHashing.put(new KeyForMutation(), 1);
}
for (int i = 0; i < 100; i++) {
_cacheWithMultipleIssues.put(new KeyForMutation(), 1);
}
for (int i = 0; i < 100; i++) {
KeyForMutation v = new KeyForMutation();
_cacheWithKeyMutation.put(v, 1);
_cacheWithMultipleIssues.put(v, 1);
v.value = 1;
}
String _health = (String) server.getAttribute(getCacheManagerObjectName(_MANAGER_NAME), "HealthStatus");
assertEquals("FAILURE: [cacheWithKeyMutation] hash quality is 0 (threshold: 5); " + "FAILURE: [cacheWithMultipleIssues] hash quality is 0 (threshold: 5); " + "WARNING: [cacheWithBadHashing] hash quality is 7 (threshold: 20); " + "WARNING: [cacheWithKeyMutation] key mutation detected; " + "WARNING: [cacheWithMultipleIssues] key mutation detected", _health);
Log.deregisterSuppression(_SUPPRESS1);
Log.deregisterSuppression(_SUPPRESS2);
m.close();
}
use of org.cache2k.CacheManager in project cache2k by cache2k.
the class JmxSupportTest method testManagerPresent.
@Test
public void testManagerPresent() throws Exception {
String _name = getClass().getName() + ".testManagerPresent";
CacheManager m = CacheManager.getInstance(_name);
MBeanInfo i = getCacheManagerInfo(_name);
assertEquals(ManagerMXBeanImpl.class.getName(), i.getClassName());
m.close();
}
Aggregations