Repository: sentry Updated Branches: refs/heads/master 3c11bb2dd -> 99aea6fcc
SENTRY-1586: [unit test] Race condition between metastore server/client could cause connection refused errors (Vamsee Yarlagadda, Reviewed by: Alexander Kolbasov) Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/99aea6fc Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/99aea6fc Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/99aea6fc Branch: refs/heads/master Commit: 99aea6fcc3b92345e4cdf82f6f1eb9677e89b5cf Parents: 3c11bb2 Author: Vamsee Yarlagadda <[email protected]> Authored: Wed Jan 4 17:14:32 2017 -0800 Committer: Vamsee Yarlagadda <[email protected]> Committed: Wed Jan 4 18:47:15 2017 -0800 ---------------------------------------------------------------------- .../hive/hiveserver/InternalMetastoreServer.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/99aea6fc/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/InternalMetastoreServer.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/InternalMetastoreServer.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/InternalMetastoreServer.java index bf43798..27ea178 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/InternalMetastoreServer.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/hiveserver/InternalMetastoreServer.java @@ -21,6 +21,10 @@ import java.net.URI; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.conf.HiveConf; @@ -54,18 +58,31 @@ public class InternalMetastoreServer extends AbstractHiveServer { // async metastore startup since Hive doesn't have that option private void startMetastore() throws Exception { + final Lock startLock = new ReentrantLock(); + final Condition startCondition = startLock.newCondition(); + final AtomicBoolean startedServing = new AtomicBoolean(); Callable<Void> metastoreService = new Callable<Void>() { public Void call() throws Exception { try { HiveMetaStore.startMetaStore(getMetastorePort(conf), - ShimLoader.getHadoopThriftAuthBridge(), conf); + ShimLoader.getHadoopThriftAuthBridge(), conf, startLock, startCondition, startedServing); } catch (Throwable e) { throw new Exception("Error starting metastore", e); } return null; } }; + + // Wait for metastore server to initialize completely before letting tests connect to it. + startLock.lock(); metaStoreExecutor.submit(metastoreService); + try { + while (!startedServing.get()) { + startCondition.await(); + } + } finally { + startLock.unlock(); + } } private static String getMetastoreHostname(Configuration conf)
