From: <hib...@li...> - 2006-03-06 18:46:00
|
Author: ste...@jb... Date: 2006-03-06 13:45:51 -0500 (Mon, 06 Mar 2006) New Revision: 9558 Modified: trunk/Hibernate3/test/org/hibernate/test/querycache/QueryCacheTest.java Log: test for HHH-1543 Modified: trunk/Hibernate3/test/org/hibernate/test/querycache/QueryCacheTest.java =================================================================== --- trunk/Hibernate3/test/org/hibernate/test/querycache/QueryCacheTest.java 2006-03-06 15:16:27 UTC (rev 9557) +++ trunk/Hibernate3/test/org/hibernate/test/querycache/QueryCacheTest.java 2006-03-06 18:45:51 UTC (rev 9558) @@ -13,6 +13,7 @@ import org.hibernate.cfg.Environment; import org.hibernate.stat.EntityStatistics; import org.hibernate.stat.QueryStatistics; +import org.hibernate.stat.CollectionStatistics; import org.hibernate.test.TestCase; /** @@ -233,7 +234,77 @@ } + public void testCollectionFetchCachingFailureExpected() throws Throwable { + getSessions().evictQueries(); + getSessions().getStatistics().clear(); + final String queryString = "select distinct i from Item i join fetch i.parts"; + + Session s = openSession(); + Transaction t = s.beginTransaction(); + Item i = new Item(); + i.setName( "widget" ); + i.setDescription( "A really top-quality, full-featured widget." ); + Part p1 = new Part(); + p1.setName( "p1-1" ); + i.getParts().add( p1 ); + Part p2 = new Part(); + p2.setName( "part-2" ); + i.getParts().add( p2 ); + s.save( i ); + t.commit(); + s.close(); + + getSessions().evict( Item.class ); + + QueryStatistics qs = getSessions().getStatistics().getQueryStatistics( queryString ); + EntityStatistics es = getSessions().getStatistics().getEntityStatistics( Item.class.getName() ); + CollectionStatistics cs = getSessions().getStatistics().getCollectionStatistics( Item.class.getName() + ".parts" ); + + Thread.sleep(200); + + s = openSession(); + t = s.beginTransaction(); + List result = s.createQuery( queryString ).setCacheable( true ).list(); + assertEquals( result.size(), 1 ); + i = ( Item ) result.get( 0 ); + assertTrue( Hibernate.isInitialized( i ) ); + assertTrue( Hibernate.isInitialized( i.getParts() ) ); + t.commit(); + s.close(); + + assertEquals( qs.getCacheHitCount(), 0 ); + assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 ); + assertEquals( getSessions().getStatistics().getCollectionFetchCount(), 0 ); + + s = openSession(); + t = s.beginTransaction(); + result = s.createQuery( queryString ).setCacheable( true ).list(); + assertEquals( result.size(), 1 ); + i = ( Item ) result.get( 0 ); + assertTrue( Hibernate.isInitialized( i ) ); + // todo : this is the bug causing the failure expected (HHH-1543). + // when the query results are served from the query cache, + // collections are not forced to initialize + assertTrue( Hibernate.isInitialized( i.getParts() ) ); + t.commit(); + s.close(); + + assertEquals( qs.getCacheHitCount(), 1 ); + assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 ); + assertEquals( getSessions().getStatistics().getCollectionFetchCount(), 0 ); + assertEquals( es.getFetchCount(), 0 ); + assertEquals( cs.getFetchCount(), 0 ); + + s = openSession(); + t = s.beginTransaction(); + s.delete( i ); + s.flush(); + s.createQuery("delete Part").executeUpdate(); + t.commit(); + s.close(); + } + protected String[] getMappings() { return new String[] { "querycache/Item.hbm.xml" }; } |