簡體   English   中英

OutOfMemoryError:嘗試使用HSQLDB,DBUnit,unitils,Hibernate,Spring優化Maven多模塊單元測試

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

我有一個包含數千個測試的大型多模塊Maven項目。 每個測試都使用SpringApplicationContext批注加載DAO,服務等。 我的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

我的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

當我運行測試時,分配給堆的2GB最終會填滿。 Permgen達到約400MB。 從堆轉儲來看, charjava.lang.Stringjava.lang.String []約占實例總數的40%。

當我抽查其中一些實例時,GC根源可以追溯到:

  • Spring上下文管理器(以上下文XML提取的形式)
  • SessionFactory(以查詢的形式)

我想優化這兩個方面,我認為它們分別是由於:

  • 每個測試都有一個@SpringApplicationContext批注
  • 每個測試還使用unitils @DataSet批注為該測試加載數據。

注意,我使用jdbc:hsqldb:file卸載堆中的某些數據(即,而不是使用jdbc:hsqldb:mem)

版本:
hsqldb 1.8.0.7
春季3.0.4。發布
unitils 3.1

PS可以有人用1500+等級,請與標簽“unitils”這個問題?

如果內存是由數據庫中存儲的數據占用的,則可以使數據庫使用基於磁盤的表來減少內存使用。 可以在數據庫URL上指定:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM