You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2016/08/10 19:41:04 UTC
[18/50] [abbrv] incubator-geode git commit: GEODE-1722 Distributed
tests should use a restricted membership-port-range
GEODE-1722 Distributed tests should use a restricted membership-port-range
fixing a damaged unit test. AvailablePort & AvailablePortHelper can now
be told to use the membership-port-range to find available ports. The
default is to use ports outside of the membership-port-range.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/73e413bf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/73e413bf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/73e413bf
Branch: refs/heads/feature/GEODE-420
Commit: 73e413bf6fce4165efeeb4633afe2814f3543593
Parents: 151b272
Author: Bruce Schuchardt <bs...@pivotal.io>
Authored: Wed Aug 3 09:43:13 2016 -0700
Committer: Bruce Schuchardt <bs...@pivotal.io>
Committed: Wed Aug 3 09:43:13 2016 -0700
----------------------------------------------------------------------
.../gemfire/internal/AvailablePort.java | 49 ++++++++++++++------
.../distributed/DistributedSystemDUnitTest.java | 14 +++---
.../gemfire/internal/AvailablePortHelper.java | 21 ++++++++-
3 files changed, 62 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73e413bf/geode-core/src/main/java/com/gemstone/gemfire/internal/AvailablePort.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/AvailablePort.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/AvailablePort.java
index 5fa826f..7a8dccd 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/AvailablePort.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/AvailablePort.java
@@ -44,7 +44,7 @@ public class AvailablePort {
* see if there is a gemfire system property that establishes a
* default address for the given protocol, and return it
*/
- private static InetAddress getAddress(int protocol) {
+ public static InetAddress getAddress(int protocol) {
String name = null;
try {
if (protocol == SOCKET) {
@@ -350,8 +350,25 @@ public class AvailablePort {
* <code>protocol</code> is unknown
*/
public static int getRandomAvailablePort(int protocol, InetAddress addr) {
+ return getRandomAvailablePort(protocol, addr, false);
+ }
+
+ /**
+ * Returns a randomly selected available port in the range 5001 to
+ * 32767.
+ *
+ * @param protocol
+ * The protocol to check (either {@link #SOCKET} or {@link
+ * #MULTICAST}).
+ * @param addr the bind-address or mcast address to use
+ * @param useMembershipPortRange use true if the port will be used for membership
+ *
+ * @throws IllegalArgumentException
+ * <code>protocol</code> is unknown
+ */
+ public static int getRandomAvailablePort(int protocol, InetAddress addr, boolean useMembershipPortRange) {
while (true) {
- int port = getRandomWildcardBindPortNumber();
+ int port = getRandomWildcardBindPortNumber(useMembershipPortRange);
if (isPortAvailable(port, protocol, addr)) {
// don't return the products default multicast port
if ( !(protocol == MULTICAST && port == DistributionConfig.DEFAULT_MCAST_PORT) ){
@@ -361,8 +378,12 @@ public class AvailablePort {
}
}
public static Keeper getRandomAvailablePortKeeper(int protocol, InetAddress addr) {
+ return getRandomAvailablePortKeeper(protocol, addr, false);
+ }
+
+ public static Keeper getRandomAvailablePortKeeper(int protocol, InetAddress addr, boolean useMembershipPortRange) {
while (true) {
- int port = getRandomWildcardBindPortNumber();
+ int port = getRandomWildcardBindPortNumber(useMembershipPortRange);
Keeper result = isPortKeepable(port, protocol, addr);
if (result != null) {
return result;
@@ -424,19 +445,19 @@ public class AvailablePort {
}
private static int getRandomWildcardBindPortNumber() {
+ return getRandomWildcardBindPortNumber(false);
+ }
+
+ private static int getRandomWildcardBindPortNumber(boolean useMembershipPortRange) {
int rangeBase;
int rangeTop;
-// wcb port range on Windows is 1024..5000 (and Linux?)
-// wcb port range on Solaris is 32768..65535
-// if (System.getProperty("os.name").equals("SunOS")) {
-// rangeBase=32768;
-// rangeTop=65535;
-// } else {
-// rangeBase=1024;
-// rangeTop=5000;
-// }
- rangeBase = AVAILABLE_PORTS_LOWER_BOUND; // 20000/udp is securid
- rangeTop = AVAILABLE_PORTS_UPPER_BOUND; // 30000/tcp is spoolfax
+ if ( !useMembershipPortRange ) {
+ rangeBase = AVAILABLE_PORTS_LOWER_BOUND; // 20000/udp is securid
+ rangeTop = AVAILABLE_PORTS_UPPER_BOUND; // 30000/tcp is spoolfax
+ } else {
+ rangeBase = DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[0];
+ rangeTop = DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1];
+ }
return rand.nextInt(rangeTop-rangeBase) + rangeBase;
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73e413bf/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemDUnitTest.java
index 5386ea1..1be3b9f 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemDUnitTest.java
@@ -35,7 +35,8 @@ import com.gemstone.gemfire.internal.SocketCreator;
import com.gemstone.gemfire.test.dunit.*;
import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-import org.junit.Test;
+
+import org.junit.*;
import org.junit.experimental.categories.Category;
import java.net.Inet4Address;
@@ -47,6 +48,7 @@ import java.util.Properties;
import java.util.concurrent.TimeoutException;
import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
+import static com.gemstone.gemfire.internal.AvailablePort.SOCKET;
import static org.junit.Assert.*;
/**
@@ -69,7 +71,7 @@ public class DistributedSystemDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testWaitForDeparture() throws Exception {
disconnectAllFromDS();
- int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+ int locatorPort = AvailablePort.getRandomAvailablePort(SOCKET);
Properties p = getDistributedSystemProperties();
p.put(LOCATORS, "");
p.put(START_LOCATOR, "localhost[" + locatorPort + "]");
@@ -241,7 +243,7 @@ public class DistributedSystemDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testSpecificTcpPort() throws Exception {
Properties config = new Properties();
- int tcpPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+ int tcpPort = AvailablePort.getRandomAvailablePort(SOCKET);
config.put(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
config.setProperty(TCP_PORT, String.valueOf(tcpPort));
InternalDistributedSystem system = getSystem(config);
@@ -290,7 +292,7 @@ public class DistributedSystemDUnitTest extends JUnit4DistributedTestCase {
@Test
public void testUDPPortRange() throws Exception {
Properties config = new Properties();
- int unicastPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+ int unicastPort = AvailablePort.getRandomAvailablePort(SOCKET, AvailablePort.getAddress(SOCKET), true);
config.put(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
// Minimum 3 ports required in range for UDP, FD_SOCK and TcpConduit.
config.setProperty(MEMBERSHIP_PORT_RANGE,
@@ -313,7 +315,7 @@ public class DistributedSystemDUnitTest extends JUnit4DistributedTestCase {
int startPort = port;
int found = 0;
while (port <= DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1]) {
- if (AvailablePort.isPortAvailable(port, AvailablePort.SOCKET)) {
+ if (AvailablePort.isPortAvailable(port, SOCKET)) {
found++;
if (found == range) {
break;
@@ -359,7 +361,7 @@ public class DistributedSystemDUnitTest extends JUnit4DistributedTestCase {
public void testConflictingUDPPort() throws Exception {
final Properties config = new Properties();
final int mcastPort = AvailablePort.getRandomAvailablePort(AvailablePort.MULTICAST);
- final int[] socketPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
+ final int[] socketPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2, true);
final int unicastPort = socketPorts[0];
config.setProperty(MCAST_PORT, String.valueOf(mcastPort));
config.setProperty(START_LOCATOR, "localhost[" + socketPorts[1] + "]");
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/73e413bf/geode-core/src/test/java/com/gemstone/gemfire/internal/AvailablePortHelper.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/AvailablePortHelper.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/AvailablePortHelper.java
old mode 100755
new mode 100644
index 246e6c7..80cfeb5
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/AvailablePortHelper.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/AvailablePortHelper.java
@@ -38,7 +38,18 @@ public class AvailablePortHelper {
* Returns array of unique randomly available tcp ports of specified count.
*/
public static int[] getRandomAvailableTCPPorts(int count) {
- List<Keeper> list = getRandomAvailableTCPPortKeepers(count);
+ return getRandomAvailableTCPPorts(count, false);
+ }
+
+ /**
+ * Returns an array of unique randomly available tcp ports
+ *
+ * @param count number of desired ports
+ * @param useMembershipPortRange whether to use the configured membership-port-range
+ * @return the ports
+ */
+ public static int[] getRandomAvailableTCPPorts(int count, boolean useMembershipPortRange) {
+ List<Keeper> list = getRandomAvailableTCPPortKeepers(count, useMembershipPortRange);
int[] ports = new int[list.size()];
int i = 0;
for (Keeper k: list) {
@@ -48,10 +59,16 @@ public class AvailablePortHelper {
}
return ports;
}
+
public static List<Keeper> getRandomAvailableTCPPortKeepers(int count) {
+ return getRandomAvailableTCPPortKeepers(count, false);
+ }
+
+ public static List<Keeper> getRandomAvailableTCPPortKeepers(int count, boolean useMembershipPortRange) {
List<Keeper> result = new ArrayList<Keeper>();
while (result.size() < count) {
- result.add(AvailablePort.getRandomAvailablePortKeeper(AvailablePort.SOCKET));
+ result.add(AvailablePort.getRandomAvailablePortKeeper(AvailablePort.SOCKET,
+ AvailablePort.getAddress(AvailablePort.SOCKET), useMembershipPortRange));
}
return result;
}