diff --git ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java index c3c353b..9e16c0c 100644 --- ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java +++ ql/src/test/org/apache/hadoop/hive/ql/session/TestSessionState.java @@ -20,13 +20,16 @@ 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,12 +51,10 @@ */ @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 V1 = "V1"; @@ -86,6 +87,13 @@ public void setUp() { 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); @@ -170,7 +178,7 @@ public void testClassLoaderEquality() throws Exception { } 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()); } diff --git ql/src/test/resources/RefreshedJarClassV1.txt ql/src/test/resources/RefreshedJarClassV1.txt new file mode 100644 index 0000000..70c9069 --- /dev/null +++ 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()); + } +} diff --git ql/src/test/resources/RefreshedJarClassV2.txt ql/src/test/resources/RefreshedJarClassV2.txt new file mode 100644 index 0000000..6aac034 --- /dev/null +++ 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()); + } +}