You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by xu...@apache.org on 2015/05/29 06:47:54 UTC
[75/84] [abbrv] hive git commit: HIVE-10684: Fix the unit test
failures for HIVE-7553 after HIVE-10674 removed the binary jar
files(Ferdinand Xu,
reviewed by Hari Sankar Sivarama Subramaniyan and Sushanth Sowmyan)
HIVE-10684: Fix the unit test failures for HIVE-7553 after HIVE-10674 removed the binary jar files(Ferdinand Xu, reviewed by Hari Sankar Sivarama Subramaniyan and Sushanth Sowmyan)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/52221a76
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/52221a76
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/52221a76
Branch: refs/heads/spark
Commit: 52221a766b431ce406f987988011ebc62071203f
Parents: 2564a92
Author: Ferdinand Xu <ch...@intel.com>
Authored: Thu May 28 14:06:40 2015 -0400
Committer: Ferdinand Xu <ch...@intel.com>
Committed: Thu May 28 14:06:40 2015 -0400
----------------------------------------------------------------------
.../hive/ql/session/TestSessionState.java | 62 +++++++++++++++++--
ql/src/test/resources/RefreshedJarClassV1.txt | 26 ++++++++
ql/src/test/resources/RefreshedJarClassV2.txt | 26 ++++++++
ql/src/test/resources/SessionStateTest.jar.v1 | Bin 2176 -> 0 bytes
ql/src/test/resources/SessionStateTest.jar.v2 | Bin 2177 -> 0 bytes
5 files changed, 108 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/52221a76/ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java b/ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java
index 45ba07e..45ad22a 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java
@@ -20,13 +20,16 @@ package org.apache.hadoop.hive.ql.session;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.conf.HiveConf;
@@ -48,13 +51,21 @@ import com.google.common.io.Files;
*/
@RunWith(value = Parameterized.class)
public class TestSessionState {
-
private final boolean prewarm;
- private final static String clazzDistFileName = "SessionStateTest.jar.v1";
- private final static String clazzV2FileName = "SessionStateTest.jar.v2";
- private final static String reloadClazzFileName = "reloadingClazz.jar";
- private final static String reloadClazzName = "org.apache.test.RefreshedJarClass";
+ private final static String clazzDistFileName = "RefreshedJarClass.jar.V1";
+ private final static String clazzV2FileName = "RefreshedJarClass.jar.V2";
+ private final static String reloadClazzFileName = "RefreshedJarClass.jar";
private final static String versionMethodName = "version";
+ private final static String RELOADED_CLAZZ_PREFIX_NAME = "RefreshedJarClass";
+ private final static String JAVA_FILE_EXT = ".java";
+ private final static String CLAZZ_FILE_EXT = ".class";
+ private final static String JAR_FILE_EXT = ".jar";
+ private final static String TXT_FILE_EXT = ".txt";
+ private final static String V1 = "V1";
+ private final static String V2 = "V2";
+ private final String clazzFile = RELOADED_CLAZZ_PREFIX_NAME + CLAZZ_FILE_EXT;
+ private final String jarFile = RELOADED_CLAZZ_PREFIX_NAME + JAR_FILE_EXT;
+ private final String javaFile = RELOADED_CLAZZ_PREFIX_NAME + JAVA_FILE_EXT;
private static String hiveReloadPath;
private File reloadFolder;
public static final Log LOG = LogFactory.getLog(TestSessionState.class);
@@ -83,6 +94,13 @@ public class TestSessionState {
reloadFolder.mkdir();
}
+ try {
+ generateRefreshJarFiles(V2);
+ generateRefreshJarFiles(V1);
+ } catch (Throwable e) {
+ Assert.fail("fail to generate refresh jar file due to the error " + e);
+ }
+
if (prewarm) {
HiveConf.setBoolVar(conf, ConfVars.HIVE_PREWARM_ENABLED, true);
HiveConf.setIntVar(conf, ConfVars.HIVE_PREWARM_NUM_CONTAINERS, 1);
@@ -167,11 +185,43 @@ public class TestSessionState {
}
private String getReloadedClazzVersion(ClassLoader cl) throws Exception {
- Class addedClazz = Class.forName(reloadClazzName, true, cl);
+ Class addedClazz = Class.forName(RELOADED_CLAZZ_PREFIX_NAME, true, cl);
Method versionMethod = addedClazz.getMethod(versionMethodName);
return (String) versionMethod.invoke(addedClazz.newInstance());
}
+ private void generateRefreshJarFiles(String version) throws IOException, InterruptedException {
+ String u = HiveTestUtils.getFileFromClasspath(
+ RELOADED_CLAZZ_PREFIX_NAME + version + TXT_FILE_EXT);
+ File dir = new File(u);
+ File parentDir = dir.getParentFile();
+ File f = new File(parentDir, javaFile);
+ Files.copy(dir, f);
+ executeCmd(new String[]{"javac", javaFile}, parentDir);
+ executeCmd(new String[]{"jar", "cf", jarFile, clazzFile}, parentDir);
+ Files.move(new File(parentDir, jarFile), new File(parentDir, jarFile + "." + version));
+ f.delete();
+ new File(parentDir, clazzFile).delete();
+ }
+
+ private void executeCmd(String[] cmdArr, File dir) throws IOException, InterruptedException {
+ final Process p1 = Runtime.getRuntime().exec(cmdArr, null, dir);
+ new Thread(new Runnable() {
+ public void run() {
+ BufferedReader input = new BufferedReader(new InputStreamReader(p1.getErrorStream()));
+ String line;
+ try {
+ while ((line = input.readLine()) != null) {
+ System.out.println(line);
+ }
+ } catch (IOException e) {
+ LOG.error("Failed to execute the command due the exception " + e);
+ }
+ }
+ }).start();
+ p1.waitFor();
+ }
+
@Test
public void testReloadAuxJars2() {
HiveConf conf = new HiveConf();
http://git-wip-us.apache.org/repos/asf/hive/blob/52221a76/ql/src/test/resources/RefreshedJarClassV1.txt
----------------------------------------------------------------------
diff --git a/ql/src/test/resources/RefreshedJarClassV1.txt b/ql/src/test/resources/RefreshedJarClassV1.txt
new file mode 100644
index 0000000..036b998
--- /dev/null
+++ b/ql/src/test/resources/RefreshedJarClassV1.txt
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class RefreshedJarClass {
+ public String version(){
+ return "version1";
+ }
+
+ public static void main(String [] args){
+ System.out.println(new RefreshedJarClass().version());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hive/blob/52221a76/ql/src/test/resources/RefreshedJarClassV2.txt
----------------------------------------------------------------------
diff --git a/ql/src/test/resources/RefreshedJarClassV2.txt b/ql/src/test/resources/RefreshedJarClassV2.txt
new file mode 100644
index 0000000..c965265
--- /dev/null
+++ b/ql/src/test/resources/RefreshedJarClassV2.txt
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class RefreshedJarClass {
+ public String version(){
+ return "version2";
+ }
+
+ public static void main(String [] args){
+ System.out.println(new RefreshedJarClass().version());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hive/blob/52221a76/ql/src/test/resources/SessionStateTest.jar.v1
----------------------------------------------------------------------
diff --git a/ql/src/test/resources/SessionStateTest.jar.v1 b/ql/src/test/resources/SessionStateTest.jar.v1
deleted file mode 100644
index 47bceb8..0000000
Binary files a/ql/src/test/resources/SessionStateTest.jar.v1 and /dev/null differ
http://git-wip-us.apache.org/repos/asf/hive/blob/52221a76/ql/src/test/resources/SessionStateTest.jar.v2
----------------------------------------------------------------------
diff --git a/ql/src/test/resources/SessionStateTest.jar.v2 b/ql/src/test/resources/SessionStateTest.jar.v2
deleted file mode 100644
index df0da41..0000000
Binary files a/ql/src/test/resources/SessionStateTest.jar.v2 and /dev/null differ