سؤال

I am trying to integration-test the Gorm pessimistic lock, and simulating with multithreading the access from many servers simultaneously, but in each thread I don't get the results expected. This is my code:

@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

I can't figure out what's happening, I supposed my Hibernate sessionFactory is not bound to each thread, and that Domain.withTransaction I should work, but it didn't.

Any help?

هل كانت مفيدة؟

المحلول

It was related to the Set Up method of the integration test, where I bootstraped the data in memory. Once I move that to Bootstrap, the closures from threads could bind the hibernate sessions! Thanks anyways!!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top