Announcement Announcement Module
Collapse
No announcement yet.
Velocity OutOfMemoryError during UnitTests Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Velocity OutOfMemoryError during UnitTests

    I'm using Velocity for email templating. I followed Matt Raible's excellent how to on using Velocity with Spring ( http://www.theserverside.com/blogs/s...gVelocityEmail ). At the very end of the aritcle he notes that during unit test execution, Velocity is initialized a numer of times. I figured this was ok since I only had a few tests that concerned sending emails. What I think I'm finding is that Velocity gets initialized for a third of my tests (about 38 times for 110 tests)! I'm seeing this 38 times in the log:
    Code:
    2004-09-18 13:17:08,562 (org.apache.velocity.app.VelocityEngine) - Starting Jakarta Velocity v1.4
    2004-09-18 13:17:08,562 (org.apache.velocity.app.VelocityEngine) - RuntimeInstance initializing.
    2004-09-18 13:17:08,562 (org.apache.velocity.app.VelocityEngine) - Default Properties File: org\apache\velocity\runtime\defaults\velocity.properties
    2004-09-18 13:17:08,562 (org.apache.velocity.app.VelocityEngine) - Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
    2004-09-18 13:17:08,562 (org.apache.velocity.app.VelocityEngine) - Resource Loader Instantiated: org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
    2004-09-18 13:17:08,562 (org.apache.velocity.app.VelocityEngine) - ClasspathResourceLoader : initialization starting.
    2004-09-18 13:17:08,562 (org.apache.velocity.app.VelocityEngine) - ClasspathResourceLoader : initialization complete.
    2004-09-18 13:17:08,562 (org.apache.velocity.app.VelocityEngine) - ResourceCache : initialized. (class org.apache.velocity.runtime.resource.ResourceCacheImpl)
    2004-09-18 13:17:08,562 (org.apache.velocity.app.VelocityEngine) - Default ResourceManager initialization complete.
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Loaded System Directive: org.apache.velocity.runtime.directive.Literal
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Loaded System Directive: org.apache.velocity.runtime.directive.Macro
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Loaded System Directive: org.apache.velocity.runtime.directive.Parse
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Loaded System Directive: org.apache.velocity.runtime.directive.Include
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Created: 20 parsers.
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocimacro : initialization starting.
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocimacro : adding VMs from VM library template : VM_global_library.vm
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - ResourceManager : unable to find resource 'VM_global_library.vm' in any resource loader.
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocimacro : error using  VM library template VM_global_library.vm : org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'VM_global_library.vm'
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocimacro :  VM library template macro registration complete.
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocimacro : allowInline = true : VMs can be defined inline in templates
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocimacro : allowInlineLocal = false : VMs defined inline will be  global in scope if allowed.
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocimacro : messages on  : VM system will output logging messages
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocimacro : autoload off  : VM system will not automatically reload global library macros
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocimacro : initialization complete.
    2004-09-18 13:17:08,578 (org.apache.velocity.app.VelocityEngine) - Velocity successfully started.
    More troubling is that tests are running out of memory, presumably because of initializing so much:

    Code:
    There were 3 errors:
         [java] 1) testRegistrationOk(com.service.UserServiceTest)org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceTarget' defined in class path resource [applicationContext.xml]: Can't resolve reference to bean 'velocityEngine' while setting property 'velocityEngine'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'velocityEngine' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: null
         [java] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'velocityEngine' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: null
         [java] java.lang.OutOfMemoryError
         [java] 2) testRetrieveCustomer(com.servlet.MobileRequestServletTest)org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceTarget' defined in class path resource [applicationContext.xml]: Can't resolve reference to bean 'velocityEngine' while setting property 'velocityEngine'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'velocityEngine' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: null
         [java] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'velocityEngine' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: null
         [java] java.lang.OutOfMemoryError
         [java] 3) testRetrieveCustomerSomeValsNull(com.servlet.MobileRequestServletTest)org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceTarget' defined in class path resource [applicationContext.xml]: Can't resolve reference to bean 'velocityEngine' while setting property 'velocityEngine'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'velocityEngine' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: null
         [java] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'velocityEngine' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: null
         [java] java.lang.OutOfMemoryError
         [java] FAILURES!!!
         [java] Tests run: 119,  Failures: 0,  Errors: 3
    Does anyone know of a way to configure Spring/Velocity so that is doesn't initialize so much? Will this affect runtime behavior or is this only an artifact of unit tests? I'm a newbie Velocity user so maybe that could be the problem too..

    Thanks,
    Andres

  • #2
    Silly me!

    I was creating a new instance of ClassPathXmlApplicationContext in the setup of most of my tests. I made the context a static variable in the super class of my tests, thus its only created once.

    Comment


    • #3
      I am receiving same error, but I am not even using Velocity. I also made my context static in my base Test, but I still receive the error while fetching some rows from database.

      My context looks like:

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN/EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd" >
      <beans>
      
      
      	
      	<!-- DataSource Definition -->
      	<bean id="mydataSource"
            	class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      		<property name="driverClassName">
      			<value>com.mysql.jdbc.Driver</value>
      		</property>
      		<property name="url">
      			<value>jdbc&#58;mysql&#58;//jgarcia&#58;3306/seguridad</value>
      		</property>
      		<property name="username">
      			<value>root</value>
      		</property>
      		<property name="password">
      			<value>root</value>
      		</property>
      	</bean>
      	
      	<!-- Spring Data Access Exception Translator Defintion -->
      	<bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator"> 
      		<property name="dataSource"><ref bean="mydataSource"/></property> 
      	</bean> 
       
      	<!-- Hibernate SessionFactory Definition -->
      	<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
      		<property name="mappingResources">
      			    <list>
      				<value>co/com/unionsoluciones/seguridad/modelo/bo/Usuario.hbm.xml</value>	
      				<value>co/com/unionsoluciones/seguridad/modelo/bo/Url.hbm.xml</value>	
      				<value>co/com/unionsoluciones/seguridad/modelo/bo/Rol.hbm.xml</value>	
      				</list>
      		</property>	
      		<property name="hibernateProperties">
      			<props>
      				<prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
      				<prop key="hibernate.show_sql">true</prop>
      				<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
      				<prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</prop>
      			</props>
      		</property>	
      		
      		<property name="dataSource">
      			<ref bean="mydataSource"/>
      		</property>
      	</bean>
      	
      		<!-- Hibernate Transaction Manager Definition -->
      	<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
      		<property name="sessionFactory"><ref local="sessionFactory"/></property>
      	</bean>
       
       
          <!-- Hibernate Template Defintion -->
      	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate.HibernateTemplate"> 
      		<property name="sessionFactory"><ref bean="sessionFactory"/></property> 
      		<property name="jdbcExceptionTranslator"><ref bean="jdbcExceptionTranslator"/></property> 
      	</bean> 	
      
      	<!-- DAO's -->
      	<bean id="rolDao" class="co.com.unionsoluciones.seguridad.modelo.dao.hibernate.RolDaoHibernateImpl">
      	<property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property> 
      	</bean>
      	
      	<bean id="urlDao" class="co.com.unionsoluciones.seguridad.modelo.dao.hibernate.UrlDaoHibernateImpl">
      	<property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property> 
      	</bean>
      	
      	<bean id="usuarioDao" class="co.com.unionsoluciones.seguridad.modelo.dao.hibernate.UsuarioDaoHibernateImpl">
      	<property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property> 
      	</bean> 
      	
      	
      	<!--<bean id="memoryAuthenticationDao" class="net.sf.acegisecurity.providers.dao.memory.InMemoryDaoImpl">
      	    <property name="userMap">
      	        <value>
      	            user=pass,ROLE_USER,ROLE_SUPERVISOR
      	            user1=pass,ROLE_USER
      	            user2=pass,ROLE_USER
      	        </value>
      	    </property>
      	</bean>-->
      	
      	<bean id="unionAuthenticationDao" class="co.com.unionsoluciones.seguridad.modelo.dao.UnionAthenticationDao">
      	     <property name="usuarioDao">
      	         <ref local="usuarioDao"/>
      	     </property>
      	</bean>
      	
      	
      	<bean id="daoAuthenticationProvider" class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider">
      	     <property name="authenticationDao">
      	         <ref local="unionAuthenticationDao"/>
      	     </property>
      	</bean>
      	
      	<bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderManager">
      	    <property name="providers">
      	        <list>
      	            <ref bean="daoAuthenticationProvider"/>
      	        </list>
      	    </property>
      	</bean>
      	
      	<bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
      	    <property name="authenticationManager">
      	        <ref bean="authenticationManager"/>
      	    </property>
      	    <property name="authenticationFailureUrl">
      	        <value>/login.jsp?error=1</value>
      	    </property>
      	    <property  name="defaultTargetUrl">
      	        <value>/</value>
      	    </property>
      	    <property name="filterProcessesUrl">
      	        <value>/j_acegi_security_check</value>
      	    </property>
      	</bean>
      	
      	<bean id="roleVoter" class="net.sf.acegisecurity.vote.RoleVoter"/>
      
      	<bean id="accessDecisionManager" class="net.sf.acegisecurity.vote.UnanimousBased">
      	    <property name="allowIfAllAbstainDecisions">
      	        <value>false</value>
      	    </property>
      	    <property name="decisionVoters">
      	        <list>
      	           <ref local="roleVoter"/>
      	        </list>
      	    </property>
      	</bean>
      
      	<bean id="securityEnforcementFilter" class="net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter">
      	    <property name="filterSecurityInterceptor">
      	        <ref bean="filterInvocationInterceptor"/>
      	    </property>
      	    <property name="authenticationEntryPoint">
      	        <ref bean="authenticationEntryPoint"/>
      	    </property>
      	</bean>
      
      	<bean id="httpSessionIntegrationFilter" class="net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter">
      	<property name="context"><value>net.sf.acegisecurity.context.security.SecureContextImpl</value></property>
      	</bean>
      	
      	<bean id="authenticationEntryPoint" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
      	    <property name="loginFormUrl">
      	        <value>/login.jsp</value>
      	    </property>
      	</bean>
      	
      	<bean id="filterInvocationInterceptor" class="net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor">
      	    <property name="authenticationManager">
      	        <ref bean="authenticationManager"/></property>
      	    <property name="accessDecisionManager">
      	        <ref bean="accessDecisionManager"/></property>
      	    <property name="objectDefinitionSource">
              <value>
                  CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
                 PATTERN_TYPE_APACHE_ANT
                  /secure/super/**=ROLE_SUPERVISOR
                  /secure/**=ROLE_USER,ROLE_SUPERVISOR
              </value>
      	    </property>
      	</bean>
      	
      	
      
          <bean id="objectDefinitionSource" class="co.com.unionsoluciones.seguridad.modelo.bo.PathBasedFilterInvocationDefinitionMapUnion" init-method="init">
      	<property name="urlDao">
      		<ref local="urlDao"/>
      	</property>
      	<property name="initExecutor">
      		<ref local="initExecutor"/> 
      	</property>
      	</bean>
      	
      	  
      	<bean id="initExecutorTarget" class="co.com.unionsoluciones.seguridad.modelo.bo.utils.InitExcecutor">
      	<property name="urlDao"> 
      		<ref local="urlDao"/>
      	</property>
      	<property name="mapUnion">
      		<ref local="objectDefinitionSource"/>
      	</property>
      	
      	</bean>
      	  
      	  
      	  <!-- Bean initExecutorProxy Proxy -->
      	<bean id="initExecutor" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      		<property name="transactionManager"><ref local="transactionManager"/></property>
      		<property name="target"><ref local="initExecutorTarget"/></property>
      		<property name="transactionAttributes">
      		<props>
      		<prop key="init*">PROPAGATION_REQUIRED, -Exception</prop>
      		</props>
      		</property>
      	</bean>
      	  
      </beans>
      Any Ideas?......


      JULIAN

      Comment

      Working...
      X