diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java index 940a1bf..afb0145 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/conf/MetastoreConf.java @@ -1095,8 +1095,10 @@ public static void setHiveSiteLocation(URL location) { } public static Configuration newMetastoreConf() { + return newMetastoreConf(new Configuration()); + } - Configuration conf = new Configuration(); + public static Configuration newMetastoreConf(Configuration conf) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java index 1d12cf9..3bf61fe 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/MetaStoreTestUtils.java @@ -101,15 +101,33 @@ public static int startMetaStoreWithRetry(HadoopThriftAuthBridge bridge, Configuration conf) throws Exception { Exception metaStoreException = null; String warehouseDir = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE); + String jdbcUrl = MetastoreConf.getVar(conf, ConfVars.CONNECT_URL_KEY); + for (int tryCount = 0; tryCount < MetaStoreTestUtils.RETRY_COUNT; tryCount++) { try { int metaStorePort = findFreePort(); + // Setting metastore instance specific warehouse directory, postfixing with port Path postfixedWarehouseDir = new Path(warehouseDir, String.valueOf(metaStorePort)); MetastoreConf.setVar(conf, ConfVars.WAREHOUSE, postfixedWarehouseDir.toString()); + + // Setting metastore instance specific jdbc url postfixed with port + String postfixedJdbcUrl = jdbcUrl.replace("junit_metastore_db", "junit_metastore_db_" + + metaStorePort); + MetastoreConf.setVar(conf, ConfVars.CONNECT_URL_KEY, postfixedJdbcUrl); + + // Setting metastore instance specific metastore uri MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + metaStorePort); MetaStoreTestUtils.startMetaStore(metaStorePort, bridge, conf); - LOG.error("MetaStore Thrift Server started on port: {} with warehouse dir: {}", - metaStorePort, postfixedWarehouseDir); + + // Creating warehouse dir, if not exists + Warehouse wh = new Warehouse(conf); + if (!wh.isDir(wh.getWhRoot())) { + wh.mkdirs(wh.getWhRoot()); + LOG.info("MetaStore warehouse root dir ({}) is created", postfixedWarehouseDir); + } + + LOG.info("MetaStore Thrift Server started on port: {} with warehouse dir: {} with " + + "jdbcUrl: {}", metaStorePort, postfixedWarehouseDir, postfixedJdbcUrl); return metaStorePort; } catch (ConnectException ce) { metaStoreException = ce; diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java index 5a56caf..9045362 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java @@ -98,7 +98,7 @@ public abstract class TestHiveMetaStore { private static final Logger LOG = LoggerFactory.getLogger(TestHiveMetaStore.class); protected static HiveMetaStoreClient client; - protected static Configuration conf; + protected static Configuration conf = null; protected static Warehouse warehouse; protected static boolean isThriftClient = false; @@ -111,7 +111,9 @@ @Before public void setUp() throws Exception { - conf = MetastoreConf.newMetastoreConf(); + if (conf == null) { + conf = MetastoreConf.newMetastoreConf(); + } warehouse = new Warehouse(conf); // set some values to use for getting conf. vars @@ -2875,7 +2877,7 @@ private void createFunction(String dbName, String funcName, String className, @Test public void testRetriableClientWithConnLifetime() throws Exception { - Configuration conf = MetastoreConf.newMetastoreConf(); + Configuration conf = MetastoreConf.newMetastoreConf(new Configuration(this.conf)); MetastoreConf.setTimeVar(conf, ConfVars.CLIENT_SOCKET_LIFETIME, 4, TimeUnit.SECONDS); MetaStoreTestUtils.setConfForStandloneMode(conf); long timeout = 5 * 1000; // Lets use a timeout more than the socket lifetime to simulate a reconnect