3
votes

I have a Spark application for which I have many implemented tests. I run this test in SBT shell inside a docker container. I need to debug the application by connecting from Intellij, and even though it connects to the running instance of SBT shell, breakpoints are completely ignored.

I set fork/test to false.

Also used this cmd to launch SBT shell inside the container:

  • export SBT_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 -Xmx4G"

  • Followed by command: sbt.

It displays the message

Listening for transport dt_socket at address: 5005

SBT shell suspends until Intellij debugger connects to the specified port.

Now I go to Intellij Remote debugger and the debug console displays this message:

Connected to the target VM, address: 'localhost:5005', transport: 'socket'

Finally, SBT resumes and starts downloading dependencies.

When I run:

test:testOnly fully.qualified.class.name

And submit breakpoints, test cases are executed but all breakpoints are ignored.

I don't know what else to try! Please help!

1
It's possible the tests are starting additional JVM processes. In this case debugging the sbt process won't work, instead you need to connect the debugger to the process started by the test. - Justin Kaeser
Thanks Justin, I have set test/fork to false to avoid execution in a new JVM process. - Jorge Cespedes
That only disables sbt forking processes, but it's possible the tests themselves start additional processes. You'd have to check if that is the case for your tests specifically. - Justin Kaeser
Tests do not start additional processes. Check my answer. - Jorge Cespedes

1 Answers

1
votes

Besides setting test/fork to false, fork in general should also be set to false. This includes running, building, etc.

Also, make sure that the suspend flag in SBT_OPTS is set to yes, so that it waits until Intellij Remote Debugger connects to it to execute tests.

That's it, that's how I got breakpoints to work when running from docker.