Repository: sqoop
Updated Branches:
  refs/heads/trunk f7b460b3f -> 3153c3610


SQOOP-3283: Fixing MySQL 3rd party test hanging issue by getting username
from System env/property instead of depending on whoami and Process#waitFor

(Daniel Voros by Attila Szabo)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/3153c361
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/3153c361
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/3153c361

Branch: refs/heads/trunk
Commit: 3153c3610da7e5db388bfb14f3681d308e9e89c6
Parents: f7b460b
Author: Attila Szabo <mau...@apache.org>
Authored: Wed Feb 14 18:58:08 2018 +0100
Committer: Attila Szabo <mau...@apache.org>
Committed: Wed Feb 14 18:58:08 2018 +0100

----------------------------------------------------------------------
 .../sqoop/manager/mysql/MySQLTestUtils.java     | 51 +++-----------------
 1 file changed, 8 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/3153c361/src/test/org/apache/sqoop/manager/mysql/MySQLTestUtils.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/sqoop/manager/mysql/MySQLTestUtils.java 
b/src/test/org/apache/sqoop/manager/mysql/MySQLTestUtils.java
index 25dbe9d..75ecc35 100644
--- a/src/test/org/apache/sqoop/manager/mysql/MySQLTestUtils.java
+++ b/src/test/org/apache/sqoop/manager/mysql/MySQLTestUtils.java
@@ -18,15 +18,11 @@
 
 package org.apache.sqoop.manager.mysql;
 
-import org.apache.sqoop.SqoopOptions;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.sqoop.SqoopOptions;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.util.ArrayList;
 
 /**
@@ -95,50 +91,19 @@ public final class MySQLTestUtils {
     return moreArgs;
   }
 
-  public static String getCurrentUser() {
+  private static String getCurrentUser() {
     // First, check the $USER environment variable.
     String envUser = System.getenv("USER");
     if (null != envUser) {
       return envUser;
     }
-    // Try `whoami`
-    String[] whoamiArgs = new String[1];
-    whoamiArgs[0] = "whoami";
-    Process p = null;
-    BufferedReader r = null;
-    try {
-      p = Runtime.getRuntime().exec(whoamiArgs);
-      InputStream is = p.getInputStream();
-      r = new BufferedReader(new InputStreamReader(is));
-      return r.readLine();
-    } catch (IOException ioe) {
-      LOG.error("IOException reading from `whoami`: " + ioe.toString());
-      return null;
-    } finally {
-      // close our stream.
-      if (null != r) {
-        try {
-          r.close();
-        } catch (IOException ioe) {
-          LOG.warn("IOException closing input stream from `whoami`: "
-              + ioe.toString());
-        }
-      }
-      // wait for whoami to exit.
-      while (p != null) {
-        try {
-          int ret = p.waitFor();
-          if (0 != ret) {
-            LOG.error("whoami exited with error status " + ret);
-            // suppress original return value from this method.
-            return null;
-          }
-        } catch (InterruptedException ie) {
-          continue; // loop around.
-        }
-      }
-
+    // Fall back to user.name system property
+    envUser = System.getProperty("user.name");
+    if (null != envUser) {
+      return envUser;
     }
+    throw new RuntimeException("MySQL username not set and unable to get 
system user. Please set it"
+        + " with '-Dsqoop.test.mysql.username=...' or USER environment 
variable!");
   }
 
   public void addPasswordIfIsSet(ArrayList<String> args) {

Reply via email to