PHOENIX-5013 Increase timeout for Tephra discovery service
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/169270da Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/169270da Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/169270da Branch: refs/heads/omid2 Commit: 169270daa894628f3dacf2957ef6cfc8a99d2f6a Parents: d1efd66 Author: James Taylor <jamestay...@apache.org> Authored: Sat Nov 10 11:07:02 2018 -0800 Committer: James Taylor <jamestay...@apache.org> Committed: Sat Nov 10 11:07:02 2018 -0800 ---------------------------------------------------------------------- .../apache/phoenix/query/QueryServicesTestImpl.java | 6 +++--- .../test/java/org/apache/phoenix/util/TestUtil.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/169270da/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 841abb6..49fb8e8 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 @@ -25,8 +25,8 @@ import org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec; import org.apache.phoenix.transaction.OmidTransactionProvider; import org.apache.phoenix.util.PhoenixRuntime; import org.apache.phoenix.util.ReadOnlyProps; +import org.apache.phoenix.util.TestUtil; import org.apache.tephra.TxConstants; -import org.apache.twill.internal.utils.Networks; /** @@ -129,12 +129,12 @@ 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, Networks.getRandomPort()) + .set(TxConstants.Service.CFG_DATA_TX_BIND_PORT, TestUtil.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) // setup default test configs for Omid - .set(OmidTransactionProvider.OMID_TSO_PORT, Networks.getRandomPort()) + .set(OmidTransactionProvider.OMID_TSO_PORT, TestUtil.getRandomPort()) ; } http://git-wip-us.apache.org/repos/asf/phoenix/blob/169270da/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..f3faa0c 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; + } + } }