You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/03/18 17:28:25 UTC
[2/8] incubator-geode git commit: GEODE-519 Make sure that membership
port range is available.
GEODE-519 Make sure that membership port range is available.
test looks for port range of 3 port. Sometime that port is not available
thus now we check range of port before starting the test.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/658981a9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/658981a9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/658981a9
Branch: refs/heads/feature/GEODE-1050
Commit: 658981a9a2015839c710d9dbdc9b20937e8dde22
Parents: f226f01
Author: Hitesh Khamesra <hk...@pivotal.io>
Authored: Tue Mar 15 14:34:18 2016 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Fri Mar 18 09:23:22 2016 -0700
----------------------------------------------------------------------
.../distributed/DistributedSystemDUnitTest.java | 47 ++++++++++++++++----
1 file changed, 38 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/658981a9/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 fcaaa2d..610be11 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
@@ -316,23 +316,52 @@ public class DistributedSystemDUnitTest extends DistributedTestCase {
assertTrue(unicastPort <= idm.getPort() && idm.getPort() <= unicastPort+2);
assertTrue(unicastPort <= idm.getPort() && idm.getDirectChannelPort() <= unicastPort+2);
}
+
+ /***
+ * this will return starting port, from it "range" of port will available
+ * @param range
+ * @return
+ */
+ private int getPortRange(int range) {
+ int port = DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[0] + 10000;
+ int startPort = port;
+ int found = 0;
+ while (port <= DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1]) {
+ if (AvailablePort.isPortAvailable(port, AvailablePort.SOCKET)) {
+ found++;
+ if (found == range) {
+ break;
+ }
+ port++;
+ } else {
+ port++;
+ startPort = port;
+ found = 0;
+ }
+ }
+ if (port > DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1]) {
+ fail("Unable to find port range " + range);
+ }
+ return startPort;
+ }
public void testMembershipPortRangeWithExactThreeValues() throws Exception {
Properties config = new Properties();
- config.setProperty("locators", "localhost["+DistributedTestUtils.getDUnitLocatorPort()+"]");
- config.setProperty(DistributionConfig.MEMBERSHIP_PORT_RANGE_NAME, ""
- + (DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1] - 2) + "-"
- + (DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1]));
- system = (InternalDistributedSystem)DistributedSystem.connect(config);
+ config.setProperty("locators", "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
+ int portRange = 3;
+ int portStartRange = getPortRange(portRange);
+ int portEndRange = portStartRange + portRange - 1;
+ config.setProperty(DistributionConfig.MEMBERSHIP_PORT_RANGE_NAME, "" + (portStartRange) + "-" + (portEndRange));
+ system = (InternalDistributedSystem) DistributedSystem.connect(config);
Cache cache = CacheFactory.create(system);
cache.addCacheServer();
DistributionManager dm = (DistributionManager) system.getDistributionManager();
InternalDistributedMember idm = dm.getDistributionManagerId();
system.disconnect();
- assertTrue(idm.getPort() <= DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1]);
- assertTrue(idm.getPort() >= DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[0]);
- assertTrue(idm.getDirectChannelPort() <= DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[1]);
- assertTrue(idm.getDirectChannelPort() >= DistributionConfig.DEFAULT_MEMBERSHIP_PORT_RANGE[0]);
+ assertTrue(idm.getPort() <= portEndRange);
+ assertTrue(idm.getPort() >= portStartRange);
+ assertTrue(idm.getDirectChannelPort() <= portEndRange);
+ assertTrue(idm.getDirectChannelPort() >= portStartRange);
}
public void testConflictingUDPPort() throws Exception {