HIVE-10705 Update tests for HIVE-9302 after removing binaries(Ferdinand Xu, 
reviewed by Hari Sankar Sivarama Subramaniyan)


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

Branch: refs/heads/spark
Commit: aec98e9f1b9d3bd0926b0b84c6ed49bbe494667a
Parents: 4140da5
Author: Ferdinand Xu <cheng.a...@intel.com>
Authored: Wed Jun 3 14:02:13 2015 -0400
Committer: Ferdinand Xu <cheng.a...@intel.com>
Committed: Wed Jun 3 14:02:20 2015 -0400

----------------------------------------------------------------------
 beeline/pom.xml                                 |   6 ++
 .../hive/beeline/TestBeelineArgParsing.java     |  32 +++++-----
 .../test/resources/DummyDriver-1.0-SNAPSHOT.jar | Bin 2812 -> 0 bytes
 beeline/src/test/resources/DummyDriver.txt      |  59 +++++++++++++++++++
 .../src/test/resources/postgresql-9.3.jdbc3.jar | Bin 539003 -> 0 bytes
 .../apache/hive/common/util/HiveTestUtils.java  |  46 +++++++++++++++
 .../hive/ql/session/TestSessionState.java       |  40 ++-----------
 7 files changed, 133 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/aec98e9f/beeline/pom.xml
