Hadoop Common
  1. Hadoop Common
  2. HADOOP-5386

To Probe free ports dynamically for Unit test to replace fixed ports

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.21.0
    • Fix Version/s: 0.21.0
    • Component/s: None
    • Labels:
      None
    • Hadoop Flags:
      Reviewed

      Description

      Currently hdfsproxy unit test uses Cactus in-container test. It uses three fixed ports. one for tomcat start-up/shut-down, another for tomcat http-port and the third for tomcat https-port.
      If theses ports are already in use, ant build will fail. To fix this, we decided to use a java program to probe the free ports dynamically and update the tomcat conf with these free ports.

      1. HADOOP-5386.patch
        8 kB
        zhiyong zhang
      2. HADOOP-5386.patch
        16 kB
        zhiyong zhang
      3. HADOOP-5386.patch
        18 kB
        zhiyong zhang
      4. HADOOP-5386.patch
        18 kB
        zhiyong zhang

        Activity

        Hide
        Hudson added a comment -
        Show
        Hudson added a comment - Integrated in Hadoop-trunk #778 (See http://hudson.zones.apache.org/hudson/job/Hadoop-trunk/778/ )
        Hide
        Chris Douglas added a comment -

        I committed this. Thanks, Zhiyong

        Show
        Chris Douglas added a comment - I committed this. Thanks, Zhiyong
        Hide
        zhiyong zhang added a comment -

        Addressed in-compatible javac and java version problem with ant "exec" task.
        [echo] Free Ports: startup-Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
        [echo] at java.lang.ClassLoader.defineClass1(Native Method)
        [echo] at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        [echo] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        [echo] at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        [echo] at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        [echo] at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        [echo] at java.security.AccessController.doPrivileged(Native Method)
        [echo] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        [echo] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        [echo] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        [echo] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        [echo] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) / http-Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file

        Now use $

        {env.JAVA_HOME}

        /bin/java instead of java.

        Show
        zhiyong zhang added a comment - Addressed in-compatible javac and java version problem with ant "exec" task. [echo] Free Ports: startup-Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file [echo] at java.lang.ClassLoader.defineClass1(Native Method) [echo] at java.lang.ClassLoader.defineClass(ClassLoader.java:620) [echo] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) [echo] at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) [echo] at java.net.URLClassLoader.access$100(URLClassLoader.java:56) [echo] at java.net.URLClassLoader$1.run(URLClassLoader.java:195) [echo] at java.security.AccessController.doPrivileged(Native Method) [echo] at java.net.URLClassLoader.findClass(URLClassLoader.java:188) [echo] at java.lang.ClassLoader.loadClass(ClassLoader.java:306) [echo] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268) [echo] at java.lang.ClassLoader.loadClass(ClassLoader.java:251) [echo] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) / http-Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file Now use $ {env.JAVA_HOME} /bin/java instead of java.
        Hide
        zhiyong zhang added a comment -

        Added clover coverage test support.

        Show
        zhiyong zhang added a comment - Added clover coverage test support.
        Hide
        Hadoop QA added a comment -

        -1 overall. Here are the results of testing the latest attachment
        http://issues.apache.org/jira/secure/attachment/12401500/HADOOP-5386.patch
        against trunk revision 751463.

        +1 @author. The patch does not contain any @author tags.

        +1 tests included. The patch appears to include 19 new or modified tests.

        +1 javadoc. The javadoc tool did not generate any warning messages.

        +1 javac. The applied patch does not increase the total number of javac compiler warnings.

        +1 findbugs. The patch does not introduce any new Findbugs warnings.

        +1 Eclipse classpath. The patch retains Eclipse classpath integrity.

        +1 release audit. The applied patch does not increase the total number of release audit warnings.

        -1 core tests. The patch failed core unit tests.

        -1 contrib tests. The patch failed contrib unit tests.

        Test results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch-vesta.apache.org/57/testReport/
        Findbugs warnings: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch-vesta.apache.org/57/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
        Checkstyle results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch-vesta.apache.org/57/artifact/trunk/build/test/checkstyle-errors.html
        Console output: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch-vesta.apache.org/57/console

        This message is automatically generated.

        Show
        Hadoop QA added a comment - -1 overall. Here are the results of testing the latest attachment http://issues.apache.org/jira/secure/attachment/12401500/HADOOP-5386.patch against trunk revision 751463. +1 @author. The patch does not contain any @author tags. +1 tests included. The patch appears to include 19 new or modified tests. +1 javadoc. The javadoc tool did not generate any warning messages. +1 javac. The applied patch does not increase the total number of javac compiler warnings. +1 findbugs. The patch does not introduce any new Findbugs warnings. +1 Eclipse classpath. The patch retains Eclipse classpath integrity. +1 release audit. The applied patch does not increase the total number of release audit warnings. -1 core tests. The patch failed core unit tests. -1 contrib tests. The patch failed contrib unit tests. Test results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch-vesta.apache.org/57/testReport/ Findbugs warnings: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch-vesta.apache.org/57/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html Checkstyle results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch-vesta.apache.org/57/artifact/trunk/build/test/checkstyle-errors.html Console output: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch-vesta.apache.org/57/console This message is automatically generated.
        Hide
        Chris Douglas added a comment -

        +1

        (assuming Hudson comes back without complaint)

        Show
        Chris Douglas added a comment - +1 (assuming Hudson comes back without complaint)
        Hide
        Chris Douglas added a comment -

        Thanks for addressing all the open issues. All the unit tests pass on fresh checkouts. I'm still seeing the prenominate failure in one dev environment, but cannot discern its cause. I doubt that it will be a problem in general.

        I changed to use ant copy plus token filter. should be more elegant than sed.

        This is a sound improvement. The current strategy of testing for open ports should stop Hudson from failing.

        I explored quite a few time on that. Unfortunately I don't think ant can continue run build if some part fails. Unless we want to return success even if it fails.

        I modified a Chukwa unit test to fail, and it looks like both projects have the same issue. I filed HADOOP-5434 to address this.

        Other than changing the port rolling to advance mod the MAX_AVAILABLE_PORT (so if it happens to start at or near that point, a single failure to bind won't fail the test), I think the current patch is fine and could go in as-is.

        +1

        Show
        Chris Douglas added a comment - Thanks for addressing all the open issues. All the unit tests pass on fresh checkouts. I'm still seeing the prenominate failure in one dev environment, but cannot discern its cause. I doubt that it will be a problem in general. I changed to use ant copy plus token filter. should be more elegant than sed. This is a sound improvement. The current strategy of testing for open ports should stop Hudson from failing. I explored quite a few time on that. Unfortunately I don't think ant can continue run build if some part fails. Unless we want to return success even if it fails. I modified a Chukwa unit test to fail, and it looks like both projects have the same issue. I filed HADOOP-5434 to address this. Other than changing the port rolling to advance mod the MAX_AVAILABLE_PORT (so if it happens to start at or near that point, a single failure to bind won't fail the test), I think the current patch is fine and could go in as-is. +1
        Hide
        zhiyong zhang added a comment -
        • As part of this patch, would it be possible to cut the test timeout from 3 minutes to 30 seconds at most?
          Yes done
        • Ideally, the proxy would start up on a random port instead of writing the config from ant, but OK. Since FindFreePort is used only in the unit tests, it should probably:
          o Move under hdfsproxy/test/...
          Yes done.
          o Write the whole config file instead of using sed in a later ant task
          I changed to use ant copy plus token filter. should be more elegant than sed.
          o Pick a random port instead of starting at a fixed port and rolling to find an open one
          Yes. I changed FindFreePort to select a random port to start with
        • ant -Dtestcase=TestHdfsProxy test fails reliably on my machine:
          Fixed, don't rely on HADOOP_CONF_DIR environment. should work fine now.
        • Note that hdfsproxy isn't the last project in test, but the failure stops the build. That should be fixed, either as part of this issue or in another one.
          I explored quite a few time on that. Unfortunately I don't think ant can continue run build if some part fails. Unless we want to return success even if it fails. It would be nice if ant is like gcc compiler, returning all the errors or failures after the full build. But ant can't do that (i think). If it is proven otherwise, please let me know.
        • When ant -Dtestcase=FOO test is run, this still starts tomcat.
          Fixed.
        Show
        zhiyong zhang added a comment - As part of this patch, would it be possible to cut the test timeout from 3 minutes to 30 seconds at most? Yes done Ideally, the proxy would start up on a random port instead of writing the config from ant, but OK. Since FindFreePort is used only in the unit tests, it should probably: o Move under hdfsproxy/test/... Yes done. o Write the whole config file instead of using sed in a later ant task I changed to use ant copy plus token filter. should be more elegant than sed. o Pick a random port instead of starting at a fixed port and rolling to find an open one Yes. I changed FindFreePort to select a random port to start with ant -Dtestcase=TestHdfsProxy test fails reliably on my machine: Fixed, don't rely on HADOOP_CONF_DIR environment. should work fine now. Note that hdfsproxy isn't the last project in test, but the failure stops the build. That should be fixed, either as part of this issue or in another one. I explored quite a few time on that. Unfortunately I don't think ant can continue run build if some part fails. Unless we want to return success even if it fails. It would be nice if ant is like gcc compiler, returning all the errors or failures after the full build. But ant can't do that (i think). If it is proven otherwise, please let me know. When ant -Dtestcase=FOO test is run, this still starts tomcat. Fixed.
        Hide
        Chris Douglas added a comment -

        Move under hdfsproxy/test/...

        Sorry, I meant hdfsproxy/src/test/...

        Show
        Chris Douglas added a comment - Move under hdfsproxy/test/... Sorry, I meant hdfsproxy/src/test/...
        Hide
        Chris Douglas added a comment -
        • As part of this patch, would it be possible to cut the test timeout from 3 minutes to 30 seconds at most?
        • Ideally, the proxy would start up on a random port instead of writing the config from ant, but OK. Since FindFreePort is used only in the unit tests, it should probably:
          • Move under hdfsproxy/test/...
          • Write the whole config file instead of using sed in a later ant task
          • Pick a random port instead of starting at a fixed port and rolling to find an open one
        • ant -Dtestcase=TestHdfsProxy test fails reliably on my machine:
          test:
               [echo]  Free Ports: startup-54321 / http-54322 / https-54323
               [echo] Please take a deep breath while Cargo gets the Tomcat for running the servlet tests...
             [cactus] -----------------------------------------------------------------
             [cactus] Running tests against Tomcat 5.x @ http://localhost:54322
             [cactus] -----------------------------------------------------------------
             [cactus] Deploying [/snip/hadoop/build/contrib/hdfsproxy/target/test.war] to \
                                [/snip/hadoop/build/contrib/hdfsproxy/target/tomcat-config/webapps]...
             [cactus] Tomcat 5.x starting...
          Server [Apache-Coyote/1.1] started
             [cactus] Running org.apache.hadoop.hdfsproxy.TestHdfsProxy
             [cactus] Tomcat 5.x started on port [54322]
             [cactus] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 14.53 sec
             [cactus] Test org.apache.hadoop.hdfsproxy.TestHdfsProxy FAILED
             [cactus] Tomcat 5.x is stopping...
             [cactus] Tomcat 5.x is stopped
          [junitreport] Processing /snip/hadoop/build/contrib/hdfsproxy/target/reports/TESTS-TestSuites.xml \
                                to /tmp/null1419962142
          [junitreport] Loading stylesheet jar:file:/tools/apache-ant-1.7.1/lib/ant-junit.jar!\
                                               /org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
          [junitreport] Transform time: 408ms
          [junitreport] Deleting: /tmp/null1419962142
          
          BUILD FAILED
          /snip/hadoop/build.xml:773: The following error occurred while executing this line:
          /snip/hadoop/src/contrib/build.xml:48: The following error occurred while executing this line:
          /snip/hadoop/src/contrib/hdfsproxy/build.xml:237: Tests failed!
          
          Total time: 41 seconds
          
        • Note that hdfsproxy isn't the last project in test, but the failure stops the build. That should be fixed, either as part of this issue or in another one.
        • When ant -Dtestcase=FOO test is run, this still starts tomcat.
        Show
        Chris Douglas added a comment - As part of this patch, would it be possible to cut the test timeout from 3 minutes to 30 seconds at most? Ideally, the proxy would start up on a random port instead of writing the config from ant, but OK. Since FindFreePort is used only in the unit tests, it should probably: Move under hdfsproxy/test/... Write the whole config file instead of using sed in a later ant task Pick a random port instead of starting at a fixed port and rolling to find an open one ant -Dtestcase=TestHdfsProxy test fails reliably on my machine: test: [echo] Free Ports: startup-54321 / http-54322 / https-54323 [echo] Please take a deep breath while Cargo gets the Tomcat for running the servlet tests... [cactus] ----------------------------------------------------------------- [cactus] Running tests against Tomcat 5.x @ http://localhost:54322 [cactus] ----------------------------------------------------------------- [cactus] Deploying [/snip/hadoop/build/contrib/hdfsproxy/target/test.war] to \ [/snip/hadoop/build/contrib/hdfsproxy/target/tomcat-config/webapps]... [cactus] Tomcat 5.x starting... Server [Apache-Coyote/1.1] started [cactus] Running org.apache.hadoop.hdfsproxy.TestHdfsProxy [cactus] Tomcat 5.x started on port [54322] [cactus] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 14.53 sec [cactus] Test org.apache.hadoop.hdfsproxy.TestHdfsProxy FAILED [cactus] Tomcat 5.x is stopping... [cactus] Tomcat 5.x is stopped [junitreport] Processing /snip/hadoop/build/contrib/hdfsproxy/target/reports/TESTS-TestSuites.xml \ to /tmp/null1419962142 [junitreport] Loading stylesheet jar:file:/tools/apache-ant-1.7.1/lib/ant-junit.jar!\ /org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl [junitreport] Transform time: 408ms [junitreport] Deleting: /tmp/null1419962142 BUILD FAILED /snip/hadoop/build.xml:773: The following error occurred while executing this line: /snip/hadoop/src/contrib/build.xml:48: The following error occurred while executing this line: /snip/hadoop/src/contrib/hdfsproxy/build.xml:237: Tests failed! Total time: 41 seconds Note that hdfsproxy isn't the last project in test, but the failure stops the build. That should be fixed, either as part of this issue or in another one. When ant -Dtestcase=FOO test is run, this still starts tomcat.
        Hide
        zhiyong zhang added a comment -

        Added Find Free Port to probe free port dynamically.

        Show
        zhiyong zhang added a comment - Added Find Free Port to probe free port dynamically.

          People

          • Assignee:
            zhiyong zhang
            Reporter:
            zhiyong zhang
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development