Get random port later

Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e02b3a27
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e02b3a27
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e02b3a27

Branch: refs/heads/omid2
Commit: e02b3a27880a8edf512f8db803666fcb599e245b
Parents: 1c21103
Author: James Taylor <jamestay...@apache.org>
Authored: Fri Nov 16 07:50:41 2018 -0800
Committer: James Taylor <jamestay...@apache.org>
Committed: Fri Nov 16 07:50:41 2018 -0800

----------------------------------------------------------------------
 .../end2end/ConnectionQueryServicesTestImpl.java      |  4 +++-
 .../phoenix/transaction/OmidTransactionProvider.java  | 11 +----------
 .../transaction/PhoenixTransactionProvider.java       |  2 +-
 .../transaction/TephraTransactionProvider.java        |  3 ++-
 .../java/org/apache/phoenix/util/TransactionUtil.java | 14 --------------
 .../apache/phoenix/query/QueryServicesTestImpl.java   |  3 +--
 .../test/java/org/apache/phoenix/util/TestUtil.java   | 14 ++++++++++++++
 7 files changed, 22 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e02b3a27/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
index 6ebaa65..969e0f4 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConnectionQueryServicesTestImpl.java
@@ -35,6 +35,7 @@ import 
org.apache.phoenix.transaction.PhoenixTransactionService;
 import org.apache.phoenix.transaction.TransactionFactory;
 import org.apache.phoenix.transaction.TransactionFactory.Provider;
 import org.apache.phoenix.util.SQLCloseables;
+import org.apache.phoenix.util.TestUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -102,7 +103,8 @@ public class ConnectionQueryServicesTestImpl extends 
ConnectionQueryServicesImpl
     public synchronized PhoenixTransactionClient 
