in commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/struct/AbstractLRUMap.java [391:463]
protected void verifyCache()
{
if ( !log.isTraceEnabled() )
{
return;
}
log.trace( "verifycache: mapContains {0} elements, linked list "
+ "contains {1} elements", map.size(), list.size() );
log.trace( "verifycache: checking linked list by key" );
for (LRUElementDescriptor<K, V> li = list.getFirst(); li != null; li = (LRUElementDescriptor<K, V>) li.next )
{
final K key = li.getKey();
if ( !map.containsKey( key ) )
{
log.error( "verifycache: map does not contain key : {0}", li.getKey() );
log.error( "li.hashCode={0}", li.getKey().hashCode() );
log.error( "key class={0}", key.getClass() );
log.error( "key hashCode={0}", key.hashCode() );
log.error( "key toString={0}", key.toString() );
if ( key instanceof GroupAttrName )
{
final GroupAttrName<?> name = (GroupAttrName<?>) key;
log.error( "GroupID hashCode={0}", name.groupId.hashCode() );
log.error( "GroupID.class={0}", name.groupId.getClass() );
log.error( "AttrName hashCode={0}", name.attrName.hashCode() );
log.error( "AttrName.class={0}", name.attrName.getClass() );
}
dumpMap();
}
else if ( map.get( li.getKey() ) == null )
{
log.error( "verifycache: linked list retrieval returned null for key: {0}",
li.getKey() );
}
}
log.trace( "verifycache: checking linked list by value " );
for (LRUElementDescriptor<K, V> li3 = list.getFirst(); li3 != null; li3 = (LRUElementDescriptor<K, V>) li3.next )
{
if (!map.containsValue(li3))
{
log.error( "verifycache: map does not contain value : {0}", li3 );
dumpMap();
}
}
log.trace( "verifycache: checking via keysets!" );
map.keySet().stream()
.filter(key -> {
for (LRUElementDescriptor<K, V> li2 = list.getFirst(); li2 != null; li2 = (LRUElementDescriptor<K, V>) li2.next )
{
if ( key.equals( li2.getKey() ) )
{
return true;
}
}
log.error( "verifycache: key not found in list : {0}", key );
dumpCacheEntries();
if ( map.containsKey( key ) )
{
log.error( "verifycache: map contains key" );
}
else
{
log.error( "verifycache: map does NOT contain key, what the HECK!" );
}
return false;
})
.findFirst();
}