IMPALA-9266: Use custom cluster test case to replace
CreateKuduTableWithoutHMSTest.java

CreateKuduTableWithoutHMSTest.java test case need to restart impala
cluster, in order to keep original cluster environment unchanged, we
write a custom cluter test case test_kudu_table_create_without_hms.py
to replace.
Besides, we also add an envp 'WITHOUT_HMS' to keep original
hive-site.xml unchanged, just generate a new hive-site_ext.xml without
hms related config.

Change-Id: Ic532574af42ed864612cf28eecee9e0416ef272c
Reviewed-on: http://gerrit.cloudera.org:8080/14962
Reviewed-by: Joe McDonnell <joemcdonnell@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
diff --git a/bin/create-test-configuration.sh b/bin/create-test-configuration.sh
index d1ec5b1..d1f5dc8 100755
--- a/bin/create-test-configuration.sh
+++ b/bin/create-test-configuration.sh
@@ -146,6 +146,12 @@
 rm -f hive-site-ext/hive-site.xml
 ln -s "${CONFIG_DIR}/hive-site_ext.xml" hive-site-ext/hive-site.xml
 
+export HIVE_VARIANT=without_hms_config
+$IMPALA_HOME/bin/generate_xml_config.py hive-site.xml.py hive-site_without_hms.xml
+mkdir -p hive-site-without-hms
+rm -f hive-site-without-hms/hive-site.xml
+ln -s "${CONFIG_DIR}/hive-site_without_hms.xml" hive-site-without-hms/hive-site.xml
+
 generate_config hive-log4j2.properties.template hive-log4j2.properties
 
 if [ $CREATE_METASTORE -eq 1 ]; then
diff --git a/fe/src/test/java/org/apache/impala/catalog/CreateKuduTableWithoutHMSTest.java b/fe/src/test/java/org/apache/impala/catalog/CreateKuduTableWithoutHMSTest.java
deleted file mode 100644
index 2d1b522..0000000
--- a/fe/src/test/java/org/apache/impala/catalog/CreateKuduTableWithoutHMSTest.java
+++ /dev/null
@@ -1,137 +0,0 @@
-// 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.
-
-package org.apache.impala.catalog;
-
-import org.apache.impala.testutil.ImpalaJdbcClient;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-
-import java.io.IOException;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Test kudu managed table create/drop operation when connected
- * to mysql/postgreSQL directly instead of HMS
- */
-public class CreateKuduTableWithoutHMSTest {
-  private static String IMPALA_HOME = System.getenv().get("IMPALA_HOME");
-  private static String HIVE_CONF_DIR = System.getenv().get("HIVE_CONF_DIR");
-  private static String TMP_HIVE_SITE = HIVE_CONF_DIR + "/hive-site-ext";
-  private static String URL =
-      "jdbc:hive2://localhost:21050/default;auth=noSasl;user=impala";
-
-  @Test
-  public void TestKuduTable() throws ClassNotFoundException,SQLException {
-    ImpalaJdbcClient client = ImpalaJdbcClient.createClientUsingHiveJdbcDriver(URL);
-    try {
-      client.connect();
-      client.execQuery("CREATE TABLE IF NOT EXISTS default.test_kudu_without_hms (" +
-          "id INT, " +
-          "PRIMARY KEY (id)" +
-          ") " +
-          "STORED AS KUDU " +
-          "TBLPROPERTIES ('kudu.master_addresses'='localhost');");
-      ResultSet rs = client.getConnection().getMetaData().getTables("",
-          "default", "test_kudu_without_hms", new String[]{"TABLE"});
-      validateTable(rs);
-      rs.close();
-    } finally {
-      client.execQuery("DROP TABLE IF EXISTS default.test_kudu_without_hms");
-      client.close();
-    }
-  }
-
-  /**
-   * Validate new created kudu managed table for testing.
-   */
-  private void validateTable(ResultSet rs) throws SQLException {
-    assertTrue(rs.next());
-    String resultTableName = rs.getString("TABLE_NAME");
-    assertEquals(rs.getString(3), resultTableName);
-    String tableType = rs.getString("TABLE_TYPE");
-    assertEquals("table", tableType.toLowerCase());
-    assertFalse(rs.next());
-  }
-
-  /**
-   * Restart impala cluster with or without HMS config
-   */
-  private static void restartImpalaCluster(boolean useHiveMetastore)
-      throws IOException, InterruptedException {
-    StringBuilder args = new StringBuilder(" --log_dir=${IMPALA_EE_TEST_LOGS_DIR}");
-    String kuduVariant = "";
-    if (!useHiveMetastore) {
-      args.append(" --env_vars=CUSTOM_CLASSPATH=" + TMP_HIVE_SITE);
-      kuduVariant = "KUDU_VARIANT=without_hms_config";
-    }
-
-    List<String> envpList = initEnv(kuduVariant);
-    String[] envpArray = new String[envpList.size()];
-    envpList.toArray(envpArray);
-
-    String generateCmd = String.format("bash %s/bin/create-test-configuration.sh",
-                                       IMPALA_HOME);
-    String restartCmd = IMPALA_HOME + "/bin/start-impala-cluster.py" + args.toString();
-    String cmdStr = generateCmd + " && " + restartCmd;
-    Process p = Runtime.getRuntime().exec(getCmdsArray(cmdStr), envpArray);
-    p.waitFor();
-    assertEquals(0, p.exitValue());
-  }
-
-  /**
-   * Reserve all enviroment path from current process, including parameters
-   */
-  private static List<String> initEnv(String kuduEnvp) {
-    List<String> envp = new ArrayList<>();
-    for (Map.Entry<String,String> entry : System.getenv().entrySet()) {
-      envp.add(entry.getKey() + "=" + entry.getValue());
-    }
-    envp.add(kuduEnvp);
-    return envp;
-  }
-
-  /**
-   * Joint several commands as one command, and pass to Runtime.exec
-   */
-  private static String[] getCmdsArray(String cmdStr) {
-    String[] cmdsArray = new String[3];
-    cmdsArray[0] = "/bin/sh";
-    cmdsArray[1] = "-c";
-    cmdsArray[2] = cmdStr;
-    return cmdsArray;
-  }
-
-  @BeforeClass
-  public static void setUp() throws Exception {
-    restartImpalaCluster(false);
-  }
-
-  @AfterClass
-  public static void cleanUp() throws Exception {
-    restartImpalaCluster(true);
-  }
-}
\ No newline at end of file
diff --git a/fe/src/test/resources/hive-site.xml.py b/fe/src/test/resources/hive-site.xml.py
index 4694a6b..bfba57d 100644
--- a/fe/src/test/resources/hive-site.xml.py
+++ b/fe/src/test/resources/hive-site.xml.py
@@ -22,7 +22,6 @@
 hive_major_version = int(os.environ['IMPALA_HIVE_VERSION'][0])
 kerberize = os.environ.get('IMPALA_KERBERIZE') == '1'
 variant = os.environ.get('HIVE_VARIANT')
