You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2015/09/09 20:45:59 UTC

[2/3] incubator-geode git commit: GEODE-77 fixed a problem with creating member IDs for a test

GEODE-77 fixed a problem with creating member IDs for a 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/ae43acaa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/ae43acaa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/ae43acaa

Branch: refs/heads/feature/GEODE-77
Commit: ae43acaa40734cd8004bca9c7e98a5098de8d354
Parents: ea9a739
Author: Bruce Schuchardt <bs...@pivotal.io>
Authored: Wed Sep 9 11:42:45 2015 -0700
Committer: Bruce Schuchardt <bs...@pivotal.io>
Committed: Wed Sep 9 11:42:45 2015 -0700

----------------------------------------------------------------------
 .../membership/gms/GMSMemberFactory.java        |  13 +-
 .../BindDistributedSystemJUnitTest.java         | 146 +------------------
 2 files changed, 11 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ae43acaa/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMemberFactory.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMemberFactory.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMemberFactory.java
index 268384e..8b6be83 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMemberFactory.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/GMSMemberFactory.java
@@ -23,6 +23,7 @@ import com.gemstone.gemfire.distributed.internal.membership.MemberServices;
 import com.gemstone.gemfire.distributed.internal.membership.MembershipManager;
 import com.gemstone.gemfire.distributed.internal.membership.NetMember;
 import com.gemstone.gemfire.distributed.internal.membership.gms.locator.GMSLocator;
+import com.gemstone.gemfire.internal.SocketCreator;
 import com.gemstone.gemfire.internal.Version;
 import com.gemstone.gemfire.internal.admin.remote.RemoteTransportConfig;
 import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
@@ -65,18 +66,20 @@ public class GMSMemberFactory implements MemberServices {
   }
 
   /**
-   * Return a new NetMember representing current host
+   * Return a new NetMember representing current host.  This
+   * is used for testing, so we ignore host-name lookup
+   * localhost inetAddress
    * 
-   * @param s a String referring to the current host
+   * @param s a String referring to a host - ignored
    * @param p the membership port being used
    * @return the new member
    */
   public NetMember newNetMember(String s, int p) {
     InetAddress inetAddr = null;
     try {
-      inetAddr=InetAddress.getByName(s);
-    } catch (UnknownHostException e) {
-      throw new RuntimeException("Unable to create an identifier for testing for " + s, e);
+      inetAddr=SocketCreator.getLocalHost();
+    } catch (UnknownHostException e2) {
+      throw new RuntimeException("Unable to create an identifier for testing for " + s, e2);
     }
     return newNetMember(inetAddr, p);
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ae43acaa/gemfire-core/src/test/java/com/gemstone/gemfire/admin/internal/BindDistributedSystemJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/admin/internal/BindDistributedSystemJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/admin/internal/BindDistributedSystemJUnitTest.java
index c8cf74b..a585726 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/admin/internal/BindDistributedSystemJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/admin/internal/BindDistributedSystemJUnitTest.java
@@ -25,6 +25,7 @@ import com.gemstone.gemfire.distributed.DistributedSystem;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
 import com.gemstone.gemfire.internal.AvailablePort;
+import com.gemstone.gemfire.internal.AvailablePortHelper;
 import com.gemstone.gemfire.internal.util.StopWatch;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 
@@ -70,159 +71,18 @@ public class BindDistributedSystemJUnitTest {
 
     Properties props = new Properties();
     props.setProperty(DistributionConfig.BIND_ADDRESS_NAME, bindTo);
-    props.setProperty(DistributionConfig.MCAST_PORT_NAME,
-        String.valueOf(AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS)));
+    props.setProperty(DistributionConfig.START_LOCATOR_NAME,
+        "localhost["+AvailablePortHelper.getRandomAvailableTCPPort()+"]");
     this.system = com.gemstone.gemfire.distributed.DistributedSystem.connect(
         props);
         
     assertEquals(true, this.system.isConnected());
 
-    // analyze the system's config...
-    DistributionConfig distConfig =
-        ((InternalDistributedSystem) this.system).getConfig();
-
-    // create a loner distributed system and make sure it is connected...
-    String locators = distConfig.getLocators();
-    String mcastAddress = InetAddressUtil.toString(distConfig.getMcastAddress());
-    int mcastPort = distConfig.getMcastPort();
-
     // Because of fix for bug 31409
     this.system.disconnect();
 
-    checkAdminAPI(bindTo, locators, mcastAddress, mcastPort);
-  }
-
-  private void checkAdminAPI(String bindTo,
-      String locators,
-      String mcastAddress,
-      int mcastPort) throws Exception {
-
-    // build the config that defines the system...
-    com.gemstone.gemfire.admin.DistributedSystemConfig config =
-      AdminDistributedSystemFactory.defineDistributedSystem();
-    config.setBindAddress(bindTo);
-    config.setLocators(locators);
-    config.setMcastAddress(mcastAddress);
-    config.setMcastPort(mcastPort);
-    config.setRemoteCommand(com.gemstone.gemfire.admin.DistributedSystemConfig.DEFAULT_REMOTE_COMMAND);
-    assertNotNull(config);
-
-    AdminDistributedSystem distSys =
-        AdminDistributedSystemFactory.getDistributedSystem(config);
-    assertNotNull(distSys);
-
-    // connect to the system...
-    distSys.connect();
-    try {
-      checkSystemIsRunning(distSys);
-
-//      DistributionManager dm =
-//          ((AdminDistributedSystemImpl) distSys).getDistributionManager();
-//      checkDistributionPorts(dm, bindTo);
-
-    }
-    finally {
-      distSys.disconnect();
-    }
-  }
-
-  private void checkSystemIsRunning(final AdminDistributedSystem distSys) throws Exception {
-//    WaitCriterion ev = new WaitCriterion() {
-//      public boolean done() {
-//        return distSys.isConnected() || distSys.isRunning();
-//      }
-//      public String description() {
-//        return "distributed system is either connected or running: " + distSys;
-//      }
-//    };
-//    DistributedTestCase.waitForCriterion(ev, 120 * 1000, 200, true);
-    boolean done = false;
-    try {
-      for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 120 * 1000; done = (distSys.isConnected() || distSys.isRunning())) {
-        Thread.sleep(200);
-      }
-    } catch (InterruptedException e) {
-      Thread.currentThread().interrupt();
-    }
-    assertTrue("waiting for distributed system is either connected or running: " + distSys, done);
-    assertTrue(distSys.isConnected());
   }
 
