HHH-9203 - ConcurrentNaturalIdCacheStatisticsImpl#getEntries() fails

with ClassCastException

Conflicts:
	hibernate-core/src/test/java/org/hibernate/test/naturalid/mutable/cached/CachedMutableNaturalIdStrictReadWriteTest.java
This commit is contained in:
Lukasz Antoniak 2014-05-23 17:43:53 -04:00 committed by Brett Meyer
parent e226cb9c7d
commit 73f7b18523
2 changed files with 34 additions and 9 deletions

View File

@ -31,7 +31,7 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.hibernate.cache.spi.CacheKey;
import org.hibernate.cache.spi.NaturalIdCacheKey;
import org.hibernate.cache.spi.Region;
import org.hibernate.stat.NaturalIdCacheStatistics;
@ -145,7 +145,7 @@ public class ConcurrentNaturalIdCacheStatisticsImpl extends CategorizedStatistic
final Iterator iter = this.region.toMap().entrySet().iterator();
while ( iter.hasNext() ) {
final Map.Entry me = (Map.Entry) iter.next();
map.put( ( (CacheKey) me.getKey() ).getKey(), me.getValue() );
map.put( ( (NaturalIdCacheKey) me.getKey() ).getNaturalIdValues(), me.getValue() );
}
return map;
}

View File

@ -1,17 +1,18 @@
package org.hibernate.test.naturalid.mutable.cached;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.Serializable;
import java.util.Map;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.stat.NaturalIdCacheStatistics;
import org.junit.Test;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.cache.CachingRegionFactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Test;
public class CachedMutableNaturalIdStrictReadWriteTest extends
CachedMutableNaturalIdTest {
@ -21,6 +22,30 @@ public class CachedMutableNaturalIdStrictReadWriteTest extends
super.configure(cfg);
cfg.setProperty( CachingRegionFactory.DEFAULT_ACCESSTYPE, "read-write" );
}
@Test
@TestForIssue( jiraKey = "HHH-9203" )
public void testToMapConversion() {
sessionFactory().getStatistics().clear();
final Session session = openSession();
session.getTransaction().begin();
final AllCached it = new AllCached( "IT" );
session.save( it );
session.getTransaction().commit();
session.close();
final NaturalIdCacheStatistics stats = sessionFactory().getStatistics().getNaturalIdCacheStatistics(
"hibernate.test." + AllCached.class.getName() + "##NaturalId"
);
final Map entries = stats.getEntries();
assertEquals( 1, entries.size() );
final Serializable[] cacheKey = (Serializable[]) entries.keySet().iterator().next();
assertEquals( 1, cacheKey.length );
assertEquals( it.getName(), cacheKey[0] );
assertNotNull( entries.get( cacheKey ) );
}
@Test
@TestForIssue( jiraKey = "HHH-7278" )