Derby
  1. Derby
  2. DERBY-5819

Add logic to BaseTestCase to start subprocesses ready to be attached to from a Java debugger

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 10.10.1.1
    • Component/s: Test
    • Labels:
      None

      Description

      Sometimes it's useful to be able to attach to subprocesses of tests with a debugger.
      Now that we have centralized subprocess creation in BaseTestCase#execJavaCmd it would be easy and useful to have subprocesses start, but wait for a debugger to attach to them, i.e. with these options on an Oracle VM:

      -Xdebug -Xrunjdwp:transport=dt_socket,address=<port>,server=y,suspend=y

      1. derby-5819.diff
        1 kB
        Dag H. Wanvik
      2. derby-5819b.diff
        2 kB
        Dag H. Wanvik
      3. derby-5819c.diff
        2 kB
        Dag H. Wanvik
      4. derby-5819d.diff
        2 kB
        Dag H. Wanvik

        Activity

        Hide
        Dag H. Wanvik added a comment -

        Closing. If needed this patch could be backported.

        Show
        Dag H. Wanvik added a comment - Closing. If needed this patch could be backported.
        Hide
        Dag H. Wanvik added a comment -

        Committed version d as svn 1356457. Commit log:

        Adds options to allow this capability for Oracle Java (properties below
        ignored for other implementations):

        derby.test.debugPortBase=<int> default 8800
        derby.test.debugSubProcesses=<boolean> default false
        derby.test.debugSuspend=<y|n> default 'y'

        If several subprocesses are created, the port for subprocess two will be
        debugPortBase + 1 (i.e. 8801 by default) etc.

        Show
        Dag H. Wanvik added a comment - Committed version d as svn 1356457. Commit log: Adds options to allow this capability for Oracle Java (properties below ignored for other implementations): derby.test.debugPortBase=<int> default 8800 derby.test.debugSubProcesses=<boolean> default false derby.test.debugSuspend=<y|n> default 'y' If several subprocesses are created, the port for subprocess two will be debugPortBase + 1 (i.e. 8801 by default) etc.
        Hide
        Dag H. Wanvik added a comment -

        Added an other option to control the way the subprocesses are started:

        derby.test.debugSuspend=<y|n> default 'y'

        Unless this property is 'n', the subprocess will hang till the debugger is connected, cf the explanation here:
        http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/conninv.html#Invocation

        Show
        Dag H. Wanvik added a comment - Added an other option to control the way the subprocesses are started: derby.test.debugSuspend=<y|n> default 'y' Unless this property is 'n', the subprocess will hang till the debugger is connected, cf the explanation here: http://docs.oracle.com/javase/1.5.0/docs/guide/jpda/conninv.html#Invocation
        Hide
        Dag H. Wanvik added a comment -

        Uploading a new version of this patch which changes the properties to

        derby.test.debugPortBase=<int> default 8800
        derby.test.debugSubProcesses=<boolean> default false

        Show
        Dag H. Wanvik added a comment - Uploading a new version of this patch which changes the properties to derby.test.debugPortBase=<int> default 8800 derby.test.debugSubProcesses=<boolean> default false
        Hide
        Dag H. Wanvik added a comment -

        Thanks, Knut. Indeed it would fail, sorry, I uploaded wrong version of the patch.

        Show
        Dag H. Wanvik added a comment - Thanks, Knut. Indeed it would fail, sorry, I uploaded wrong version of the patch.
        Hide
        Knut Anders Hatlen added a comment -

        This sounds like useful functionality. A couple of comments:

        • Maybe the properties should be prefixed with "derby.test." for consistency with the other test properties.
        • Won't this check fail with a NullPointerException if the debugSubprocesses property is not set?

        + if (isSunJVM() && "true".equals(
        + getSystemProperty("debugSubprocesses").toLowerCase())) {

        (Btw, Boolean.valueOf(String) would save you the trouble of normalizing/lowercasing the value, and it also handles null.)

        Show
        Knut Anders Hatlen added a comment - This sounds like useful functionality. A couple of comments: Maybe the properties should be prefixed with "derby.test." for consistency with the other test properties. Won't this check fail with a NullPointerException if the debugSubprocesses property is not set? + if (isSunJVM() && "true".equals( + getSystemProperty("debugSubprocesses").toLowerCase())) { (Btw, Boolean.valueOf(String) would save you the trouble of normalizing/lowercasing the value, and it also handles null.)
        Hide
        Dag H. Wanvik added a comment -

        Attached version "b" of this patch. For now, it limits this to Sun VMs. Added another property, "debugPortBase=<int>", but the default is still 8800. Refactored the code to a private method in BasetestCase: setupForDebuggerAttach.

        Summary of properties as the patch stands:

        debugPortBase=<int> default 8800
        debugSubProcesses=<boolean> default false

        Show
        Dag H. Wanvik added a comment - Attached version "b" of this patch. For now, it limits this to Sun VMs. Added another property, "debugPortBase=<int>", but the default is still 8800. Refactored the code to a private method in BasetestCase: setupForDebuggerAttach. Summary of properties as the patch stands: debugPortBase=<int> default 8800 debugSubProcesses=<boolean> default false
        Hide
        Dag H. Wanvik added a comment -

        Here is a crude patch which basically creates debug ports on all started subprocesses from 8800 and upward iff this setting applies in the parent VM:

        -DdebugSubprocesses=true

        We could parameterize the port offset, and the value for "suspend=?". Defaults could be 8800 and 'y' though. This method probably only applies to Oracle VMs, too, so the code should check for that, I guess.

        Show
        Dag H. Wanvik added a comment - Here is a crude patch which basically creates debug ports on all started subprocesses from 8800 and upward iff this setting applies in the parent VM: -DdebugSubprocesses=true We could parameterize the port offset, and the value for "suspend=?". Defaults could be 8800 and 'y' though. This method probably only applies to Oracle VMs, too, so the code should check for that, I guess.

          People

          • Assignee:
            Dag H. Wanvik
            Reporter:
            Dag H. Wanvik
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development