You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2012/04/18 19:33:41 UTC
svn commit: r1327591 -
/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestRemoteHiveMetaStoreIpAddress.java
Author: hashutosh
Date: Wed Apr 18 17:33:41 2012
New Revision: 1327591
URL: http://svn.apache.org/viewvc?rev=1327591&view=rev
Log:
HIVE-2959 [jira] TestRemoteHiveMetaStoreIpAddress always uses the same port
(Kevin Wilfong via Ashutosh Chauhan)
Summary:
https://issues.apache.org/jira/browse/HIVE-2959
TestRemoteHiveMetaStoreIpAddress now uses the standard way of finding a free
port using Java's ServerSocket class.
TestRemoteHiveMetaStoreIpAddress always uses the same port, meaning that if
another process happens to be using that port, the tests cannot succeed.
There seems to be a standard way of finding a free port using Java's
ServerSocket class, this should be used instead.
Test Plan: Ran TestRemoteHiveMetaStoreIpAddress and
TestRemoteUGIHiveMetaStoreIpAddress, the two tests which would be affected by
this change. I verified they passed and did not use port 39083.
Reviewers: JIRA, njain, ashutoshc
Reviewed By: ashutoshc
Differential Revision: https://reviews.facebook.net/D2841
Modified:
hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestRemoteHiveMetaStoreIpAddress.java
Modified: hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestRemoteHiveMetaStoreIpAddress.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestRemoteHiveMetaStoreIpAddress.java?rev=1327591&r1=1327590&r2=1327591&view=diff
==============================================================================
--- hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestRemoteHiveMetaStoreIpAddress.java (original)
+++ hive/trunk/metastore/src/test/org/apache/hadoop/hive/metastore/TestRemoteHiveMetaStoreIpAddress.java Wed Apr 18 17:33:41 2012
@@ -18,6 +18,9 @@
package org.apache.hadoop.hive.metastore;
+import java.io.IOException;
+import java.net.ServerSocket;
+
import junit.framework.TestCase;
import org.apache.hadoop.hive.conf.HiveConf;
@@ -33,19 +36,25 @@ import org.apache.hadoop.util.StringUtil
* IpAddressListener
*/
public class TestRemoteHiveMetaStoreIpAddress extends TestCase {
- protected static final String METASTORE_PORT = "39083";
private static boolean isServerStarted = false;
private static HiveConf hiveConf;
private static HiveMetaStoreClient msc;
+ private String port;
+
private static class RunMS implements Runnable {
+ String port;
+
+ public RunMS(String port) {
+ this.port = port;
+ }
@Override
public void run() {
try {
System.setProperty(ConfVars.METASTORE_EVENT_LISTENERS.varname,
IpAddressListener.class.getName());
- HiveMetaStore.main(new String[] { METASTORE_PORT });
+ HiveMetaStore.main(new String[] { port });
} catch (Throwable e) {
e.printStackTrace(System.err);
assert false;
@@ -58,14 +67,15 @@ public class TestRemoteHiveMetaStoreIpAd
protected void setUp() throws Exception {
super.setUp();
hiveConf = new HiveConf(this.getClass());
+ port = findFreePort();
if (isServerStarted) {
assertNotNull("Unable to connect to the MetaStore server", msc);
return;
}
- System.out.println("Starting MetaStore Server on port " + METASTORE_PORT);
- Thread t = new Thread(new RunMS());
+ System.out.println("Starting MetaStore Server on port " + port);
+ Thread t = new Thread(new RunMS(port));
t.start();
isServerStarted = true;
@@ -92,7 +102,14 @@ public class TestRemoteHiveMetaStoreIpAd
protected void createClient() throws Exception {
hiveConf.setBoolVar(ConfVars.METASTORE_MODE, false);
- hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + METASTORE_PORT);
+ hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + port);
msc = new HiveMetaStoreClient(hiveConf);
}
+
+ private String findFreePort() throws IOException {
+ ServerSocket socket= new ServerSocket(0);
+ int port = socket.getLocalPort();
+ socket.close();
+ return String.valueOf(port);
+ }
}