简体   繁体   English

OutOfMemoryError:尝试使用HSQLDB,DBUnit,unitils,Hibernate,Spring优化Maven多模块单元测试

[英]OutOfMemoryError: Trying to optimise Maven multi-module unit tests using HSQLDB, DBUnit, unitils, Hibernate, Spring

I have a big multi-module Maven project with thousands of tests. 我有一个包含数千个测试的大型多模块Maven项目。 Each test loads DAOs, services, etc using the SpringApplicationContext annotation. 每个测试都使用SpringApplicationContext批注加载DAO,服务等。 My unitils configuration looks like this: 我的unitils配置如下所示:

database.driverClassName=org.hsqldb.jdbcDriver
database.url=jdbc:hsqldb:file:mytestdb
database.schemaNames=PUBLIC
database.userName=sa
database.password=
database.dialect=hsqldb
unitils.modules=database,dbunit,hibernate,inject,spring
# custom version of HsqldbDbSupport which calls "SET REFERENTIAL_INTEGRITY FALSE"
org.unitils.core.dbsupport.DbSupport.implClassName.hsqldb=my.company.unitils.HsqldbDbSupport
org.dbunit.dataset.datatype.IDataTypeFactory.implClassName.hsqldb=org.dbunit.ext.hsqldb.HsqldbDataTypeFactory
org.unitils.dbmaintainer.structure.ConstraintsDisabler.implClassName=org.unitils.dbmaintainer.structure.impl.DefaultConstraintsDisabler
# custom version of CleanInsertLoadStrategy which calls "DatabaseUnitils.disableConstraints();"
DbUnitModule.DataSet.loadStrategy.default=my.company.unitils.DataSetLoadStrategy
HibernateModule.configuration.implClassName=org.hibernate.cfg.AnnotationConfiguration
dbMaintainer.disableConstraints.enabled=true
dbMaintainer.cleanDb.enabled=true
dbMaintainer.generateDataSetStructure.enabled=false
dataSetStructureGenerator.xsd.dirName=target/xsd
dbMaintainer.autoCreateExecutedScriptsTable=true
updateDataBaseSchema.enabled=false
dbMaintainer.fromScratchEnabled=true

My Hibernate configuration looks like this: 我的Hibernate配置如下所示:

hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.connection.autocommit=false
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.cache.use_query_cache=false
hibernate.cache.use_second_level_cache=false
hibernate.cache.use_structured_entries=false
hibernate.generate_statistics=false

When I run the tests, the 2GB allocated for heap eventually fills up. 当我运行测试时,分配给堆的2GB最终会填满。 Permgen reaches about 400MB. Permgen达到约400MB。 Looking at the heap dump, char , java.lang.String and java.lang.String[] takes up about 40% of the total instances. 从堆转储来看, charjava.lang.Stringjava.lang.String []约占实例总数的40%。

When I spot-check a few of these instances, the GC root traces back to: 当我抽查其中一些实例时,GC根源可以追溯到:

  • the Spring context manager (in the form of context XML extracts) Spring上下文管理器(以上下文XML提取的形式)
  • the SessionFactory (in the form of queries) SessionFactory(以查询的形式)

I would like to optimise these 2 things, and I think they are respectively caused by: 我想优化这两个方面,我认为它们分别是由于:

  • Each test has a @SpringApplicationContext annotation 每个测试都有一个@SpringApplicationContext批注
  • Each test also uses the unitils @DataSet annotation to load up data for that test. 每个测试还使用unitils @DataSet批注为该测试加载数据。

Note, I use jdbc:hsqldb:file to offload some data off of the heap (ie instead of using jdbc:hsqldb:mem) 注意,我使用jdbc:hsqldb:file卸载堆中的某些数据(即,而不是使用jdbc:hsqldb:mem)

Versions: 版本:
hsqldb 1.8.0.7 hsqldb 1.8.0.7
Spring 3.0.4.RELEASE 春季3.0.4。发布
unitils 3.1 unitils 3.1

PS can someone with a 1500+ rating please tag this question with "unitils"? PS可以有人用1500+等级,请与标签“unitils”这个问题?

If the memory is taken by the data stored in the database, you can make the database use disk based tables to reduce memory use. 如果内存是由数据库中存储的数据占用的,则可以使数据库使用基于磁盘的表来减少内存使用。 This can be specified on the database URL: 可以在数据库URL上指定:

database.url=jdbc:hsqldb:file:mytestdb;hsqldb.default_table_type=cached database.url = jdbc:hsqldb:file:mytestdb; hsqldb.default_table_type = cached

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring boot application.properties maven 多模块项目 - Spring boot application.properties maven multi-module projects 用于maven多模块的Spring Hibernate配置 - Spring Hibernate configuration for maven multi module 无法进行单元测试-Unitils,休眠 - Unable to unit test - Unitils, Hibernate Maven 多模块依赖编译问题 - Maven Multi-Module Dependency Compile Problem 在使用spring,maven和hibernate时,启动HSQLDB进行单元测试的最佳方法是什么? - What is the best way to launch HSQLDB for unit testing, when working with spring, maven and hibernate? 使用Spring 3.1,Hibernate 4.1,Dbunit等提高数据库测试的性能 - Improving performance of database tests using Spring 3.1, Hibernate 4.1, Dbunit, etc HSQLDB上具有Spring DBUnit的Hibernate和Spring数据-由于外键约束,无法删除 - Hibernate and Spring Data with Spring DBUnit on HSQLDB - Unable to delete due to foreign key constraint 使用JPA 2.0,Spring 2.5.6,Hibernate 3.6.1和Maven无法在HSQLDB中持久存在 - Cannot persist in HSQLDB using JPA 2.0, Spring 2.5.6, Hibernate 3.6.1 and Maven 基于Hibernate的代码在hsqldb 1.8.1.3之上的单元测试不再适用于hsqldb 2.2.9 - Unit tests of Hibernate based code on top of hsqldb 1.8.1.3 no longer work on hsqldb 2.2.9 多模块项目中的Hibernate Java 8时间类型支持 - Hibernate Java 8 time types support in multi-module project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM