diff --git hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatMultiOutputFormat.java hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatMultiOutputFormat.java index 7de2bbf..d9de10e 100644 --- hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatMultiOutputFormat.java +++ hcatalog/core/src/test/java/org/apache/hive/hcatalog/mapreduce/TestHCatMultiOutputFormat.java @@ -40,6 +40,7 @@ import org.apache.hadoop.hive.metastore.api.SerDeInfo; import org.apache.hadoop.hive.metastore.api.StorageDescriptor; import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; import org.apache.hadoop.hive.ql.CompilationOpContext; import org.apache.hadoop.hive.ql.QueryState; import org.apache.hadoop.hive.ql.exec.FetchTask; @@ -161,7 +162,10 @@ public static void setup() throws Exception { metastoreConf.setVar(HiveConf.ConfVars.METASTOREWAREHOUSE, warehousedir.toString()); // Run hive metastore server - msPort = MetaStoreTestUtils.startMetaStore(metastoreConf); + msPort = MetaStoreTestUtils.startMetaStoreWithRetry(metastoreConf); + // Read the warehouse dir, which can be changed so multiple MetaStore tests could be run on + // the same server + warehousedir = new Path(MetastoreConf.getVar(metastoreConf, MetastoreConf.ConfVars.WAREHOUSE)); // LocalJobRunner does not work with mapreduce OutputCommitter. So need // to use MiniMRCluster. MAPREDUCE-2350 Configuration conf = new Configuration(true); diff --git hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java index 515eef2..f9ee9d9 100644 --- hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java +++ hcatalog/webhcat/java-client/src/test/java/org/apache/hive/hcatalog/api/TestHCatClient.java @@ -120,7 +120,7 @@ public static void startMetaStoreServer() throws Exception { System.setProperty(HiveConf.ConfVars.METASTORE_TRANSACTIONAL_EVENT_LISTENERS.varname, DbNotificationListener.class.getName()); // turn on db notification listener on metastore - msPort = MetaStoreTestUtils.startMetaStore(); + msPort = MetaStoreTestUtils.startMetaStoreWithRetry(); securityManager = System.getSecurityManager(); System.setSecurityManager(new NoExitSecurityManager()); Policy.setPolicy(new DerbyPolicy()); @@ -178,7 +178,8 @@ public void testBasicDDLCommands() throws Exception { if (useExternalMS) { assertTrue(testDb.getLocation().matches(".*" + "/" + db + ".db")); } else { - String expectedDir = warehouseDir.replaceFirst("pfile:///", "pfile:/"); + String expectedDir = warehouseDir.replaceFirst("pfile:///", "pfile:/") + + "/" + msPort; assertEquals(expectedDir + "/" + db + ".db", testDb.getLocation()); } ArrayList cols = new ArrayList(); @@ -809,7 +810,7 @@ private void startReplicationTargetMetaStoreIfRequired() throws Exception { HiveConf conf = new HiveConf(); conf.set("javax.jdo.option.ConnectionURL", hcatConf.get("javax.jdo.option.ConnectionURL") .replace("metastore", "target_metastore")); - replicationTargetHCatPort = MetaStoreTestUtils.startMetaStore(conf); + replicationTargetHCatPort = MetaStoreTestUtils.startMetaStoreWithRetry(conf); replicationTargetHCatConf = new HiveConf(hcatConf); replicationTargetHCatConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + replicationTargetHCatPort); diff --git itests/hive-unit-hadoop2/src/test/java/org/apache/hadoop/hive/metastore/security/TestHadoopAuthBridge23.java itests/hive-unit-hadoop2/src/test/java/org/apache/hadoop/hive/metastore/security/TestHadoopAuthBridge23.java index f979baf..df7c521 100644 --- itests/hive-unit-hadoop2/src/test/java/org/apache/hadoop/hive/metastore/security/TestHadoopAuthBridge23.java +++ itests/hive-unit-hadoop2/src/test/java/org/apache/hadoop/hive/metastore/security/TestHadoopAuthBridge23.java @@ -140,17 +140,12 @@ private void configureSuperUserIPAddresses(Configuration conf, @Before public void setup() throws Exception { isMetastoreTokenManagerInited = false; - int port = findFreePort(); System.setProperty(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL.varname, "true"); - System.setProperty(HiveConf.ConfVars.METASTOREURIS.varname, - "thrift://localhost:" + port); - System.setProperty(HiveConf.ConfVars.METASTOREWAREHOUSE.varname, new Path( - System.getProperty("test.build.data", "/tmp")).toString()); System.setProperty(HiveConf.ConfVars.METASTORE_CLUSTER_DELEGATION_TOKEN_STORE_CLS.varname, MyTokenStore.class.getName()); conf = new HiveConf(TestHadoopAuthBridge23.class); - MetaStoreTestUtils.startMetaStore(port, new MyHadoopThriftAuthBridge23()); + MetaStoreTestUtils.startMetaStoreWithRetry(new MyHadoopThriftAuthBridge23(), conf); } /** diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/AbstractTestAuthorizationApiAuthorizer.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/AbstractTestAuthorizationApiAuthorizer.java index 439cf56..abd5e32 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/AbstractTestAuthorizationApiAuthorizer.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/AbstractTestAuthorizationApiAuthorizer.java @@ -58,8 +58,7 @@ protected static void setup() throws Exception { hiveConf = new HiveConf(); if (isRemoteMetastoreMode) { - int port = MetaStoreTestUtils.startMetaStoreWithRetry(); - hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + port); + MetaStoreTestUtils.startMetaStoreWithRetry(hiveConf); } hiveConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3); hiveConf.set(HiveConf.ConfVars.PREEXECHOOKS.varname, ""); diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreAuthorization.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreAuthorization.java index 6c4491e..747efd8 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreAuthorization.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreAuthorization.java @@ -18,8 +18,6 @@ package org.apache.hadoop.hive.metastore; -import java.io.IOException; -import java.net.ServerSocket; import java.util.concurrent.TimeUnit; import org.apache.hadoop.fs.FileSystem; @@ -30,7 +28,6 @@ import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.metastore.api.NoSuchObjectException; -import org.apache.hadoop.hive.metastore.security.HadoopThriftAuthBridge; import junit.framework.TestCase; @@ -41,17 +38,13 @@ private int port; public void setup() throws Exception { - port = findFreePort(); - System.setProperty(HiveConf.ConfVars.METASTORE_AUTHORIZATION_STORAGE_AUTH_CHECKS.varname, - "true"); - conf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + port); + conf.setBoolVar(HiveConf.ConfVars.METASTORE_AUTHORIZATION_STORAGE_AUTH_CHECKS, true); conf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3); conf.setTimeVar(ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY, 60, TimeUnit.SECONDS); } public void testIsWritable() throws Exception { setup(); - conf = new HiveConf(this.getClass()); String testDir = System.getProperty("test.warehouse.dir", "/tmp"); Path testDirPath = new Path(testDir); FileSystem fs = testDirPath.getFileSystem(conf); @@ -75,7 +68,7 @@ public void testIsWritable() throws Exception { public void testMetaStoreAuthorization() throws Exception { setup(); - MetaStoreTestUtils.startMetaStore(port, HadoopThriftAuthBridge.getBridge()); + MetaStoreTestUtils.startMetaStoreWithRetry(conf); HiveMetaStoreClient client = new HiveMetaStoreClient(conf); FileSystem fs = null; @@ -116,11 +109,4 @@ public void testMetaStoreAuthorization() throws Exception { } } } - - private int findFreePort() throws IOException { - ServerSocket socket= new ServerSocket(0); - int port = socket.getLocalPort(); - socket.close(); - return port; - } } diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreMetrics.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreMetrics.java index 25186c9..f671fe7 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreMetrics.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreMetrics.java @@ -19,6 +19,7 @@ import org.apache.hadoop.hive.cli.CliSessionState; import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; import org.apache.hadoop.hive.metastore.metrics.Metrics; import org.apache.hadoop.hive.metastore.metrics.MetricsConstants; import org.apache.hadoop.hive.ql.DriverFactory; @@ -49,9 +50,7 @@ public static void before() throws Exception { "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory"); //Increments one HMS connection - int port = MetaStoreTestUtils.startMetaStoreWithRetry(hiveConf); - - hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + port); + MetaStoreTestUtils.startMetaStoreWithRetry(hiveConf); //Increments one HMS connection (Hive.get()) SessionState.start(new CliSessionState(hiveConf)); diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java index 41c89b1..6f4fe64 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/TestReplicationScenarios.java @@ -45,6 +45,7 @@ import org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint; import org.apache.hadoop.hive.metastore.api.Table; import org.apache.hadoop.hive.metastore.api.UniqueConstraintsRequest; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf; import org.apache.hadoop.hive.metastore.messaging.MessageFactory; import org.apache.hadoop.hive.metastore.messaging.event.filters.AndFilter; import org.apache.hadoop.hive.metastore.messaging.event.filters.DatabaseAndTableFilter; @@ -98,12 +99,10 @@ System.getProperty("test.warehouse.dir", "/tmp") + Path.SEPARATOR + tid; private static HiveConf hconf; - private static int msPort; private static IDriver driver; private static HiveMetaStoreClient metaStoreClient; private static String proxySettingName; static HiveConf hconfMirror; - static int msPortMirror; static IDriver driverMirror; static HiveMetaStoreClient metaStoreClientMirror; @@ -139,10 +138,8 @@ public static void setUpBeforeClass() throws Exception { hconf.setVar(HiveConf.ConfVars.REPLCMDIR, TEST_PATH + "/cmroot/"); proxySettingName = "hadoop.proxyuser." + Utils.getUGI().getShortUserName() + ".hosts"; hconf.set(proxySettingName, "*"); - msPort = MetaStoreTestUtils.startMetaStore(hconf); + MetaStoreTestUtils.startMetaStoreWithRetry(hconf); hconf.setVar(HiveConf.ConfVars.REPLDIR,TEST_PATH + "/hrepl/"); - hconf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" - + msPort); hconf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3); hconf.set(HiveConf.ConfVars.PREEXECHOOKS.varname, ""); hconf.set(HiveConf.ConfVars.POSTEXECHOOKS.varname, ""); @@ -166,10 +163,10 @@ public static void setUpBeforeClass() throws Exception { FileUtils.deleteDirectory(new File("metastore_db2")); HiveConf hconfMirrorServer = new HiveConf(); hconfMirrorServer.set(HiveConf.ConfVars.METASTORECONNECTURLKEY.varname, "jdbc:derby:;databaseName=metastore_db2;create=true"); - msPortMirror = MetaStoreTestUtils.startMetaStore(hconfMirrorServer); + MetaStoreTestUtils.startMetaStoreWithRetry(hconfMirrorServer); hconfMirror = new HiveConf(hconf); - hconfMirror.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" - + msPortMirror); + String thriftUri = MetastoreConf.getVar(hconfMirrorServer, MetastoreConf.ConfVars.THRIFT_URIS); + MetastoreConf.setVar(hconfMirror, MetastoreConf.ConfVars.THRIFT_URIS, thriftUri); driverMirror = DriverFactory.newDriver(hconfMirror); metaStoreClientMirror = new HiveMetaStoreClient(hconfMirror); diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/WarehouseInstance.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/WarehouseInstance.java index 33e5157..4ea7201 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/WarehouseInstance.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/parse/WarehouseInstance.java @@ -126,8 +126,7 @@ private void initialize(String cmRoot, String warehouseRoot, System.setProperty(HiveConf.ConfVars.PREEXECHOOKS.varname, " "); System.setProperty(HiveConf.ConfVars.POSTEXECHOOKS.varname, " "); - int metaStorePort = MetaStoreTestUtils.startMetaStore(hiveConf); - hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + metaStorePort); + MetaStoreTestUtils.startMetaStoreWithRetry(hiveConf); Path testPath = new Path(hiveWarehouseLocation); FileSystem testPathFileSystem = FileSystem.get(testPath.toUri(), hiveConf); diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/StorageBasedMetastoreTestBase.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/StorageBasedMetastoreTestBase.java index 1729893..b3383d9 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/StorageBasedMetastoreTestBase.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/StorageBasedMetastoreTestBase.java @@ -72,12 +72,11 @@ public void setUp() throws Exception { InjectableDummyAuthenticator.class.getName()); clientHiveConf = createHiveConf(); - int port = MetaStoreTestUtils.startMetaStoreWithRetry(clientHiveConf); + MetaStoreTestUtils.startMetaStoreWithRetry(clientHiveConf); // Turn off client-side authorization clientHiveConf.setBoolVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_ENABLED,false); - clientHiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + port); clientHiveConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3); clientHiveConf.set(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false"); 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 8bbf8a4..ef3a3bf 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 @@ -335,8 +335,7 @@ public MiniHS2(HiveConf hiveConf, MiniClusterType clusterType, boolean usePortsF public void start(Map confOverlay) throws Exception { if (isMetastoreRemote) { - int metaStorePort = MetaStoreTestUtils.startMetaStoreWithRetry(getHiveConf()); - getHiveConf().setVar(ConfVars.METASTOREURIS, "thrift://localhost:" + metaStorePort); + MetaStoreTestUtils.startMetaStoreWithRetry(getHiveConf()); } // Set confOverlay parameters diff --git ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveRemote.java ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveRemote.java index 08536f0..eccca48 100644 --- ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveRemote.java +++ ql/src/test/org/apache/hadoop/hive/ql/metadata/TestHiveRemote.java @@ -43,7 +43,7 @@ protected void setUp() throws Exception { hiveConf .setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory"); - hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + MetaStoreTestUtils.startMetaStore()); + MetaStoreTestUtils.startMetaStoreWithRetry(hiveConf); try { hm = Hive.get(hiveConf); 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 d4820b3..19fdb58 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 @@ -33,30 +33,19 @@ import org.slf4j.LoggerFactory; public class MetaStoreTestUtils { - private static final Logger LOG = LoggerFactory.getLogger(MetaStoreTestUtils.class); public static final int RETRY_COUNT = 10; - public static int startMetaStore() throws Exception { - return MetaStoreTestUtils.startMetaStore(HadoopThriftAuthBridge.getBridge(), null); - } - - public static int startMetaStore(final HadoopThriftAuthBridge bridge, Configuration conf) - throws Exception { - int port = MetaStoreTestUtils.findFreePort(); - MetaStoreTestUtils.startMetaStore(port, bridge, conf); - return port; - } - - public static int startMetaStore(Configuration conf) throws Exception { - return startMetaStore(HadoopThriftAuthBridge.getBridge(), conf); - } - - - public static void startMetaStore(final int port, final HadoopThriftAuthBridge bridge) throws Exception { - MetaStoreTestUtils.startMetaStore(port, bridge, null); - } - + /** + * Starts a MetaStore instance on get given port with the given configuration and Thrift bridge. + * Use it only it the port is definitely free. For tests use startMetaStoreWithRetry instead so + * the MetaStore will find an emtpy port eventually, so the different tests can be run on the + * same machine. + * @param port The port to start on + * @param bridge The bridge to use + * @param conf The configuration to use + * @throws Exception + */ public static void startMetaStore(final int port, final HadoopThriftAuthBridge bridge, Configuration conf) throws Exception{ @@ -73,14 +62,14 @@ public void run() { LOG.error("Metastore Thrift Server threw an exception...", e); } } - }); + }, "MetaStoreThread-" + port); thread.setDaemon(true); thread.start(); MetaStoreTestUtils.loopUntilHMSReady(port); } public static int startMetaStoreWithRetry(final HadoopThriftAuthBridge bridge) throws Exception { - return MetaStoreTestUtils.startMetaStoreWithRetry(bridge, null); + return MetaStoreTestUtils.startMetaStoreWithRetry(bridge, MetastoreConf.newMetastoreConf()); } public static int startMetaStoreWithRetry(Configuration conf) throws Exception { @@ -88,23 +77,33 @@ public static int startMetaStoreWithRetry(Configuration conf) throws Exception { } public static int startMetaStoreWithRetry() throws Exception { - return MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), null); - } - - public static int startMetaStoreWithRetry(final HadoopThriftAuthBridge bridge, Configuration conf) - throws Exception { - int metaStorePort = findFreePort(); - startMetaStoreWithRetry(metaStorePort, bridge, conf); - return metaStorePort; + return MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), + MetastoreConf.newMetastoreConf()); } - private static void startMetaStoreWithRetry(int port, HadoopThriftAuthBridge bridge, - Configuration conf) throws Exception { + /** + * Starts a MetaStore instance with the given configuration and given bridge. + * Tries to find a free port, and use it. If failed tries another port so the tests will not + * fail if run parallel. Also adds the port to the warehouse dir, so the multiple MetaStore + * instances will use different warehouse directories. + * @param bridge The Thrift bridge to uses + * @param conf The configuration to use + * @return The port on which the MetaStore finally started + * @throws Exception + */ + public static int startMetaStoreWithRetry(HadoopThriftAuthBridge bridge, + Configuration conf) throws Exception { Exception metaStoreException = null; + String warehouseDir = MetastoreConf.getVar(conf, ConfVars.WAREHOUSE); for (int tryCount = 0; tryCount < MetaStoreTestUtils.RETRY_COUNT; tryCount++) { try { - MetaStoreTestUtils.startMetaStore(port, bridge, conf); - return; + int metaStorePort = findFreePort(); + MetastoreConf.setVar(conf, ConfVars.WAREHOUSE, warehouseDir + "/" + metaStorePort); + 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, warehouseDir); + return metaStorePort; } catch (ConnectException ce) { metaStoreException = ce; } @@ -116,7 +115,7 @@ private static void startMetaStoreWithRetry(int port, HadoopThriftAuthBridge bri * A simple connect test to make sure that the metastore is up * @throws Exception */ - public static void loopUntilHMSReady(int port) throws Exception { + private static void loopUntilHMSReady(int port) throws Exception { int retries = 0; Exception exc = null; while (true) { @@ -141,7 +140,7 @@ public static void loopUntilHMSReady(int port) throws Exception { throw exc; } - public static String getAllThreadStacksAsString() { + private static String getAllThreadStacksAsString() { Map threadStacks = Thread.getAllStackTraces(); StringBuilder sb = new StringBuilder(); for (Map.Entry entry : threadStacks.entrySet()) { @@ -153,7 +152,7 @@ public static String getAllThreadStacksAsString() { return sb.toString(); } - public static void addStackString(StackTraceElement[] stackElems, StringBuilder sb) { + private static void addStackString(StackTraceElement[] stackElems, StringBuilder sb) { sb.append(System.lineSeparator()); for (StackTraceElement stackElem : stackElems) { sb.append(stackElem).append(System.lineSeparator()); diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestFilterHooks.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestFilterHooks.java index 45a65e0..371e03b 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestFilterHooks.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestFilterHooks.java @@ -178,8 +178,7 @@ public static void setUp() throws Exception { MetastoreConf.setClass(conf, ConfVars.FILTER_HOOK, DummyMetaStoreFilterHookImpl.class, MetaStoreFilterHook.class); MetaStoreTestUtils.setConfForStandloneMode(conf); - int port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); - MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); msc = new HiveMetaStoreClient(conf); diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java index 0a97b27..b2d1d5a 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStorePartitionSpecs.java @@ -70,7 +70,7 @@ public static void startMetaStoreServer() throws Exception { MetastoreConf.setClass(metastoreConf, ConfVars.EXPRESSION_PROXY_CLASS, MockPartitionExpressionForMetastore.class, PartitionExpressionProxy.class); MetaStoreTestUtils.setConfForStandloneMode(metastoreConf); - msPort = MetaStoreTestUtils.startMetaStore(metastoreConf); + msPort = MetaStoreTestUtils.startMetaStoreWithRetry(metastoreConf); conf = MetastoreConf.newMetastoreConf(); MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + msPort); MetastoreConf.setLongVar(conf, ConfVars.THRIFT_CONNECTION_RETRIES, 3); diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreWithEnvironmentContext.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreWithEnvironmentContext.java index 42e77a6..d53a606 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreWithEnvironmentContext.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStoreWithEnvironmentContext.java @@ -75,8 +75,7 @@ public void setUp() throws Exception { MetastoreConf.setLongVar(conf, ConfVars.THRIFT_CONNECTION_RETRIES, 3); MetastoreConf.setBoolVar(conf, ConfVars.HIVE_SUPPORT_CONCURRENCY, false); MetaStoreTestUtils.setConfForStandloneMode(conf); - int port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); - MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); msc = new HiveMetaStoreClient(conf); msc.dropDatabase(dbName, true, true); diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMarkPartitionRemote.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMarkPartitionRemote.java index 55f3324..8cf0f8e 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMarkPartitionRemote.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMarkPartitionRemote.java @@ -30,10 +30,7 @@ @Before public void startServer() throws Exception { - int port = MetaStoreTestUtils.findFreePort(); - MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); - MetastoreConf.setLongVar(conf, ConfVars.THRIFT_CONNECTION_RETRIES, 3); MetaStoreTestUtils.setConfForStandloneMode(conf); - MetaStoreTestUtils.startMetaStore(port, HadoopThriftAuthBridge.getBridge(), conf); + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); } } diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java index bfc819e..1a720fb 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEndFunctionListener.java @@ -57,8 +57,7 @@ public void setUp() throws Exception { MetastoreConf.setLongVar(conf, ConfVars.THRIFT_CONNECTION_RETRIES, 3); MetastoreConf.setBoolVar(conf, ConfVars.HIVE_SUPPORT_CONCURRENCY, false); MetaStoreTestUtils.setConfForStandloneMode(conf); - int port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); - MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); msc = new HiveMetaStoreClient(conf); } diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java index 879e611..607e231 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListener.java @@ -111,8 +111,7 @@ public void setUp() throws Exception { MetastoreConf.setLongVar(conf, ConfVars.THRIFT_CONNECTION_RETRIES, 3); MetastoreConf.setBoolVar(conf, ConfVars.HIVE_SUPPORT_CONCURRENCY, false); MetaStoreTestUtils.setConfForStandloneMode(conf); - int port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); - MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); msc = new HiveMetaStoreClient(conf); diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListenerOnlyOnCommit.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListenerOnlyOnCommit.java index 062520b..a91d1c8 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListenerOnlyOnCommit.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListenerOnlyOnCommit.java @@ -63,8 +63,7 @@ public void setUp() throws Exception { MetastoreConf.setLongVar(conf, ConfVars.THRIFT_CONNECTION_RETRIES, 3); MetastoreConf.setBoolVar(conf, ConfVars.HIVE_SUPPORT_CONCURRENCY, false); MetaStoreTestUtils.setConfForStandloneMode(conf); - int port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); - MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); msc = new HiveMetaStoreClient(conf); DummyListener.notifyList.clear(); diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListenerWithOldConf.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListenerWithOldConf.java index a9d9e78..6fa059c 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListenerWithOldConf.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreEventListenerWithOldConf.java @@ -99,15 +99,13 @@ public void setUp() throws Exception { System.setProperty("hive.metastore.pre.event.listeners", DummyPreListener.class.getName()); - int port = MetaStoreTestUtils.findFreePort(); conf = MetastoreConf.newMetastoreConf(); MetastoreConf.setVar(conf, ConfVars.PARTITION_NAME_WHITELIST_PATTERN, metaConfVal); - MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); MetastoreConf.setLongVar(conf, ConfVars.THRIFT_CONNECTION_RETRIES, 3); MetastoreConf.setBoolVar(conf, ConfVars.HIVE_SUPPORT_CONCURRENCY, false); MetaStoreTestUtils.setConfForStandloneMode(conf); - MetaStoreTestUtils.startMetaStore(port, HadoopThriftAuthBridge.getBridge(), conf); + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); DummyListener.notifyList.clear(); DummyPreListener.notifyList.clear(); diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreInitListener.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreInitListener.java index fd8fde4..b78076b 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreInitListener.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestMetaStoreInitListener.java @@ -43,8 +43,7 @@ public void setUp() throws Exception { MetastoreConf.setLongVar(conf, ConfVars.THRIFT_CONNECTION_RETRIES, 3); MetastoreConf.setBoolVar(conf, ConfVars.HIVE_SUPPORT_CONCURRENCY, false); MetaStoreTestUtils.setConfForStandloneMode(conf); - int port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); - MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); } @Test diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestRemoteHiveMetaStoreIpAddress.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestRemoteHiveMetaStoreIpAddress.java index e26a97d..6b7d913 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestRemoteHiveMetaStoreIpAddress.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestRemoteHiveMetaStoreIpAddress.java @@ -50,9 +50,7 @@ public void setUp() throws Exception { System.setProperty(ConfVars.EVENT_LISTENERS.toString(), IpAddressListener.class.getName()); MetaStoreTestUtils.setConfForStandloneMode(conf); - int port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); - LOG.debug("Starting MetaStore Server on port " + port); - MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); msc = new HiveMetaStoreClient(conf); } diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestRetryingHMSHandler.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestRetryingHMSHandler.java index b72cc09..11f84f2 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestRetryingHMSHandler.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/TestRetryingHMSHandler.java @@ -52,8 +52,7 @@ public void setUp() throws Exception { MetastoreConf.setTimeVar(conf, ConfVars.HMSHANDLERINTERVAL, 0, TimeUnit.MILLISECONDS); MetastoreConf.setBoolVar(conf, ConfVars.HMSHANDLERFORCERELOADCONF, false); MetaStoreTestUtils.setConfForStandloneMode(conf); - int port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); - MetastoreConf.setVar(conf, ConfVars.THRIFT_URIS, "thrift://localhost:" + port); + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf); msc = new HiveMetaStoreClient(conf); } diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/minihms/RemoteMetaStoreForTests.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/minihms/RemoteMetaStoreForTests.java index 4249991..b32d761 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/minihms/RemoteMetaStoreForTests.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/minihms/RemoteMetaStoreForTests.java @@ -36,10 +36,8 @@ public RemoteMetaStoreForTests(Configuration configuration) { public void start() throws Exception { MetastoreConf.setBoolVar(getConfiguration(), MetastoreConf.ConfVars.EXECUTE_SET_UGI, false); - int port = MetaStoreTestUtils.startMetaStore(HadoopThriftAuthBridge.getBridge(), + MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), getConfiguration()); - MetastoreConf.setVar(getConfiguration(), MetastoreConf.ConfVars.THRIFT_URIS, - "thrift://localhost:" + port); super.start(); } }