Skip to content

drahkrub/concurrentFindOrCreateTests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Warning

The stuff I've done here (is used in production [shudder] but) is just "upper nonsense".

Unfortunatly I've found no time to fix it up to now!


Concurrent find-or-create tests in MySQL

See the comments below Vlad's answer to Find or insert based on unique key with Hibernate on Stack Overflow.

I tried the solution proposed by Vlad Mihalcea, but I think the "find part" is not really working this way.

  • to run the tests you have to create a database 'demo' with user 'demo' and password 'demo' (or alter src/test/resources/application.properties)

  • run all the tests (meanwhile there are three) with: mvn clean test (lot's of stuff is downloaded because spring-boot-starter-data-jpa etc. is used)

  • the tests testWithInsertOnDuplicateUpdate and testWithInsertIgnore should fail

  • the test testWithTableLock should succeed with some output similar to

    Fred: no bean found by findByName("dummy")
    Fred: lock table
          Marcey: no bean found by findByName("dummy")
          Marcey: lock table
      Pamela: no bean found by findByName("dummy")
  Alice: no bean found by findByName("dummy")
      Pamela: lock table
  Alice: lock table
    Fred: lock aquired
    Fred: no bean found by second findByName("dummy")
    Fred: bean created!
    Fred: unlock table
          Marcey: lock aquired
          Marcey: found bean by second findByName("dummy")
          Marcey: unlock table
      Pamela: lock aquired
      Pamela: found bean by second findByName("dummy")
      Pamela: unlock table
  Alice: lock aquired
  Alice: found bean by second findByName("dummy")
  Alice: unlock table
Bob: found bean by findByName("dummy")
        Harvey: found bean by findByName("dummy")

About

Find or insert based on unique key with Hibernate (in MySQL)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages