GORM GPARS集成测试

时间:2012-09-11 20:08:51

标签: hibernate grails gorm grails-2.0 gpars

我正在尝试集成测试Gorm悲观锁,并使用多线程模拟同时从多个服务器访问,但在每个线程中我都没有得到预期的结果。这是我的代码:

@Test
void testLockInBetweenCheck() {
def tid = IdocTidInfo.findByTid("AC10870D0E12504F3E88D575") //here tid is not null
withPool{
      [1,2].eachParallel{ tids ->
     IdocTidInfo.withTransaction{ tid ->
        def t = IdocTidInfo.findByTid("AC10870D0E12504F3E88D575") // here is t is null

我无法弄清楚发生了什么,我认为我的Hibernate sessionFactory没有绑定到每个线程,并且我应该使用Domain.withTransaction,但它没有。

任何帮助?

1 个答案:

答案 0 :(得分:2)

它与集成测试的Set Up方法有关,我将数据引导到内存中。一旦我将它移动到Bootstrap,线程的闭包可以绑定hibernate会话!非常感谢!!