-kudu_variant = os.environ.get('KUDU_VARIANT')
 
 CONFIG = {
   'dfs.replication': '3'
@@ -143,7 +142,7 @@
  'hive.metastore.dml.events': 'true',
 })
 
-if kudu_variant == 'without_hms_config':
+if variant == 'without_hms_config':
   CONFIG.clear()
 
 # Database and JDO-related configs:
diff --git a/tests/custom_cluster/test_kudu_table_create_without_hms.py b/tests/custom_cluster/test_kudu_table_create_without_hms.py
new file mode 100644
index 0000000..1fc553b
--- /dev/null
+++ b/tests/custom_cluster/test_kudu_table_create_without_hms.py
@@ -0,0 +1,38 @@
+# 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 pytest
+import os
+
+from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
+
+IMPALA_HOME = os.getenv('IMPALA_HOME')
+HIVE_SITE_WITHOUT_HMS_DIR = IMPALA_HOME + '/fe/src/test/resources/hive-site-without-hms'
+TBL_NAME = "test_kudu_table_create_without_hms"
+
+
+class TestCreatingKuduTableWithoutHMS(CustomClusterTestSuite):
+  """Test creating kudu managed table without hms"""
+
+  @pytest.mark.execute_serially
+  @CustomClusterTestSuite.with_args(hive_conf_dir=HIVE_SITE_WITHOUT_HMS_DIR)
+  def test_kudu_table_create_without_hms(self, unique_database):
+    table_name = unique_database + "." + TBL_NAME
+    self.execute_query_expect_success(self.client, "create table %s "
+        "(id int, primary key(id)) stored as kudu" % table_name)
+    self.execute_query_expect_success(self.client, "select * from %s" % table_name)
+    self.execute_query("drop table if exists %s" % table_name)