【发布时间】:2016-02-25 09:52:26
【问题描述】:
我们使用org.codehaus.btm:btm:2.1.4 进行测试,我们看到这些文件出现在我们的 maven 模块目录(即工作目录)中:
btm1.tlogbtm2.tlog
我希望在另一个目录中创建它们,例如在 target/btmlogs/ 中。我该如何配置 BTM 来做到这一点?
【问题讨论】:
我们使用org.codehaus.btm:btm:2.1.4 进行测试,我们看到这些文件出现在我们的 maven 模块目录(即工作目录)中:
btm1.tlogbtm2.tlog我希望在另一个目录中创建它们,例如在 target/btmlogs/ 中。我该如何配置 BTM 来做到这一点?
【问题讨论】:
您必须配置 TransactionManager。 Relevant part of the configuration
在名为src/main/resources/bitronix-default-config.properties 的文件中执行此操作。像这样的:
# Avoid warnings in test log
bitronix.tm.serverId=foo-bar
# Disable tlog files
bitronix.tm.journal=null
# In case the journal is enabled locally, avoid that the btm1.tlog and btm2.tlog files are created in the module's directory
# causing gitignore, mvn clean and IDE indexing issues
bitronix.tm.journal.disk.logPart1Filename=target/btm/btm1.tlog
bitronix.tm.journal.disk.logPart2Filename=target/btm/btm2.tlog
【讨论】:
poolingDataSource.getDriverProperties().setProperty("bitronix.tm.journal.disk.logPart1Filename", "target/btm/my-btm1.tlog"); 导致bitronix.tm.utils.PropertyException: no readable property 'bitronix' in class 'bitronix.tm.resource.jdbc.lrc.LrcXADataSource'
TransactionManagerServices.getConfiguration(),会导致IllegalStateException: cannot change the configuration while the transaction manager is running。在静态构造函数中而不是在每个 JUnit 测试开始时执行它们会使除第一个测试之外的所有测试都写入错误的目录(因此忽略该属性)。