-//  protected void checkDistributionPorts(DistributionManager dm,
-//      String bindToAddress) throws Exception {
-//    assertNotNull(dm);
-//    DistributionChannel distChannel = dm.getDistributionChannel();
-//
-//    // now query the Channel...
-//    DirectChannel dc = distChannel.getDirectChannel();
-////    MembershipManager jc = distChannel.getMembershipManager();
-//
-//    // get Jgroups IpAddress and retrieve its ports...
-//    DistributedMember ipAddress = dc.getLocalAddress();
-//    InetAddress jgAddr = ipAddress.getIpAddress();
-////    int mcastPort = ipAddress.getPort();
-//    int directPort = ipAddress.getDirectChannelPort();
-//    int[] portsToCheck = new int[]{directPort};
-//
-//    // check the loopback first...
-//    assertEquals(InetAddress.getByName(bindToAddress), jgAddr);
-//    checkInetAddress(jgAddr, portsToCheck, true);
-//
-//    // check all non-loopback (127.0.0.1) interfaces...
-//    // note: if this fails then this machine probably lacks a NIC
-//    InetAddress host = InetAddress.getLocalHost();
-//    assertEquals(false, InetAddressUtil.isLoopback(host));
-//    InetAddress[] hostAddrs = InetAddress.getAllByName(host.getHostName());
-//    for (int i = 0; i < hostAddrs.length; i++) {
-//      if (!InetAddressUtil.isLoopback(hostAddrs[i])) {
-//        // make sure sure non-loopback is not listening to ports...
-//        checkInetAddress(hostAddrs[i], portsToCheck, false);
-//      }
-//    }
-//  }
-
-  private static void checkInetAddress(InetAddress addr,
-      int[] ports,
-      boolean isListening) throws Exception {
-    for (int i = 0; i < ports.length; i++) {
-      System.out.println("addr = " + addr);
-      System.out.println("ports[i] = " + ports[i]);
-      System.out.println("isListening = " + isListening);
-      assertEquals(isListening, isPortListening(addr, ports[i]));
-    }
-  }
-
-  /**
-   * Gets the portListening attribute of the BindDistributedSystemJUnitTest class
-   *
-   * @param addr           Description of the Parameter
-   * @param port           Description of the Parameter
-   * @return               The portListening value
-   * @exception Exception  Description of the Exception
-   */
-  private static boolean isPortListening(InetAddress addr, int port) throws Exception {
-    // Try to create a Socket
-    Socket client = null;
-    try {
-      client = new Socket(addr, port);
-      return true;
-    }
-    catch (Exception e) {
-      return false;
-    }
-    finally {
-      if (client != null) {
-        try {
-          client.close();
-        }
-        catch (Exception e) {
-          /*
-           *  ignore
-           */
-        }
-      }
-    }
-  }
 
 }