0

I want to use h2 console for accessing the inmemory database while testing(test debugging). Tests run fine and the h2 database seems to do its job.

To enable the h2 console I followed this How to set H2 Database console url in the Quarkus Application.

Then the console is available when I run the application for normal development. its available under http://localhost:8082/h2/

But when running my tests (with RestAssured) the console is not available. I tried it with breakpoints that only are stopping the thread and also I tried setting a while(true) loop in one of the tests so the test would not finish and then I would try to access the console, but none of it worked.

Is there any additional settings that I need to do for accessing the h2 console when running tests?

in the application.yml I also have the following

"%test":
  quarkus:
    datasource:
      db-kind: h2
      jdbc:
        driver: org.h2.Driver
        url: jdbc:h2:mem:test

also I tried adding the META-INF folder with the web.xml not only under main/resources but also under test/resources. But I am not sure if that is something you would do?

Any idea how to access the h2 console for tests?

Maybe when running tests the servlets are not getting loaded? Or maybe it will run under a different port? I am not really sure what is the problem.

Maybe I need to add a code in the TestProfiles that loads the servlet explicitly? Any idea where and how to that?

user1664377
  • 393
  • 1
  • 3
  • 13

1 Answers1

0

h2 console is working in same JVM, and it is using same servlet threads, it means if you put a break point in your rest service it will suspend all. Therefore h2 console will not be available while debugging.

You can try to run second spring boot application and use h2 console from there check https://stackoverflow.com/a/50039942/175554 and check Spring boot: can't login h2 console

Comment in blocks

I am wondering then why I cannot access the console even when I dont use a breakpoint but just set a while loop in the test. then nothing halts. but I cannot find h2 console anywhere.

@user1664377 Can you share a reproducer for this ?

A question also about "webAllowOthers: allow other computers to connect." it says that on the h2 console website. I am not sure what that means? Is that not a setting about remotely accessing the h2 console? What you say seems to be not to remotely access the h2 console but access the h2 console locally and just access a different process?

"run second spring boot" means running separate jvm and connecting from separate jvm requires remote access, I think it would be easier to use postgresql or mysql for testing.

ozkanpakdil
  • 3,199
  • 31
  • 48
  • I am wondering then why I cannot access the console even when I dont use a breakpoint but just set a while loop in the test. then nothing halts. but I cannot find h2 console anywhere. A question also about "webAllowOthers: allow other computers to connect." it says that on the h2 console website. I am not sure what that means? Is that not a setting about remotely accessing the h2 console? What you say seems to be not to remotely access the h2 console but access the h2 console locally and just access a different process? – user1664377 Apr 20 '23 at 08:48
  • @user1664377 have you seen my answers ? – ozkanpakdil Apr 24 '23 at 19:14