diff --git itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithDBTokenStore.java itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithDBTokenStore.java index 272c745a8f..febfcf5230 100644 --- itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithDBTokenStore.java +++ itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithDBTokenStore.java @@ -51,13 +51,14 @@ public static void beforeTest() throws Exception { MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.WAREHOUSE)); System.setProperty(HiveConf.ConfVars.METASTORECONNECTURLKEY.varname, MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.CONNECT_URL_KEY)); - // Before this patch, the Embedded MetaStore was used here not the one started by the MiniHS2 - // The below 3 lines would change the tests to use the Remote MetaStore, but it will cause a - // failure. By removing the thrift MetaStore uris, the tests are passing again. - // I think this is an valid problem here, but not really sure about the - // tests original intention, so keep everything as it was originally. -// System.setProperty(HiveConf.ConfVars.METASTOREURIS.varname, -// MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.THRIFT_URIS)); -// Thread.sleep(2000); + System.setProperty(HiveConf.ConfVars.METASTOREURIS.varname, + MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.THRIFT_URIS)); + System.setProperty(ConfVars.METASTORE_USE_THRIFT_SASL.varname, + String.valueOf(MetastoreConf.getBoolVar(hiveConf, MetastoreConf.ConfVars.USE_THRIFT_SASL))); + System.setProperty(HiveConf.ConfVars.METASTORE_KERBEROS_PRINCIPAL.varname, + MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.KERBEROS_PRINCIPAL)); + System.setProperty(ConfVars.METASTORE_KERBEROS_KEYTAB_FILE.varname, + MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.KERBEROS_KEYTAB_FILE)); + } } \ No newline at end of file diff --git itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithDBTokenStoreNoDoAs.java itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithDBTokenStoreNoDoAs.java index 5b7fb7ea5d..136c966abe 100644 --- itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithDBTokenStoreNoDoAs.java +++ itests/hive-minikdc/src/test/java/org/apache/hive/minikdc/TestJdbcWithDBTokenStoreNoDoAs.java @@ -53,6 +53,5 @@ public static void beforeTest() throws Exception { MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.CONNECT_URL_KEY)); System.setProperty(HiveConf.ConfVars.METASTOREURIS.varname, MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.THRIFT_URIS)); - Thread.sleep(2000); } } \ No newline at end of file diff --git itests/util/src/main/java/org/apache/hive/jdbc/miniHS2/MiniHS2.java itests/util/src/main/java/org/apache/hive/jdbc/miniHS2/MiniHS2.java index e5b100c549..30b23cf029 100644 --- itests/util/src/main/java/org/apache/hive/jdbc/miniHS2/MiniHS2.java +++ itests/util/src/main/java/org/apache/hive/jdbc/miniHS2/MiniHS2.java @@ -21,6 +21,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -68,6 +70,9 @@ private static final FsPermission WRITE_ALL_PERM = new FsPermission((short)00733); private static final String tmpDir = System.getProperty("test.tmp.dir"); private static final int DEFAULT_DATANODE_COUNT = 4; + private static final long STARTUP_TIMEOUT = 1000L * 1000L; + private static final long STARTUP_WAIT_STEP = 500L; + private HiveServer2 hiveServer2 = null; private final File baseDir; private final Path baseFsDir; @@ -397,7 +402,11 @@ public void start(Map confOverlay) throws Exception { throw(hs2Exception); } - waitForStartup(); + if (getHiveConf().getBoolean(ConfVars.HIVE_SERVER2_ACTIVE_PASSIVE_HA_ENABLE.varname, false)) { + waitForStartupForHA(); + } else { + waitForStartupWithDriver(); + } setStarted(true); } @@ -606,24 +615,43 @@ public MiniDFSShim getDFS() { return dfs; } - private void waitForStartup() throws Exception { + private void waitForStartupWithDriver() throws Exception { + int waitTime = 0; + Connection hs2Conn; + do { + Thread.sleep(STARTUP_WAIT_STEP); + waitTime += STARTUP_WAIT_STEP; + if (waitTime > STARTUP_TIMEOUT) { + throw new TimeoutException("Couldn't access new HiveServer2: " + getJdbcURL()); + } + try { + hs2Conn = DriverManager.getConnection(getJdbcURL()); + } catch (Throwable e) { + // service not started yet + continue; + } + hs2Conn.close(); + break; + } while (true); + } + + private void waitForStartupForHA() throws Exception { int waitTime = 0; - long startupTimeout = 1000L * 1000L; CLIServiceClient hs2Client = getServiceClientInternal(); SessionHandle sessionHandle = null; do { - Thread.sleep(500L); - waitTime += 500L; - if (waitTime > startupTimeout) { + Thread.sleep(STARTUP_WAIT_STEP); + waitTime += STARTUP_WAIT_STEP; + if (waitTime > STARTUP_TIMEOUT) { throw new TimeoutException("Couldn't access new HiveServer2: " + getJdbcURL()); } try { Map sessionConf = new HashMap(); /** - if (isUseMiniKdc()) { - getMiniKdc().loginUser(getMiniKdc().getDefaultUserPrincipal()); - sessionConf.put("principal", serverPrincipal); - } + if (isUseMiniKdc()) { + getMiniKdc().loginUser(getMiniKdc().getDefaultUserPrincipal()); + sessionConf.put("principal", serverPrincipal); + } */ sessionHandle = hs2Client.openSession("foo", "bar", sessionConf); } catch (Exception e) {