4

I would like to connect to an in-memory HSQL database instance using the hsql DatabaseManager (or the swing version, it doesn't matter) while debugging tests in my IDE (Intellij IDEA 11.1.2).

I have tried as was suggested by this answer, but every time I do so the DatabaseManager process/thread (I don't know which) starts and freezes once the debug breakpoint is hit. If kill/force quit it, the debug session also dies.

How can I do this without the DatabaseManager freezing?

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Paul D. Eden
  • 19,939
  • 18
  • 59
  • 63

3 Answers3

9

Your Spring/JUnit is starting the database in in-process mode.

Your options would be:

  1. Either starting hsqldb in server mode
  2. Or starting the DBmanager from your application
  3. Or make your breakpoint stop only the current thread, then your databasemanager will not freeze
Eugenio Cuevas
  • 10,858
  • 3
  • 29
  • 51
  • Thanks, but unfortunately Junit/Spring is starting up and loading with test data the hsqldb instance already and that seems to be working, so creating another instance of hsqldb wouldn't help me. I would like to look at the existing hsqldb instance to debug problems in the tests. – Paul D. Eden Jul 11 '12 at 15:35
  • 1
    Oh, yes... I totally misunderstood the question! Anyway, could your problem be Spring loading the database in [in-process mode](http://www.hsqldb.org/doc/1.8/guide/ch01.html#N101A8)? If so, you should change the spring config so it runs it on server mode – Eugenio Cuevas Jul 11 '12 at 15:47
  • I bet you are right, thanks! Maybe I can run DatabaseManager from one of my tests (at least temporarily while I am debugging)? Right now, I am using the Intellij Idea "Evaluate Expression" feature to start it and it's probably spawning a separate process/thread and can't connect due to the database being in in-process mode. – Paul D. Eden Jul 11 '12 at 16:16
  • I'll update the answer with the comment info. I would totally recomend starting it in server mode, that way you can access the data not only from dbmanager, but from any database explorer, like Squirrel, which is very convenient. However I don't use Intellij to know how is it starting the db – Eugenio Cuevas Jul 11 '12 at 16:36
4

Please also check if your breakpoint halts all threads. Most debuggers have a setting for this. You can change this setting for this breakpoint to only halt the JUnit test thread and not other threads. See also here:

Does a breakpoint halt all threads?

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
3

I think there are two answers to this question.

  1. The answer given by Eugenio Cuevas in his comment if you would like to start DatabaseManager in a separate process/thread from your tests.
  2. Adding the call to DatabaseManager.main() inside one of your tests if you are running in in-process mode. Make sure you pause execution (i.e., prompt for user input, or run Thread.sleep(Long.MAX_VALUE); right after the line where DatabaseManager.main() is called so that the test does not keep executing. See here for the code to start the DatabaseManager.
rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Paul D. Eden
  • 19,939
  • 18
  • 59
  • 63
  • I'm using unitils for unit testing. I'm able to run the manager, but it freezes on table, which is probably locked by the test. Other tables which are not used during the test I can see are empty. Any idea how to resolve this? – Zveratko Apr 18 '16 at 07:56
  • 1
    Faster then expected `DatabaseModule.Transactional.value.default=disabled` unitils configuration fixed this – Zveratko Apr 18 '16 at 07:57