You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2015/01/12 20:02:54 UTC

incubator-slider git commit: SLIDER-749 jenkins on windows failing: move/rename utility methods

Repository: incubator-slider
Updated Branches:
  refs/heads/develop e4f5db951 -> 06bea7194


SLIDER-749 jenkins on windows failing: move/rename utility methods


Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/06bea719
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/06bea719
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/06bea719

Branch: refs/heads/develop
Commit: 06bea719491bb69b0397f015a71d9dc7bfa3d5ed
Parents: e4f5db9
Author: Steve Loughran <st...@apache.org>
Authored: Mon Jan 12 19:02:37 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Mon Jan 12 19:02:37 2015 +0000

----------------------------------------------------------------------
 .../common/tools/TestWindowsSupport.groovy      | 30 +-------
 .../apache/slider/test/SliderTestUtils.groovy   | 75 +++++++++++++++++++-
 2 files changed, 75 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/06bea719/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy
index 198bd82..d96886a 100644
--- a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy
@@ -136,7 +136,7 @@ class TestWindowsSupport extends YarnMiniClusterTestBase {
   @Test
   public void testExecNonexistentBinary2() throws Throwable {
     assumeWindows()
-    assert !doesWindowsAppExist(["undefined-application", "--version"])
+    assert !doesAppExist(["undefined-application", "--version"])
   }
 
   public assumeWindows() {
@@ -196,32 +196,4 @@ class TestWindowsSupport extends YarnMiniClusterTestBase {
     log.info "Hadoop DLL at: $exepath"
   }
 
-  public File locateExecutable(String exe) {
-    File exepath = null
-    String path = extractPath()
-    String[] dirs = path.split(System.getProperty("path.separator"));
-    dirs.each { String dirname ->
-      File dir = new File(dirname)
-
-      File possible = new File(dir, exe)
-      if (possible.exists()) {
-        exepath = possible
-      }
-    }
-    return exepath
-  }
-
-  public String extractPath() {
-    String pathkey = "";
-
-    System.getenv().keySet().each { String it ->
-      if (it.toLowerCase(Locale.ENGLISH).equals("path")) {
-        pathkey = it;
-      }
-    }
-    assert pathkey
-    log.info("Path env variable is $pathkey")
-    def path = System.getenv(pathkey)
-    return path
-  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/06bea719/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
index 4891f02..82436e2 100644
--- a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
@@ -691,7 +691,20 @@ class SliderTestUtils extends Assert {
     process
   }
 
-  public static boolean doesWindowsAppExist(List<String> commands) {
+  /**
+   * Does an application exist? Run the commands and if the
+   * operation fails with a FileNotFoundException, then
+   * this method returns false.
+   * <p>
+   *   Run something harmless like a -version command, something
+   *   which must return 0
+   *   
+   * @param commands
+   * @return true if the command sequence succeeded
+   * false if they failed with no file
+   * @throws Exception on any other failure cause
+   */
+  public static boolean doesAppExist(List<String> commands) {
     try {
       exec(0, commands)
       return true;
@@ -704,6 +717,66 @@ class SliderTestUtils extends Assert {
   }
 
   /**
+   * Locate an executable on the path
+   * @param exe executable name. If it is an absolute path which
+   * exists then it will returned direct
+   * @return the path to an exe or null for no match
+   */
+  public static File locateExecutable(String exe) {
+    File exeNameAsPath = new File(exe).absoluteFile
+    if (exeNameAsPath.exists()) {
+      return exeNameAsPath
+    }
+    
+    File exepath = null
+    String path = extractPath()
+    String[] dirs = path.split(System.getProperty("path.separator"));
+    dirs.each { String dirname ->
+      File dir = new File(dirname)
+
+      File possible = new File(dir, exe)
+      if (possible.exists()) {
+        exepath = possible
+      }
+    }
+    return exepath
+  }
+
+  /**
+   * Lookup the PATH env var
+   * @return the path or null
+   */
+  public static String extractPath() {
+    return extractEnvVar("PATH")
+  }
+  
+  /**
+   * Find an environment variable. Uses case independent checking for
+   * the benefit of windows.
+   * Will fail if the var is not found.
+   * @param var path variable <i>in upper case</i>
+   * @return the env var
+   */
+  public static String extractEnvVar(String var) {
+    String realkey = "";
+
+    System.getenv().keySet().each { String it ->
+      if (it.toUpperCase(Locale.ENGLISH).equals(var)) {
+        realkey = it;
+      }
+    }
+
+    if (!realkey) {
+      fail("No environment variable $var found")
+    }
+    assert realkey
+    def val = System.getenv(realkey)
+    
+    log.info("$realkey = $val")
+    return val
+  }
+
+  /**
    * Execute a closure, assert it fails with a given exit code and text
    * @param exitCode exit code
    * @param text text (can be "")