19

I'm trying to access the H2-Console during a WebIntegrationTest in debug mode. However, I noticed that Spring Boot is blocking the H2-console when I'm debugging the test. It seems as soon as a breakpoint is reached, the H2-console is blocked as well. I'm working with Spring Boot 1.3.1.RELEASE.

Each breakpoint in the following test causes to block the H2-console. In breakpoint 1, the login page appears. I then press to login button but nothing happens until I let continue the test to the next breakpoint. In breakpoint 2, I'm logged in and can execute a query. But only when I'm going to the next breakpoint, the query results appear.

@Test
public void whenGetById_thenCorrectId() throws InterruptedException {
    // do some stuff
    // breakpoint 1
    Thread.sleep(1000);
    // breakpoint 2
    Thread.sleep(1000);
    // breakpoint 3
}

The WebIntegrationTest ist configured as follows:

@ActiveProfiles("local,unittest")
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = MyApplication.class)
@WebIntegrationTest({"spring.h2.console.enabled=true", "server.port=8080"})
public class MyResourceTest {

How can I decouple the H2-in-memory DB from the debug mode?

René Winkler
  • 6,508
  • 7
  • 42
  • 69
  • Well, what you essentially do with a breakpoint is to stop the application, until you continue the run manually. So there is no way to circumvent this except not using breakpoints. You could use one of the other storage methods for H2 (like using a file or server-mode) and then connect a separate web console instance to that. – dunni Feb 03 '16 at 14:59
  • 1
    It sounds like you have the breakpoint configured to suspend the whole JVM rather than just a single thread. – Andy Wilkinson Feb 03 '16 at 20:07
  • @René Winkler See this answer : http://stackoverflow.com/questions/12390116/access-to-h2-web-console-while-running-junit-test-in-a-spring-application – Jesus Zavarce Feb 03 '16 at 20:17

1 Answers1

36

Breakpoint can be configured to suspend the whole VM or only a single thread. In IntelliJ you can set this via right-click on the respective breakpoint. My breakpoints were configured to suspend the whole VM and so each breakpoint also blocked to access the H2-Console.

enter image description here

René Winkler
  • 6,508
  • 7
  • 42
  • 69
  • Thnx! I'm stuck on this issue for almost two days now. I feed like an idiot :) – MrA Mar 30 '20 at 09:39
  • And notice the "Make Default" button, that will unhide if you switch the radio button... jetbrains, why do you hide and scatter options around the IDE? This setting should be available in the global Debugger settings. – leo Jun 17 '20 at 07:57
  • wow, amazing option – Gondri Jun 14 '23 at 10:23