----------------------------------------------------------------------
diff --git a/beeline/pom.xml b/beeline/pom.xml
index 352f561..4ead3d3 100644
--- a/beeline/pom.xml
+++ b/beeline/pom.xml
@@ -111,6 +111,12 @@
       <version>${junit.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>postgresql</groupId>
+      <artifactId>postgresql</artifactId>
+      <version>9.1-901.jdbc4</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <profiles>

http://git-wip-us.apache.org/repos/asf/hive/blob/aec98e9f/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
----------------------------------------------------------------------
diff --git 
a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java 
b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
index 7a354f3..702805f 100644
--- a/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
+++ b/beeline/src/test/org/apache/hive/beeline/TestBeelineArgParsing.java
@@ -18,6 +18,7 @@
 
 package org.apache.hive.beeline;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -30,6 +31,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hive.common.util.HiveTestUtils;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -41,6 +43,9 @@ import org.junit.runners.Parameterized.Parameters;
 @RunWith(Parameterized.class)
 public class TestBeelineArgParsing {
   private static final Log LOG = 
LogFactory.getLog(TestBeelineArgParsing.class.getName());
+
+  private static final String dummyDriverClazzName = "DummyDriver";
+
   private String connectionString;
   private String driverClazzName;
   private String driverJarFileName;
@@ -85,15 +90,17 @@ public class TestBeelineArgParsing {
     }
   }
 
-  @Parameters
-  public static Collection<Object[]> data() {
-    return Arrays.asList(
-        new Object[][] {
-            {"jdbc:postgresql://host:5432/testdb", "org.postgresql.Driver", 
"postgresql-9.3.jdbc3.jar",
-                true},
-            {"jdbc:dummy://host:5432/testdb", "org.apache.dummy.DummyDriver",
-                "DummyDriver-1.0-SNAPSHOT.jar", false}
-        });
+  @Parameters public static Collection<Object[]> data() throws IOException, 
InterruptedException {
+    // generate the dummy driver by using txt file
+    String u = HiveTestUtils.getFileFromClasspath("DummyDriver.txt");
+    File jarFile = HiveTestUtils.genLocalJarForTest(u, dummyDriverClazzName);
+    String pathToDummyDriver = jarFile.getAbsolutePath();
+    return Arrays.asList(new Object[][] {
+        { "jdbc:postgresql://host:5432/testdb", "org.postgresql.Driver",
+            System.getProperty("maven.local.repository") + File.separator + 
"postgresql"
+                + File.separator + "postgresql" + File.separator + 
"9.1-901.jdbc4" + File.separator
+                + "postgresql-9.1-901.jdbc4.jar", true },
+        { "jdbc:dummy://host:5432/testdb", dummyDriverClazzName, 
pathToDummyDriver, false } });
   }
 
   @Test
@@ -217,9 +224,8 @@ public class TestBeelineArgParsing {
     Assert.assertNull(bl.findLocalDriver(connectionString));
 
     LOG.info("Add " + driverJarFileName + " for the driver class " + 
driverClazzName);
-    String mysqlDriverPath = 
HiveTestUtils.getFileFromClasspath(driverJarFileName);
 
-    bl.addLocalJar(mysqlDriverPath);
+    bl.addLocalJar(driverJarFileName);
     bl.addlocaldrivername(driverClazzName);
     
Assert.assertEquals(bl.findLocalDriver(connectionString).getClass().getName(), 
driverClazzName);
   }
@@ -229,9 +235,7 @@ public class TestBeelineArgParsing {
     TestBeeline bl = new TestBeeline();
 
     LOG.info("Add " + driverJarFileName + " for the driver class " + 
driverClazzName);
-    String mysqlDriverPath = 
HiveTestUtils.getFileFromClasspath(driverJarFileName);
-
-    bl.addLocalJar(mysqlDriverPath);
+    bl.addLocalJar(driverJarFileName);
     if (!defaultSupported) {
       Assert.assertNull(bl.findLocalDriver(connectionString));
     } else {

http://git-wip-us.apache.org/repos/asf/hive/blob/aec98e9f/beeline/src/test/resources/DummyDriver-1.0-SNAPSHOT.jar
----------------------------------------------------------------------
diff --git a/beeline/src/test/resources/DummyDriver-1.0-SNAPSHOT.jar 
b/beeline/src/test/resources/DummyDriver-1.0-SNAPSHOT.jar
deleted file mode 100644
index 3dadc9e..0000000
Binary files a/beeline/src/test/resources/DummyDriver-1.0-SNAPSHOT.jar and 
/dev/null differ

http://git-wip-us.apache.org/repos/asf/hive/blob/aec98e9f/beeline/src/test/resources/DummyDriver.txt
----------------------------------------------------------------------
diff --git a/beeline/src/test/resources/DummyDriver.txt 
b/beeline/src/test/resources/DummyDriver.txt
new file mode 100644
index 0000000..05f8b12
--- /dev/null
+++ b/beeline/src/test/resources/DummyDriver.txt
@@ -0,0 +1,59 @@
+/**
+ * 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.
+ */
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+public class DummyDriver implements Driver {
+  @Override public Connection connect(String url, Properties info) throws 
SQLException {
+    return null;
+  }
+
+  @Override public boolean acceptsURL(String url) throws SQLException {
+    if (url == null) {
+      return false;
+    } else {
+      return url.startsWith("jdbc:dummy://");
+    }
+  }
+
+  @Override public DriverPropertyInfo[] getPropertyInfo(String url, Properties 
info)
+      throws SQLException {
+    return new DriverPropertyInfo[0];
+  }
+
+  @Override public int getMajorVersion() {
+    return 0;
+  }
+
+  @Override public int getMinorVersion() {
+    return 0;
+  }
+
+  @Override public boolean jdbcCompliant() {
+    return false;
+  }
+
+  @Override public Logger getParentLogger() throws 
SQLFeatureNotSupportedException {
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/hive/blob/aec98e9f/beeline/src/test/resources/postgresql-9.3.jdbc3.jar
----------------------------------------------------------------------
diff --git a/beeline/src/test/resources/postgresql-9.3.jdbc3.jar 
b/beeline/src/test/resources/postgresql-9.3.jdbc3.jar
deleted file mode 100644
index f537b98..0000000
Binary files a/beeline/src/test/resources/postgresql-9.3.jdbc3.jar and 
/dev/null differ

http://git-wip-us.apache.org/repos/asf/hive/blob/aec98e9f/common/src/java/org/apache/hive/common/util/HiveTestUtils.java
----------------------------------------------------------------------
diff --git a/common/src/java/org/apache/hive/common/util/HiveTestUtils.java 
b/common/src/java/org/apache/hive/common/util/HiveTestUtils.java
index db34494..06caa53 100644
--- a/common/src/java/org/apache/hive/common/util/HiveTestUtils.java
+++ b/common/src/java/org/apache/hive/common/util/HiveTestUtils.java
@@ -18,14 +18,27 @@
 
 package org.apache.hive.common.util;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.net.URL;
 
+import com.google.common.io.Files;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hive.common.classification.InterfaceAudience;
 import org.apache.hadoop.hive.common.classification.InterfaceStability;
 
 @InterfaceAudience.Private
 @InterfaceStability.Unstable
 public class HiveTestUtils {
+  public static final Log LOG = LogFactory.getLog(HiveTestUtils.class);
+
+  public final static String JAVA_FILE_EXT = ".java";
+  public final static String CLAZZ_FILE_EXT = ".class";
+  public final static String JAR_FILE_EXT = ".jar";
+  public final static String TXT_FILE_EXT = ".txt";
 
   public static String getFileFromClasspath(String name) {
     URL url = ClassLoader.getSystemResource(name);
@@ -34,4 +47,37 @@ public class HiveTestUtils {
     }
     return url.getPath();
   }
+
+  private static 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();
+  }
+
+  public static File genLocalJarForTest(String pathToClazzFile, String 
clazzName)
+      throws IOException, InterruptedException {
+    String u = pathToClazzFile;
+    File dir = new File(u);
+    File parentDir = dir.getParentFile();
+    File f = new File(parentDir, clazzName + JAVA_FILE_EXT);
+    Files.copy(dir, f);
+    executeCmd(new String[] { "javac", clazzName + JAVA_FILE_EXT }, parentDir);
+    executeCmd(new String[] { "jar", "cf", clazzName + JAR_FILE_EXT, clazzName 
+ CLAZZ_FILE_EXT },
+        parentDir);
+    f.delete();
+    new File(parentDir, clazzName + CLAZZ_FILE_EXT).delete();
+    return new File(parentDir, clazzName + JAR_FILE_EXT);
+  }
 }

http://git-wip-us.apache.org/repos/asf/hive/blob/aec98e9f/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 45ad22a..9e16c0c 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
@@ -57,15 +57,8 @@ public class TestSessionState {
   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);
@@ -191,35 +184,10 @@ public class TestSessionState {
   }
 
   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();
+    String u = HiveTestUtils
+        .getFileFromClasspath(RELOADED_CLAZZ_PREFIX_NAME + version + 
HiveTestUtils.TXT_FILE_EXT);
+    File jarFile = HiveTestUtils.genLocalJarForTest(u, 
RELOADED_CLAZZ_PREFIX_NAME);
+    Files.move(jarFile, new File(jarFile.getAbsolutePath() + "." + version));
   }
 
   @Test

Reply via email to