use of org.cache2k.Cache 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.Cache in project cache2k by cache2k.
the class JmxSupportTest method testDisabled.
@Test
public void testDisabled() throws Exception {
String _name = getClass().getName() + ".testInitialProperties";
Cache c = new Cache2kBuilder<Long, List<Collection<Long>>>() {
}.name(_name).disableStatistics(true).eternal(true).build();
objectName = constructCacheObjectName(_name);
try {
retrieve("Alert");
fail("exception expected");
} catch (InstanceNotFoundException ex) {
}
c.close();
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class JmxSupportTest method testInitialProperties.
@Test
public void testInitialProperties() throws Exception {
Date _beforeCreateion = new Date();
String _name = getClass().getName() + ".testInitialProperties";
Cache c = new Cache2kBuilder<Long, List<Collection<Long>>>() {
}.name(_name).eternal(true).build();
objectName = constructCacheObjectName(_name);
checkAttribute("KeyType", "Long");
checkAttribute("ValueType", "java.util.List<java.util.Collection<Long>>");
checkAttribute("Size", 0L);
checkAttribute("EntryCapacity", 1234L);
checkAttribute("InsertCount", 0L);
checkAttribute("MissCount", 0L);
checkAttribute("RefreshCount", 0L);
checkAttribute("RefreshFailedCount", 0L);
checkAttribute("RefreshedHitCount", 0L);
checkAttribute("ExpiredCount", 0L);
checkAttribute("EvictedCount", 0L);
checkAttribute("PutCount", 0L);
checkAttribute("RemoveCount", 0L);
checkAttribute("ClearedEntriesCount", 0L);
checkAttribute("ClearCount", 0L);
checkAttribute("KeyMutationCount", 0L);
checkAttribute("LoadExceptionCount", 0L);
checkAttribute("SuppressedLoadExceptionCount", 0L);
checkAttribute("HitRate", 0.0);
checkAttribute("HashQuality", 100);
checkAttribute("MillisPerLoad", 0.0);
checkAttribute("TotalLoadMillis", 0L);
checkAttribute("Implementation", "HeapCache");
checkAttribute("ClearedTime", null);
checkAttribute("Alert", 0);
assertTrue("reasonable CreatedTime", ((Date) retrieve("CreatedTime")).compareTo(_beforeCreateion) >= 0);
assertTrue("reasonable InfoCreatedTime", ((Date) retrieve("InfoCreatedTime")).compareTo(_beforeCreateion) >= 0);
assertTrue("reasonable InfoCreatedDeltaMillis", ((Integer) retrieve("InfoCreatedDeltaMillis")) >= 0);
assertTrue("reasonable EvictionStatistics", retrieve("EvictionStatistics").toString().contains("impl="));
assertTrue("reasonable IntegrityDescriptor", retrieve("IntegrityDescriptor").toString().startsWith("0."));
c.close();
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class BasicCacheOperationsTest method peekAndRemove_Exception.
@Test
public void peekAndRemove_Exception() {
((Cache) cache).put(KEY, new ExceptionWrapper(OUCH));
try {
cache.peekAndRemove(KEY);
fail("exception expected");
} catch (CacheLoaderException ex) {
}
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class BasicCacheOperationsTest method getEntryState_Exception.
@Test
public void getEntryState_Exception() {
if (!(cache instanceof InternalCache)) {
return;
}
((Cache) cache).put(KEY, new ExceptionWrapper(OUCH));
InternalCache c = (InternalCache) cache;
String s = c.getEntryState(KEY);
assertTrue(s.contains("exception="));
}
Aggregations