我正在尝试集成测试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我应该工作,但它没有。
有什么帮助吗?
发布于 2012-09-14 20:48:13
这与集成测试的设置方法有关,在该方法中,我将数据引导到内存中。一旦我把它移到Bootstrap,线程的闭包就可以绑定hibernate会话!无论如何,谢谢!!
https://stackoverflow.com/questions/12377140
复制相似问题