initTransactionClient(Provider provider) throws SQLException {
         PhoenixTransactionService txService = txServices[provider.ordinal()];
         if (txService == null) {
-            txService = txServices[provider.ordinal()] = 
provider.getTransactionProvider().getTransactionService(config, connectionInfo);
+            int port = TestUtil.getRandomPort();
+            txService = txServices[provider.ordinal()] = 
provider.getTransactionProvider().getTransactionService(config, connectionInfo, 
port);
         }
         return super.initTransactionClient(provider);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e02b3a27/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
index c4769b7..1646a92 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/transaction/OmidTransactionProvider.java
@@ -120,19 +120,10 @@ public class OmidTransactionProvider implements 
PhoenixTransactionProvider {
     }
     
     @Override
-    public PhoenixTransactionService getTransactionService(Configuration 
config, ConnectionInfo connectionInfo) throws  SQLException{
+    public PhoenixTransactionService getTransactionService(Configuration 
config, ConnectionInfo connectionInfo, int port) throws  SQLException{
         TSOServerConfig tsoConfig = new TSOServerConfig();
         TSOServer tso;
 
-        int port;
-        String portStr = config.get(OMID_TSO_PORT);
-        if (portStr == null) {
-            // setup default test configs for Omid
-            port = TransactionUtil.getRandomPort();
-        } else {
-            port = Integer.parseInt(portStr);
-        }
-
         tsoConfig.setPort(port);
         tsoConfig.setConflictMapSize(config.getInt(OMID_TSO_CONFLICT_MAP_SIZE, 
DEFAULT_OMID_TSO_CONFLICT_MAP_SIZE));
         tsoConfig.setTimestampType(config.get(OMID_TSO_TIMESTAMP_TYPE, 
DEFAULT_OMID_TSO_TIMESTAMP_TYPE));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e02b3a27/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
index b7f660e..3af554b 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
@@ -50,7 +50,7 @@ public interface PhoenixTransactionProvider {
     public PhoenixTransactionContext getTransactionContext(PhoenixConnection 
connection) throws SQLException;
 
     public PhoenixTransactionClient getTransactionClient(Configuration config, 
ConnectionInfo connectionInfo) throws SQLException;
-    public PhoenixTransactionService getTransactionService(Configuration 
config, ConnectionInfo connectionInfo) throws  SQLException;
+    public PhoenixTransactionService getTransactionService(Configuration 
config, ConnectionInfo connectionInfo, int port) throws  SQLException;
     public Class<? extends RegionObserver> getCoprocessor();
     public Class<? extends RegionObserver> getGCCoprocessor();
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e02b3a27/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionProvider.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionProvider.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionProvider.java
index 060aaf4..7025e5b 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionProvider.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/transaction/TephraTransactionProvider.java
@@ -111,7 +111,8 @@ public class TephraTransactionProvider implements 
PhoenixTransactionProvider {
     }
 
     @Override
-    public PhoenixTransactionService getTransactionService(Configuration 
config, ConnectionInfo connInfo) {
+    public PhoenixTransactionService getTransactionService(Configuration 
config, ConnectionInfo connInfo, int port) {
+        config.setInt(TxConstants.Service.CFG_DATA_TX_BIND_PORT, port);
         int retryTimeOut = 
config.getInt(TxConstants.Service.CFG_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC, 
                 
TxConstants.Service.DEFAULT_DATA_TX_CLIENT_DISCOVERY_TIMEOUT_SEC);
         ZKClientService zkClient = ZKClientServices.delegate(

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e02b3a27/phoenix-core/src/main/java/org/apache/phoenix/util/TransactionUtil.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/util/TransactionUtil.java 
b/phoenix-core/src/main/java/org/apache/phoenix/util/TransactionUtil.java
index 9a352c0..dee02d1 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/TransactionUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/TransactionUtil.java
@@ -18,7 +18,6 @@
 package org.apache.phoenix.util;
 
 import java.io.IOException;
-import java.net.ServerSocket;
 import java.sql.SQLException;
 import java.util.List;
 import java.util.Map;
@@ -153,17 +152,4 @@ public class TransactionUtil {
         }
         return mutation;
        }
-
-    /**
-     * Find a random free port in localhost for binding.
-     * @return A port number or -1 for failure.
-     */
-    public static int getRandomPort() {
-        try (ServerSocket socket = new ServerSocket(0)) {
-            socket.setReuseAddress(true);
-            return socket.getLocalPort();
-        } catch (IOException e) {
-            return -1;
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e02b3a27/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
index db9a8c9..a64f8d2 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java
@@ -24,7 +24,7 @@ import org.apache.curator.shaded.com.google.common.io.Files;
 import org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.ReadOnlyProps;
-import org.apache.phoenix.util.TransactionUtil;
+import org.apache.phoenix.util.TestUtil;
 import org.apache.tephra.TxConstants;
 
 
@@ -128,7 +128,6 @@ public final class QueryServicesTestImpl extends 
BaseQueryServicesImpl {
                 .set(TxConstants.Manager.CFG_DO_PERSIST, false)
                 .set(TxConstants.Service.CFG_DATA_TX_CLIENT_RETRY_STRATEGY, 
"n-times")
                 .set(TxConstants.Service.CFG_DATA_TX_CLIENT_ATTEMPTS, 1)
-                .set(TxConstants.Service.CFG_DATA_TX_BIND_PORT, 
TransactionUtil.getRandomPort())
                 .set(TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, 
Files.createTempDir().getAbsolutePath())
                 .set(TxConstants.Manager.CFG_TX_TIMEOUT, 
DEFAULT_TXN_TIMEOUT_SECONDS)
                 .set(TxConstants.Manager.CFG_TX_SNAPSHOT_INTERVAL, 5L)

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e02b3a27/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java 
b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index f0a26b9..d2649e1 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -36,6 +36,7 @@ import static org.junit.Assert.fail;
 import java.io.File;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.net.ServerSocket;
 import java.sql.Connection;
 import java.sql.Date;
 import java.sql.DriverManager;
@@ -1105,4 +1106,17 @@ public class TestUtil {
         }
         return filteredData;
     }
+
+    /**
+     * Find a random free port in localhost for binding.
+     * @return A port number or -1 for failure.
+     */
+    public static int getRandomPort() {
+        try (ServerSocket socket = new ServerSocket(0)) {
+            socket.setReuseAddress(true);
+            return socket.getLocalPort();
+        } catch (IOException e) {
+            return -1;
+        }
+    }
 }

Reply via email to