• Bug
  • Status: Closed
  • 2 Major
  • Resolution: Fixed
  • ehcache-core
  • foshea
  • Reporter: cavedave
  • April 09, 2013
  • 1
  • Watchers: 4
  • May 13, 2013
  • April 10, 2013

Description

At JUnit unit tests execution time a Spring application context is initialized for each test during set up and destroyed during tear down. The application context takes care of creating an Hibernate SessionFactory which is configured to use a _net.sf.ehcache.hibernate.EhCacheProvider_ cache provider.

Sometimes (not always!) unit tests fail with the following exception:

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' 
 defined in class path resource [sysconf/applicationContext-jbpm-sessionFactory.xml]: 
 Invocation of init method failed; 
 nested exception is net.sf.ehcache.CacheException: java.lang.AssertionError: NaN Eviction Cost [hit:NaN miss:NaN size:0]
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
 	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
 	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
 	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
 	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
 	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
 	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
 	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
 	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
 	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:119)
 	at com.cardinis.cardinis.test.CardinisTestCaseHelper.init(CardinisTestCaseHelper.java:233)
 	at com.cardinis.cardinis.test.CardinisTestSuite.setUpEnvironment(CardinisTestSuite.java:189)
 	at sun.reflect.GeneratedMethodAccessor296.invoke(Unknown Source)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 	at java.lang.reflect.Method.invoke(Method.java:597)
 	at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
 	at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
 	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
 	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
 	at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
 	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
 	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
 	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
 	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
 	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
 [...]
 Caused by: net.sf.ehcache.CacheException: java.lang.AssertionError: NaN Eviction Cost [hit:NaN miss:NaN size:0]
 	at net.sf.ehcache.CacheManager.init(CacheManager.java:367)
 	at net.sf.ehcache.CacheManager.<init>(CacheManager.java:243)
 	at net.sf.ehcache.hibernate.EhCacheProvider.start(EhCacheProvider.java:101)
 	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:183)
 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
 	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
 	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
 	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
 	... 61 more
 Caused by: java.lang.AssertionError: NaN Eviction Cost [hit:NaN miss:NaN size:0]
 	at net.sf.ehcache.pool.impl.AbstractBalancedAccessEvictor.evictionCost(AbstractBalancedAccessEvictor.java:172)
 	at net.sf.ehcache.pool.impl.AbstractBalancedAccessEvictor.access$000(AbstractBalancedAccessEvictor.java:37)
 	at net.sf.ehcache.pool.impl.AbstractBalancedAccessEvictor$EvictionCostComparator.compare(AbstractBalancedAccessEvictor.java:63)
 	at java.util.Arrays.mergeSort(Arrays.java:1270)
 	at java.util.Arrays.sort(Arrays.java:1210)
 	at java.util.Collections.sort(Collections.java:159)
 	at net.sf.ehcache.pool.impl.AbstractBalancedAccessEvictor.freeSpace(AbstractBalancedAccessEvictor.java:124)
 	at net.sf.ehcache.pool.impl.AbstractPool.setMaxSize(AbstractPool.java:87)
 	at net.sf.ehcache.config.CacheConfiguration.updateCacheManagerPoolSizes(CacheConfiguration.java:1656)
 	at net.sf.ehcache.config.CacheConfiguration.setupFor(CacheConfiguration.java:1545)
 	at net.sf.ehcache.CacheManager.initializeEhcache(CacheManager.java:1234)
 	at net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:1289)
 	at net.sf.ehcache.CacheManager.addConfiguredCaches(CacheManager.java:706)
 	at net.sf.ehcache.CacheManager.doInit(CacheManager.java:424)
 	at net.sf.ehcache.CacheManager.init(CacheManager.java:358)
 	... 70 more

This issue originated from http://forums.terracotta.org/forums/posts/list/8010.page

Comments

Chris Dennis 2013-04-10

This same bug was actually identified by a unit test recently. It’s fixed in the 2.5.x branch (and all other dev branches). The fix has been released in the 2.6.x branch as part of 2.6.6, but there has not been a 2.5.x release since the fix was merged in to the 2.5.x branch. Not sure if there is a scheduled 2.5.x release at the moment or not.

Davide Cavestro 2013-04-10

So please consider this is at least a good reason to schedule a 2.5.x release :-) We have tests failing on an intermittent basis… it’s somewhat cumbersome.

Chris Dennis 2013-04-10

Assigning this to someone with the authority to think/talk about a 2.5.x release.

Mauro Molinari 2013-04-10

Thanks for the quick fix. We got no answer for long time in the forum :-(

Davide Cavestro 2013-05-07

Just wondering why _net.sf.ehcache:ehcache-core:2.6.6_ seems still available only via oss.sonatype.org maven repo and not from other public maven repos (like maven central, ibiblio and so on)

Davide Cavestro 2013-05-07

I was wrong: _‘net.sf.ehcache:ehcache-core:2.6.6’_ seems not available at all from maven, neither from the oss.sonatype.org repo: did the GAV change? From http://ehcache.org/downloads/catalog I see the last stable release available is 2.6.6 (a tar.gz archive). OTOH I’ve seen there’s a _‘net.sf.ehcache.internal:ehcache-core:2.7.0’_ on the pubic maven repos published as _not meant to be used directly_. Did I miss something? If so, could you please redirect me to the relevant documentation? In order to test your fix within my CI server I need to declare and resolve a valid maven dependency: I’ve checked the release notes with no success…

Fiona OShea 2013-05-07

Davide, We are checking into the maven issue. We will update the Ehcache 2.6.6 release notes with this Issue information.

Davide Cavestro 2013-05-10

@Fiona I confirm release 2.6.6 is now available on public maven repos, and it actually seems fixed (I haven’t reproduced it anymore on that version).

Fiona OShea 2013-05-13

Great thanks for confirming Davide