hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jd...@apache.org
Subject svn commit: r1637234 - /hive/branches/branch-0.14/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java
Date Thu, 06 Nov 2014 21:51:17 GMT
Author: jdere
Date: Thu Nov  6 21:51:17 2014
New Revision: 1637234

URL: http://svn.apache.org/r1637234
Log:
HIVE-8737: setEnv is not portable, which fails TestCliDriverMethods#testprocessInitFiles on
Windows (Xiaobing Zhou via Jason Dere)

Modified:
    hive/branches/branch-0.14/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java

Modified: hive/branches/branch-0.14/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java
URL: http://svn.apache.org/viewvc/hive/branches/branch-0.14/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java?rev=1637234&r1=1637233&r2=1637234&view=diff
==============================================================================
--- hive/branches/branch-0.14/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java
(original)
+++ hive/branches/branch-0.14/cli/src/test/org/apache/hadoop/hive/cli/TestCliDriverMethods.java
Thu Nov  6 21:51:17 2014
@@ -58,6 +58,7 @@ import org.apache.hadoop.hive.ql.Driver;
 import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
 import org.apache.hadoop.hive.service.HiveClient;
 import org.apache.hadoop.hive.service.HiveServerException;
+import org.apache.hadoop.util.Shell;
 import org.apache.thrift.TException;
 
 
@@ -375,8 +376,14 @@ public class TestCliDriverMethods extend
     }
   }
 
-
   private static void setEnv(String key, String value) throws Exception {
+    if (Shell.WINDOWS)
+      setEnvWindows(key, value);
+    else
+      setEnvLinux(key, value);
+  }
+
+  private static void setEnvLinux(String key, String value) throws Exception {
     Class[] classes = Collections.class.getDeclaredClasses();
     Map<String, String> env = (Map<String, String>) System.getenv();
     for (Class cl : classes) {
@@ -394,6 +401,26 @@ public class TestCliDriverMethods extend
     }
   }
 
+  private static void setEnvWindows(String key, String value) throws Exception {
+    Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
+    Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
+    theEnvironmentField.setAccessible(true);
+    Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
+    if (value == null) {
+      env.remove(key);
+    } else {
+      env.put(key, value);
+    }
+
+    Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
+    theCaseInsensitiveEnvironmentField.setAccessible(true);
+    Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null);
+    if (value == null) {
+      cienv.remove(key);
+    } else {
+      cienv.put(key, value);
+    }
+  }
 
   private static class FakeCliDriver extends CliDriver {
 



Mime
View raw message