geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bschucha...@apache.org
Subject incubator-geode git commit: GEODE-77 adding additional test coverage
Date Tue, 01 Sep 2015 23:37:57 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-77 fb0e2b281 -> edc81a750


GEODE-77 adding additional test coverage

Test coverage is now > 71% for all membership services.
This also fixes a problem in GMSJoinLeave.join where a member that
was shut down & restarted with a start-locator setting formed a
split-brain.  Now we send a collection of previously attempted
coordinators with FindCoordinator requests, and a member receiving
a join request will check to see if the new member ought to assume
the role of coordinator.  See LocatorDUnitTest.testCollocatedLocatorWithSecurity.


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

Branch: refs/heads/feature/GEODE-77
Commit: edc81a750d6e54040cc5210bcdbd9013602002ae
Parents: fb0e2b2
Author: Bruce Schuchardt <bschuchardt@pivotal.io>
Authored: Tue Sep 1 16:36:19 2015 -0700
Committer: Bruce Schuchardt <bschuchardt@pivotal.io>
Committed: Tue Sep 1 16:37:15 2015 -0700

----------------------------------------------------------------------
 .../gemfire/distributed/DistributedSystem.java  |   2 +-
 .../distributed/internal/InternalLocator.java   |   2 +-
 .../internal/membership/MemberFactory.java      |   5 +-
 .../internal/membership/MemberServices.java     |   3 +-
 .../internal/membership/NetView.java            |  27 ++-
 .../membership/gms/GMSMemberFactory.java        |   5 +-
 .../gms/locator/FindCoordinatorRequest.java     |  23 ++-
 .../membership/gms/locator/GMSLocator.java      |  60 ++++--
 .../membership/gms/membership/GMSJoinLeave.java |  34 +++-
 .../gms/messages/JoinResponseMessage.java       |  17 +-
 .../gms/messenger/JGroupsMessenger.java         |   6 +-
 .../membership/gms/messenger/StatRecorder.java  |   1 +
 .../gms/mgr/GMSMembershipManager.java           |   6 +-
 .../gemfire/distributed/LocatorJUnitTest.java   |  42 ----
 .../membership/MembershipJUnitTest.java         |  13 +-
 .../gms/locator/GMSLocatorJUnitTest.java        |  76 ++++++-
 .../gms/membership/GMSJoinLeaveJUnitTest.java   |  50 +++++
 .../membership/gms/messenger/InterceptUDP.java  |  26 ++-
 .../messenger/JGroupsMessengerJUnitTest.java    |  75 ++++++-
 .../tcpserver/TcpServerJUnitDisabledTest.java   | 203 -------------------
 .../internal/tcpserver/TcpServerJUnitTest.java  | 203 +++++++++++++++++++
 .../gemfire/redis/RedisDistDUnitTest.java       |  11 +-
 .../java/dunit/standalone/DUnitLauncher.java    |  10 +-
 23 files changed, 579 insertions(+), 321 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
index 3f8040e..5c2d2cc 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/DistributedSystem.java
@@ -299,7 +299,7 @@ import com.gemstone.gemfire.security.GemFireSecurityException;
  *   instead of a colon to separate the host name and bind address.
  *   For example, "server1@fdf0:76cf:a0ed:9449::5[12233]" specifies a locator
  *   running on "server1" and bound to fdf0:76cf:a0ed:9449::5 on port 12233.<p>
- *   If "mcast-port" is zero and "locators" is ""
+ *   If "locators" is empty
  *   then this distributed system will be isolated from all other GemFire
  *   processes.<p>
  *   </dd>

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
index cfda513..2158414 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalLocator.java
@@ -664,7 +664,7 @@ public class InternalLocator extends Locator implements ConnectListener {
     }
     
     this.locatorImpl = MemberFactory.newLocatorHandler(this.bindAddress, this.stateFile,
-        locatorsProp, locatorsAreCoordinators, networkPartitionDetectionEnabled);
+        locatorsProp, locatorsAreCoordinators, networkPartitionDetectionEnabled, stats);
     this.handler.addHandler(PeerLocatorRequest.class, this.locatorImpl);
     peerLocator = true;
     if(!server.isAlive()) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/MemberFactory.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/MemberFactory.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/MemberFactory.java
index de469d8..6021e2f 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/MemberFactory.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/MemberFactory.java
@@ -12,6 +12,7 @@ import java.net.InetAddress;
 
 import com.gemstone.gemfire.distributed.internal.DMStats;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.distributed.internal.LocatorStats;
 import com.gemstone.gemfire.distributed.internal.membership.gms.GMSMemberFactory;
 import com.gemstone.gemfire.distributed.internal.membership.gms.NetLocator;
 import com.gemstone.gemfire.internal.admin.remote.RemoteTransportConfig;
@@ -99,9 +100,9 @@ public class MemberFactory {
           File stateFile,
           String locatorString,
           boolean usePreferredCoordinators,
-          boolean networkPartitionDetectionEnabled) {
+          boolean networkPartitionDetectionEnabled, LocatorStats stats) {
     return services.newLocatorHandler(bindAddress, stateFile, locatorString,
-        usePreferredCoordinators, networkPartitionDetectionEnabled);
+        usePreferredCoordinators, networkPartitionDetectionEnabled, stats);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/MemberServices.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/MemberServices.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/MemberServices.java
index 9e6c27c..cdafe9e 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/MemberServices.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/MemberServices.java
@@ -13,6 +13,7 @@ import java.net.InetAddress;
 import com.gemstone.gemfire.CancelCriterion;
 import com.gemstone.gemfire.distributed.internal.DMStats;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.distributed.internal.LocatorStats;
 import com.gemstone.gemfire.distributed.internal.membership.gms.NetLocator;
 import com.gemstone.gemfire.internal.admin.remote.RemoteTransportConfig;
 
@@ -83,5 +84,5 @@ public interface MemberServices {
    */
   public abstract NetLocator newLocatorHandler(InetAddress bindAddress,
       File stateFile, String locatorString, boolean usePreferredCoordinators,
-      boolean networkPartitionDetectionEnabled);
+      boolean networkPartitionDetectionEnabled, LocatorStats stats);
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/NetView.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/NetView.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/NetView.java
index 7b86159..46ac284 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/NetView.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/NetView.java
@@ -13,7 +13,6 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -24,10 +23,7 @@ import org.apache.logging.log4j.Logger;
 
 import com.gemstone.gemfire.DataSerializer;
 import com.gemstone.gemfire.distributed.internal.DistributionManager;
-import com.gemstone.gemfire.distributed.internal.membership.gms.GMSMemberFactory;
 import com.gemstone.gemfire.distributed.internal.membership.gms.Services;
-import com.gemstone.gemfire.distributed.internal.membership.gms.messages.SuspectRequest;
-import com.gemstone.gemfire.distributed.internal.membership.gms.mgr.GMSMembershipManager;
 import com.gemstone.gemfire.internal.DataSerializableFixedID;
 import com.gemstone.gemfire.internal.InternalDataSerializer;
 import com.gemstone.gemfire.internal.Version;
@@ -185,6 +181,29 @@ public class NetView implements DataSerializableFixedID {
     return null;
   }
 
+  /**
+   * Returns the coordinator of this view, rejecting any in the
+   * given collection of IDs
+   */
+  public InternalDistributedMember getCoordinator(Collection<InternalDistributedMember> rejections) {
+    if (rejections == null) {
+      return getCoordinator();
+    }
+    synchronized (members) {
+      for (InternalDistributedMember addr : members) {
+        if (addr.getNetMember().preferredForCoordinator() && !rejections.contains(addr)) {
+          return addr;
+        }
+      }
+      for (InternalDistributedMember addr: members) {
+        if (!rejections.contains(addr)) {
+          return addr;
+        }
+      }
+    }
+    return null;
+  }
+
   /***
    * This functions returns the list of all preferred coordinators.
    * One random member from list of non-preferred member list. It make

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/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 34e1123..268384e 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
@@ -16,6 +16,7 @@ import com.gemstone.gemfire.SystemConnectException;
 import com.gemstone.gemfire.distributed.internal.DMStats;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.distributed.internal.DistributionException;
+import com.gemstone.gemfire.distributed.internal.LocatorStats;
 import com.gemstone.gemfire.distributed.internal.membership.DistributedMembershipListener;
 import com.gemstone.gemfire.distributed.internal.membership.MemberAttributes;
 import com.gemstone.gemfire.distributed.internal.membership.MemberServices;
@@ -118,8 +119,8 @@ public class GMSMemberFactory implements MemberServices {
       File stateFile,
       String locatorString,
       boolean usePreferredCoordinators,
-      boolean networkPartitionDetectionEnabled) {
+      boolean networkPartitionDetectionEnabled, LocatorStats stats) {
     
-    return new GMSLocator(bindAddress, stateFile, locatorString, usePreferredCoordinators, networkPartitionDetectionEnabled);
+    return new GMSLocator(bindAddress, stateFile, locatorString, usePreferredCoordinators, networkPartitionDetectionEnabled, stats);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/FindCoordinatorRequest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/FindCoordinatorRequest.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/FindCoordinatorRequest.java
index 0a7370f..9af29a1 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/FindCoordinatorRequest.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/FindCoordinatorRequest.java
@@ -3,6 +3,7 @@ package com.gemstone.gemfire.distributed.internal.membership.gms.locator;
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
+import java.util.Collection;
 
 import com.gemstone.gemfire.DataSerializer;
 import com.gemstone.gemfire.distributed.internal.DistributionManager;
@@ -13,12 +14,18 @@ import com.gemstone.gemfire.internal.Version;
 
 public class FindCoordinatorRequest implements DataSerializableFixedID, PeerLocatorRequest {
 
-  public InternalDistributedMember memberID;
+  private InternalDistributedMember memberID;
+  private Collection<InternalDistributedMember> rejectedCoordinators;
   
   public FindCoordinatorRequest(InternalDistributedMember myId) {
     this.memberID = myId;
   }
   
+  public FindCoordinatorRequest(InternalDistributedMember myId, Collection<InternalDistributedMember> rejectedCoordinators) {
+    this.memberID = myId;
+    this.rejectedCoordinators = rejectedCoordinators;
+  }
+  
   public FindCoordinatorRequest() {
     // no-arg constructor for serialization
   }
@@ -27,9 +34,18 @@ public class FindCoordinatorRequest implements DataSerializableFixedID, PeerLoca
     return memberID;
   }
   
+  public Collection<InternalDistributedMember> getRejectedCoordinators() {
+    return rejectedCoordinators;
+  }
+  
   @Override
   public String toString() {
-    return "FindCoordinatorRequest(memberID="+memberID+")";
+    if (rejectedCoordinators != null) {
+      return "FindCoordinatorRequest(memberID="+memberID
+          +", rejected="+rejectedCoordinators+")";
+    } else {
+      return "FindCoordinatorRequest(memberID="+memberID+")";
+    }
   }
 
   @Override
@@ -45,12 +61,13 @@ public class FindCoordinatorRequest implements DataSerializableFixedID, PeerLoca
   @Override
   public void toData(DataOutput out) throws IOException {
     DataSerializer.writeObject(this.memberID, out);
+    DataSerializer.writeObject(this.rejectedCoordinators, out);
   }
 
   @Override
   public void fromData(DataInput in) throws IOException, ClassNotFoundException {
     this.memberID = DataSerializer.readObject(in);
-
+    this.rejectedCoordinators = DataSerializer.readObject(in);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/GMSLocator.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/GMSLocator.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/GMSLocator.java
index dd4ac51..d9cfb36 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/GMSLocator.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/GMSLocator.java
@@ -10,17 +10,21 @@ import java.io.ObjectOutputStream;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
 import com.gemstone.gemfire.InternalGemFireException;
+
 import org.apache.logging.log4j.Logger;
 
 import com.gemstone.gemfire.DataSerializer;
 import com.gemstone.gemfire.cache.GemFireCache;
 import com.gemstone.gemfire.distributed.DistributedSystem;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
+import com.gemstone.gemfire.distributed.internal.LocatorStats;
 import com.gemstone.gemfire.distributed.internal.SharedConfiguration;
 import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
 import com.gemstone.gemfire.distributed.internal.membership.MembershipManager;
@@ -49,6 +53,7 @@ public class GMSLocator implements Locator, NetLocator {
   private final String locatorString;
   private final List<InetSocketAddress> locators;
   private Services services;
+  private final LocatorStats stats;
   
   private Set<InternalDistributedMember> registrants = new HashSet<InternalDistributedMember>();
 
@@ -62,12 +67,13 @@ public class GMSLocator implements Locator, NetLocator {
    * @param locatorString     location of other locators (bootstrapping, failover)
    * @param usePreferredCoordinators    true if the membership coordinator should be a Locator
    * @param networkPartitionDetectionEnabled true if network partition detection is enabled
+   * @param stats the locator statistics object
    */
   public GMSLocator(  InetAddress bindAddress,
                       File stateFile,
                       String locatorString,
                       boolean usePreferredCoordinators,
-                      boolean networkPartitionDetectionEnabled) {
+                      boolean networkPartitionDetectionEnabled, LocatorStats stats) {
     this.usePreferredCoordinators = usePreferredCoordinators;
     this.networkPartitionDetectionEnabled = networkPartitionDetectionEnabled;
     this.locatorString = locatorString;
@@ -77,6 +83,7 @@ public class GMSLocator implements Locator, NetLocator {
       this.locators = GMSUtil.parseLocators(locatorString, bindAddress);
     }
     this.viewFile = stateFile;
+    this.stats = stats;
   }
   
   @Override
@@ -85,7 +92,10 @@ public class GMSLocator implements Locator, NetLocator {
       logger.info("Peer locator is connecting to local membership services");
       services = ((GMSMembershipManager)mgr).getServices();
       services.setLocator(this);
-      this.view = services.getJoinLeave().getView();
+      NetView newView = services.getJoinLeave().getView();
+      if (newView != null) {
+        this.view = newView;
+      }
     }
   }
   
@@ -117,8 +127,8 @@ public class GMSLocator implements Locator, NetLocator {
   public Object processRequest(Object request) throws IOException {
     Object response = null;
     
-    if (logger.isDebugEnabled()) {
-      logger.debug("Peer locator processing " + request);
+    if (logger.isInfoEnabled()) {
+      logger.info("Peer locator processing {}", request);
     }
     
     if (request instanceof GetViewRequest) {
@@ -140,7 +150,8 @@ public class GMSLocator implements Locator, NetLocator {
         boolean fromView = false;
         
         if (view != null) {
-          coord = view.getCoordinator();
+          coord = view.getCoordinator(findRequest.getRejectedCoordinators());
+          logger.info("Peer locator: coordinator from view is {}", coord);
           fromView = true;
         }
         
@@ -152,6 +163,10 @@ public class GMSLocator implements Locator, NetLocator {
           
         } else {
           // find the "oldest" registrant
+          Collection<InternalDistributedMember> rejections = findRequest.getRejectedCoordinators();
+          if (rejections == null) {
+            rejections = Collections.emptyList();
+          }
           synchronized(registrants) {
             registrants.add(findRequest.getMemberID());
             if (services != null) {
@@ -159,11 +174,13 @@ public class GMSLocator implements Locator, NetLocator {
             }
             for (InternalDistributedMember mbr: registrants) {
               if (mbr != coord  &&  (coord==null  ||  mbr.compareTo(coord) < 0)) {
-                if (mbr.getNetMember().preferredForCoordinator() || !mbr.getNetMember().splitBrainEnabled()) {
+                if (!rejections.contains(mbr)
+                    && (mbr.getNetMember().preferredForCoordinator() || !mbr.getNetMember().splitBrainEnabled())) {
                   coord = mbr;
                 }
               }
             }
+            logger.info("Peer locator: coordinator from registrations is {}", coord);
           }
         }
         response = new FindCoordinatorResponse(coord, fromView,
@@ -207,16 +224,17 @@ public class GMSLocator implements Locator, NetLocator {
   
   @Override
   public void endRequest(Object request, long startTime) {
-    // place holder for statistics
+    stats.endLocatorRequest(startTime);
   }
 
   @Override
   public void endResponse(Object request, long startTime) {
-    // place holder for statistics
+    stats.endLocatorResponse(startTime);
   }
 
   @Override
   public void shutDown() {
+    // nothing to do for GMSLocator
   }
   
   
@@ -244,10 +262,6 @@ public class GMSLocator implements Locator, NetLocator {
   }
   
   private boolean recoverFromOthers() {
-    if (locators.isEmpty()) {
-      return false;
-    }
-
     for (InetSocketAddress other: this.locators) {
       logger.info("Peer locator attempting to get state from " + other);
       if (recover(other)) {
@@ -266,7 +280,9 @@ public class GMSLocator implements Locator, NetLocator {
         logger.info("Peer locator recovered initial membership of {}", view);
         return true;
       }
-    } catch (IOException | ClassNotFoundException ignore) {}
+    } catch (IOException | ClassNotFoundException ignore) {
+      logger.info("Peer locator could not recover membership view from {}: {}", other, ignore.getMessage());
+    }
     return false;
   }
 
@@ -281,16 +297,18 @@ public class GMSLocator implements Locator, NetLocator {
         return false;
       }
 
-      int version = ois.readInt();
-      Version geodeVersion = Version.fromOrdinalNoThrow((short)version, false);
-      if (geodeVersion != null  &&  version == Version.CURRENT_ORDINAL) {
+      ObjectInput ois2 = ois;
+      int version = ois2.readInt();
+      if (version != Version.CURRENT_ORDINAL) {
+        Version geodeVersion = Version.fromOrdinalNoThrow((short)version, false);
         logger.info("Peer locator found that persistent view was written with {}", geodeVersion);
-        ObjectInput ois2 = new VersionedObjectInput(ois, geodeVersion);
-        this.view = DataSerializer.readObject(ois2);
-        logger.info("Initial membership is " + view);
-        return true;
+        ois2 = new VersionedObjectInput(ois2, geodeVersion);
       }
-      return false;
+    
+      this.view = DataSerializer.readObject(ois2);
+      logger.info("Peer locator initial membership is " + view);
+      return true;
+
     } catch (Exception e) {
       String msg = LOCATOR_UNABLE_TO_RECOVER_VIEW.toLocalizedString(file.toString());
       logger.warn(msg, e);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
index 6e7abbd..9414dfa 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
@@ -64,6 +64,8 @@ import com.gemstone.gemfire.security.AuthenticationFailedException;
  * 
  */
 public class GMSJoinLeave implements JoinLeave, MessageHandler {
+  
+  public static String BYPASS_DISCOVERY = "gemfire.bypass-discovery";
 
   /** number of times to try joining before giving up */
   private static final int JOIN_ATTEMPTS = Integer.getInteger("gemfire.join-attempts", 4);
@@ -153,15 +155,15 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
    * @return true if successful, false if not
    */
   public boolean join() {
-
-    if (this.localAddress.getVmKind() == LOCATOR_DM_TYPE
-        && Boolean.getBoolean("gemfire.first-member")) {
+    Set<InternalDistributedMember> alreadyTried = new HashSet<>();
+    
+    if (Boolean.getBoolean(BYPASS_DISCOVERY)) {
       becomeCoordinator();
       return true;
     }
 
     for (int tries=0; tries<JOIN_ATTEMPTS; tries++) {
-      InternalDistributedMember coord = findCoordinator();
+      InternalDistributedMember coord = findCoordinator(alreadyTried);
       logger.debug("found possible coordinator {}", coord);
       if (coord != null) {
         if (coord.equals(this.localAddress)) {
@@ -172,7 +174,8 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
         } else {
           if (attemptToJoin(coord)) {
             return true;
-          } 
+          }
+          alreadyTried.add(coord);
         }
       }
       try {
@@ -211,8 +214,7 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
       response = joinResponse[0];
     }
     if (response != null) {
-// DEBUGGING - REMOVE
-logger.info("received join response {}", response);
+      logger.debug("received join response {}", response);
       joinResponse[0] = null;
       String failReason = response.getRejectionMessage();
       if (failReason != null) {
@@ -222,6 +224,12 @@ logger.info("received join response {}", response);
         }
         throw new AuthenticationFailedException(failReason);
       }
+      if (response.getBecomeCoordinator()) {
+        logger.info("I am being told to become the membership coordinator by {}", coord);
+        this.currentView = response.getCurrentView();
+        becomeCoordinator(response.getCurrentView().getCoordinator());
+        return true;
+      }
       if (response.getCurrentView() != null) {
         this.birthViewId = response.getMemberID().getVmViewId();
         this.localAddress.setVmViewId(this.birthViewId);
@@ -250,6 +258,12 @@ logger.info("received join response {}", response);
   private void processJoinRequest(JoinRequestMessage incomingRequest) {
 
     logger.info("received join request from {}", incomingRequest.getMemberID());
+
+    if (!this.localAddress.getNetMember().preferredForCoordinator() &&
+        incomingRequest.getMemberID().getNetMember().preferredForCoordinator()) {
+      // tell the new guy to become the coordinator
+      
+    }
     
     if (incomingRequest.getMemberID().getVersionObject().compareTo(Version.CURRENT) < 0) {
       logger.warn("detected an attempt to start a peer using an older version of the product {}",
@@ -574,14 +588,16 @@ logger.info("received join response {}", response);
    * coordinator and return it.
    * @return
    */
-  private InternalDistributedMember findCoordinator() {
+  private InternalDistributedMember findCoordinator(Set<InternalDistributedMember> alreadyTried) {
     assert this.localAddress != null;
     
-    FindCoordinatorRequest request = new FindCoordinatorRequest(this.localAddress);
+    FindCoordinatorRequest request = new FindCoordinatorRequest(this.localAddress, alreadyTried);
     Set<InternalDistributedMember> coordinators = new HashSet<InternalDistributedMember>();
     long giveUpTime = System.currentTimeMillis() + (services.getConfig().getLocatorWaitTime() * 1000L);
     boolean anyResponses = false;
     
+    logger.debug("sending {} to {}", request, locators);
+    
     do {
       for (InetSocketAddress addr: locators) { 
         try {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messages/JoinResponseMessage.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messages/JoinResponseMessage.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messages/JoinResponseMessage.java
index ab88849..d85229c 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messages/JoinResponseMessage.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messages/JoinResponseMessage.java
@@ -18,6 +18,7 @@ public class JoinResponseMessage extends HighPriorityDistributionMessage {
   private String rejectionMessage;
   private InternalDistributedMember memberID;
   private Object messengerData;
+  private boolean becomeCoordinator;
   
   public JoinResponseMessage(InternalDistributedMember memberID, NetView view) {
     this.currentView = view;
@@ -25,6 +26,13 @@ public class JoinResponseMessage extends HighPriorityDistributionMessage {
     setRecipient(memberID);
   }
   
+  public JoinResponseMessage(InternalDistributedMember memberID, NetView view, boolean becomeCoordinator) {
+    this.currentView = view;
+    this.memberID = memberID;
+    setRecipient(memberID);
+    this.becomeCoordinator = becomeCoordinator;
+  }
+  
   public JoinResponseMessage(String rejectionMessage) {
     this.rejectionMessage = rejectionMessage;
   }
@@ -40,6 +48,10 @@ public class JoinResponseMessage extends HighPriorityDistributionMessage {
   public InternalDistributedMember getMemberID() {
     return memberID;
   }
+  
+  public boolean getBecomeCoordinator() {
+    return becomeCoordinator;
+  }
 
   public String getRejectionMessage() {
     return rejectionMessage;
@@ -62,7 +74,8 @@ public class JoinResponseMessage extends HighPriorityDistributionMessage {
   public String toString() {
     return getShortClassName() + "("+memberID + "; "
         + (currentView==null? "" : currentView.toString())
-        + (rejectionMessage==null? "" : rejectionMessage)
+        + (rejectionMessage==null? "" : ("; "+rejectionMessage))
+        + (becomeCoordinator? "; becomeCoordinator" : "")
         + ")";
   }
   
@@ -80,6 +93,7 @@ public class JoinResponseMessage extends HighPriorityDistributionMessage {
   public void toData(DataOutput out) throws IOException {
     DataSerializer.writeObject(currentView, out);
     DataSerializer.writeObject(memberID, out);
+    out.writeBoolean(becomeCoordinator);
     DataSerializer.writeString(rejectionMessage, out);
     DataSerializer.writeObject(messengerData, out);
   }
@@ -88,6 +102,7 @@ public class JoinResponseMessage extends HighPriorityDistributionMessage {
   public void fromData(DataInput in) throws IOException, ClassNotFoundException {
     currentView = DataSerializer.readObject(in);
     memberID = DataSerializer.readObject(in);
+    becomeCoordinator = in.readBoolean();
     rejectionMessage = DataSerializer.readString(in);
     messengerData = DataSerializer.readObject(in);
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessenger.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessenger.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessenger.java
index a653110..d7f2723 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessenger.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessenger.java
@@ -348,7 +348,8 @@ public class JGroupsMessenger implements Messenger {
     myChannel.down(new Event(Event.SET_LOCAL_ADDRESS, this.jgAddress));
 
     DistributionConfig config = services.getConfig().getDistributionConfig();
-    boolean isLocator = (services.getConfig().getTransport().getVmKind() == DistributionManager.LOCATOR_DM_TYPE); 
+    boolean isLocator = (services.getConfig().getTransport().getVmKind() == DistributionManager.LOCATOR_DM_TYPE)
+        || !services.getConfig().getDistributionConfig().getStartLocator().isEmpty();
     
     // establish the DistributedSystem's address
     DurableClientAttributes dca = null;
@@ -423,8 +424,7 @@ public class JGroupsMessenger implements Messenger {
     JGAddress local = this.jgAddress;
     
     if (useMcast) {
-      if (logger.isTraceEnabled())
-        logger.trace("This message is being multicast");
+      logger.trace("This message is being multicast");
 
       Exception problem = null;
       try {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/StatRecorder.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/StatRecorder.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/StatRecorder.java
index 49dc423..1fef0da 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/StatRecorder.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/StatRecorder.java
@@ -57,6 +57,7 @@ public class StatRecorder extends Protocol {
       Message msg = (Message)evt.getArg();
       processForMulticast(msg, INCOMING);
       processForUnicast(msg, INCOMING);
+      break;
     }
     return down_prot.down(evt);
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/mgr/GMSMembershipManager.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/mgr/GMSMembershipManager.java b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/mgr/GMSMembershipManager.java
index ec2bd53..9c4d061 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/mgr/GMSMembershipManager.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/mgr/GMSMembershipManager.java
@@ -2920,9 +2920,11 @@ public class GMSMembershipManager implements MembershipManager, Manager
       // information.  This has caused client failures in bridge/wan
       // network-down testing
       InternalLocator loc = (InternalLocator)Locator.getLocator();
-      loc.stop(!services.getConfig().getDistributionConfig()
+      if (loc != null) {
+        loc.stop(!services.getConfig().getDistributionConfig()
                      .getDisableAutoReconnect(), false);
-
+      }
+      
       uncleanShutdown(reason, shutdownCause);
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
index db7c217..5a09b55 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/LocatorJUnitTest.java
@@ -104,7 +104,6 @@ public class LocatorJUnitTest {
 
   @Test
   public void testServerOnly() throws Exception {
-    fail("testServerOnly must be fixed for the jgroups replacement");
     Properties props = new Properties();
     props.setProperty("mcast-port", "0");
     props.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
@@ -112,15 +111,6 @@ public class LocatorJUnitTest {
     Assert.assertFalse(locator.isPeerLocator());
     Assert.assertTrue(locator.isServerLocator());
     Thread.sleep(1000);
-    try {
-      // TODO fix this part of the test
-//      GossipData request = new GossipData(GossipData.REGISTER_REQ, "group", new IpAddress(InetAddress.getLocalHost(), 55), null, null);
-//      TcpClient.requestToServer(InetAddress.getLocalHost(), port, request, REQUEST_TIMEOUT);
-      Assert.fail("Should have got an exception");
-    } catch (Exception expected) {
-//      expected.printStackTrace();
-    }
-
     doServerLocation();
   }
 
@@ -136,7 +126,6 @@ public class LocatorJUnitTest {
     Assert.assertTrue(locator.isServerLocator());
     Thread.sleep(1000);
     doServerLocation();
-    doGossip();
     locator.stop();
   }
 
@@ -153,37 +142,6 @@ public class LocatorJUnitTest {
     }
   }
 
-  //TODO - test durable queue discovery, excluded servers, server groups.
-
-  private void doGossip()  throws Exception {
-    fail("doGossip must be fixed for the jgroups replacement");
-    // TODO
-//    final GossipClient client = new GossipClient(new IpAddress(InetAddress.getLocalHost(), port),  500);
-//    client.register("mygroup1", new IpAddress(InetAddress.getLocalHost(), 55),5000, false);
-    WaitCriterion ev = new WaitCriterion() {
-      public boolean done() {
-        try {
-          // TODO
-//          Vector members = client.getMembers("mygroup1",
-//              new IpAddress(InetAddress.getLocalHost(), 55), true,5000);
-//          return members.size() == 1;
-        }
-        catch (Exception e) {
-          e.printStackTrace();
-          fail("unexpected exception");
-        }
-        return false; // NOTREACHED
-      }
-      public String description() {
-        return null;
-      }
-    };
-    DistributedTestCase.waitForCriterion(ev, 1 * 1000, 200, true);
-    // TODO
-//    Vector members = client.getMembers("mygroup1", new IpAddress(InetAddress.getLocalHost(), 55), true,5000);
-//    Assert.assertEquals(new IpAddress(InetAddress.getLocalHost(), 55), members.get(0));
-  }
-
   private void doServerLocation() throws Exception {
     {
       ClientConnectionRequest request = new ClientConnectionRequest(Collections.EMPTY_SET, "group1");

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/MembershipJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/MembershipJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/MembershipJUnitTest.java
index b668f7a..92cc6ad 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/MembershipJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/MembershipJUnitTest.java
@@ -165,10 +165,15 @@ public class MembershipJUnitTest extends TestCase {
           DistributionManager.NORMAL_DM_TYPE);
 
       // start the first membership manager
-      DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
-      DMStats stats1 = mock(DMStats.class);
-      m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
-
+      try {
+        System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY, "true");
+        DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
+        DMStats stats1 = mock(DMStats.class);
+        m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
+      } finally {
+        System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY);
+      }
+      
       // start the second membership manager
       DistributedMembershipListener listener2 = mock(DistributedMembershipListener.class);
       DMStats stats2 = mock(DMStats.class);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/GMSLocatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/GMSLocatorJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/GMSLocatorJUnitTest.java
index e79dcbc..048dd65 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/GMSLocatorJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/locator/GMSLocatorJUnitTest.java
@@ -2,19 +2,37 @@ package com.gemstone.gemfire.distributed.internal.membership.gms.locator;
 
 import com.gemstone.gemfire.DataSerializer;
 import com.gemstone.gemfire.InternalGemFireException;
+import com.gemstone.gemfire.distributed.Locator;
+import com.gemstone.gemfire.distributed.internal.DMStats;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.distributed.internal.DistributionConfigImpl;
+import com.gemstone.gemfire.distributed.internal.DistributionManager;
+import com.gemstone.gemfire.distributed.internal.InternalLocator;
+import com.gemstone.gemfire.distributed.internal.LocatorStats;
+import com.gemstone.gemfire.distributed.internal.membership.DistributedMembershipListener;
+import com.gemstone.gemfire.distributed.internal.membership.MemberFactory;
+import com.gemstone.gemfire.distributed.internal.membership.MembershipManager;
 import com.gemstone.gemfire.distributed.internal.membership.NetView;
+import com.gemstone.gemfire.internal.AvailablePortHelper;
+import com.gemstone.gemfire.internal.SocketCreator;
 import com.gemstone.gemfire.internal.Version;
+import com.gemstone.gemfire.internal.admin.remote.RemoteTransportConfig;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.ObjectOutputStream;
+import java.net.InetAddress;
+import java.util.Properties;
 
 import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
 
 @Category(UnitTest.class)
 public class GMSLocatorJUnitTest {
@@ -24,8 +42,8 @@ public class GMSLocatorJUnitTest {
 
   @Before
   public void setUp() throws Exception {
-    tempStateFile = File.createTempFile("tempLocator-", ".dat", new File("/tmp"));
-    locator = new GMSLocator(null, tempStateFile, null, false, false);
+    tempStateFile = File.createTempFile("tempLocator-", ".dat", new File(""));
+    locator = new GMSLocator(null, tempStateFile, null, false, false, new LocatorStats());
     // System.out.println("temp state file: " + tempStateFile);
   }
 
@@ -83,5 +101,59 @@ public class GMSLocatorJUnitTest {
     }
   }
 
+  @Test
+  public void testRecoverFromOther() throws Exception {
+    
+    MembershipManager m1=null, m2=null;
+    Locator l = null;
+    
+    try {
+      
+      // boot up a locator
+      int port = AvailablePortHelper.getRandomAvailableTCPPort();
+      InetAddress localHost = SocketCreator.getLocalHost();
+      
+      // this locator will hook itself up with the first MembershipManager
+      // to be created
+//      l = Locator.startLocator(port, new File(""), localHost);
+      l = InternalLocator.startLocator(port, new File(""), null,
+          null, null, localHost, false, new Properties(), true, false, null,
+          false);
+      
+      // create configuration objects
+      Properties nonDefault = new Properties();
+      nonDefault.put(DistributionConfig.DISABLE_TCP_NAME, "true");
+      nonDefault.put(DistributionConfig.MCAST_PORT_NAME, "0");
+      nonDefault.put(DistributionConfig.LOG_FILE_NAME, "");
+      nonDefault.put(DistributionConfig.LOG_LEVEL_NAME, "fine");
+      nonDefault.put(DistributionConfig.LOCATORS_NAME, localHost.getHostName()+'['+port+']');
+      DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
+      RemoteTransportConfig transport = new RemoteTransportConfig(config,
+          DistributionManager.NORMAL_DM_TYPE);
+
+      // start the first membership manager
+      DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
+      DMStats stats1 = mock(DMStats.class);
+      m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
+      
+      // hook up the locator to the membership manager
+      ((InternalLocator)l).getLocatorHandler().setMembershipManager(m1);
+      
+      GMSLocator l2 = new GMSLocator(SocketCreator.getLocalHost(), new File("l2.dat"),
+          m1.getLocalMember().getHost()+"["+port+"]", true, true, new LocatorStats());
+      l2.init(null);
+      
+      assertTrue("expected view to contain "
+          + m1.getLocalMember() + ": " + l2.getMembers(),
+          l2.getMembers().contains(m1.getLocalMember()));
+    } finally {
+      if (m1 != null) {
+        m1.shutdown();
+      }
+      if (l != null) {
+        l.stop();
+      }
+    }
+  }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java
index cbabc20..822e074 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeaveJUnitTest.java
@@ -10,6 +10,7 @@ import static org.mockito.Mockito.verify;
 
 import java.io.IOException;
 import java.net.UnknownHostException;
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -393,6 +394,55 @@ public class GMSJoinLeaveJUnitTest {
     Assert.assertTrue("Expected becomeCoordinator to be invoked", gmsJoinLeave.isCoordinator());
   }
 
+  @Test
+  public void testBecomeCoordinatorThroughRemove() throws Exception {
+    String reason = "testing";
+    initMocks();
+    prepareAndInstallView();
+    NetView view = gmsJoinLeave.getView();
+    view.add(gmsJoinLeaveMemberId);
+    InternalDistributedMember creator = view.getCreator();
+    RemoveMemberMessage msg = new RemoveMemberMessage(creator, creator, reason);
+    msg.setSender(creator);
+    gmsJoinLeave.processMessage(msg);
+    Assert.assertTrue("Expected becomeCoordinator to be invoked", gmsJoinLeave.isCoordinator());
+  }
+
+  @Test
+  public void testBecomeCoordinatorThroughViewChange() throws Exception {
+    String reason = "testing";
+    initMocks();
+    prepareAndInstallView();
+    NetView oldView = gmsJoinLeave.getView();
+    oldView.add(gmsJoinLeaveMemberId);
+    NetView view = new NetView(oldView, oldView.getViewId()+1);
+    InternalDistributedMember creator = view.getCreator();
+    view.remove(creator);
+    InstallViewMessage msg = new InstallViewMessage(view, creator);
+    msg.setSender(creator);
+    gmsJoinLeave.processMessage(msg);
+    Assert.assertTrue("Expected it to become coordinator", gmsJoinLeave.isCoordinator());
+  }
+
+  @Test
+  public void testBecomeParticipantThroughViewChange() throws Exception {
+    String reason = "testing";
+    initMocks();
+    prepareAndInstallView();
+    NetView oldView = gmsJoinLeave.getView();
+    oldView.add(gmsJoinLeaveMemberId);
+    InternalDistributedMember creator = oldView.getCreator();
+    gmsJoinLeave.becomeCoordinator();
+    NetView view = new NetView(2, gmsJoinLeave.getView().getViewId()+1);
+    view.setCreator(creator);
+    view.add(creator);
+    view.add(gmsJoinLeaveMemberId);
+    InstallViewMessage msg = new InstallViewMessage(view, creator);
+    msg.setSender(creator);
+    gmsJoinLeave.processMessage(msg);
+    Assert.assertTrue("Expected it to stop being coordinator", !gmsJoinLeave.isCoordinator());
+  }
+
   @Test 
   public void testNetworkPartitionDetected() throws IOException {
     initMocks(true);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/InterceptUDP.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/InterceptUDP.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/InterceptUDP.java
index aafb466..4cf4237 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/InterceptUDP.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/InterceptUDP.java
@@ -10,12 +10,13 @@ import org.jgroups.Message;
 import org.jgroups.conf.ClassConfigurator;
 import org.jgroups.protocols.UNICAST3;
 import org.jgroups.protocols.pbcast.NAKACK2;
+import org.jgroups.protocols.pbcast.NakAckHeader2;
 import org.jgroups.stack.IpAddress;
 import org.jgroups.stack.Protocol;
 import org.jgroups.util.UUID;
 
 /**
- * FakeUDP replaces the regular UDP JGroups messaging protocol
+ * InterceptUDP replaces the regular UDP JGroups messaging protocol
  * for unit testing.  It does not create a datagram socket
  * and is only set up to record message counts and respond
  * to Unicast to keep it from retransmitting
@@ -31,6 +32,7 @@ public class InterceptUDP extends Protocol {
 //  IpAddress addr;
 //  Map<UUID, IpAddress> addressMap;
   int unicastSentDataMessages;
+  int mcastSentDataMessages;
   
   public InterceptUDP() {
 //    uuid = new UUID();
@@ -63,16 +65,20 @@ public class InterceptUDP extends Protocol {
   
   private void handleMessage(Message msg) {
     Object o = msg.getHeader(nakackHeaderId);
-    o = msg.getHeader(unicastHeaderId);
     if (o != null) {
-      UNICAST3.Header hdr = (UNICAST3.Header)o;
-      switch (hdr.type()) {
-      case UNICAST3.Header.DATA:
-        unicastSentDataMessages++;
-        Message response = new Message(uuid, msg.getDest(), null);
-        response.putHeader(unicastHeaderId, UNICAST3.Header.createAckHeader(hdr.seqno(), hdr.connId(), System.currentTimeMillis()));
-        up_prot.up(new Event(Event.MSG, response));
-        break;
+      mcastSentDataMessages++;
+    } else {
+      o = msg.getHeader(unicastHeaderId);
+      if (o != null) {
+        UNICAST3.Header hdr = (UNICAST3.Header)o;
+        switch (hdr.type()) {
+        case UNICAST3.Header.DATA:
+          unicastSentDataMessages++;
+          Message response = new Message(uuid, msg.getDest(), null);
+          response.putHeader(unicastHeaderId, UNICAST3.Header.createAckHeader(hdr.seqno(), hdr.connId(), System.currentTimeMillis()));
+          up_prot.up(new Event(Event.MSG, response));
+          break;
+        }
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
index 515c115..3b1c1dc 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/gms/messenger/JGroupsMessengerJUnitTest.java
@@ -7,6 +7,7 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import java.util.List;
 import java.util.Properties;
 
 import org.jgroups.Event;
@@ -21,7 +22,9 @@ import com.gemstone.gemfire.distributed.internal.DMStats;
 import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.distributed.internal.DistributionConfigImpl;
 import com.gemstone.gemfire.distributed.internal.DistributionManager;
+import com.gemstone.gemfire.distributed.internal.SerialAckedMessage;
 import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
+import com.gemstone.gemfire.distributed.internal.membership.NetView;
 import com.gemstone.gemfire.distributed.internal.membership.gms.GMSMember;
 import com.gemstone.gemfire.distributed.internal.membership.gms.ServiceConfig;
 import com.gemstone.gemfire.distributed.internal.membership.gms.Services;
@@ -31,6 +34,7 @@ import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.Manag
 import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.MessageHandler;
 import com.gemstone.gemfire.distributed.internal.membership.gms.messages.JoinRequestMessage;
 import com.gemstone.gemfire.distributed.internal.membership.gms.messages.LeaveRequestMessage;
+import com.gemstone.gemfire.internal.AvailablePortHelper;
 import com.gemstone.gemfire.internal.Version;
 import com.gemstone.gemfire.internal.admin.remote.RemoteTransportConfig;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
@@ -48,11 +52,11 @@ public class JGroupsMessengerJUnitTest {
   /**
    * Create stub and mock objects
    */
-  @Before
-  public void initMocks() throws Exception {
+  private void initMocks(boolean enableMcast) throws Exception {
     Properties nonDefault = new Properties();
     nonDefault.put(DistributionConfig.DISABLE_TCP_NAME, "true");
-    nonDefault.put(DistributionConfig.MCAST_PORT_NAME, "0");
+    nonDefault.put(DistributionConfig.MCAST_PORT_NAME, enableMcast? ""+AvailablePortHelper.getRandomAvailableUDPPort() : "0");
+    nonDefault.put(DistributionConfig.MCAST_TTL_NAME, "0");
     nonDefault.put(DistributionConfig.LOG_FILE_NAME, "");
     nonDefault.put(DistributionConfig.LOG_LEVEL_NAME, "fine");
     nonDefault.put(DistributionConfig.LOCATORS_NAME, "localhost[10344]");
@@ -106,9 +110,23 @@ public class JGroupsMessengerJUnitTest {
   
   @Test
   public void testMessageDeliveredToHandler() throws Exception {
+    doTestMessageDeliveredToHandler(false);
+  }
+  
+  @Test
+  public void testMessageDeliveredToHandlerMcast() throws Exception {
+    doTestMessageDeliveredToHandler(true);
+  }
+  
+  private void doTestMessageDeliveredToHandler(boolean mcast) throws Exception {
+    initMocks(mcast);
     MessageHandler mh = mock(MessageHandler.class);
     messenger.addHandler(JoinRequestMessage.class, mh);
     
+    InternalDistributedMember addr = messenger.getMemberID();
+    NetView v = new NetView(addr);
+    when(joinLeave.getView()).thenReturn(v);
+
     InternalDistributedMember sender = createAddress(8888);
     JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null);
     
@@ -128,15 +146,38 @@ public class JGroupsMessengerJUnitTest {
   
   @Test
   public void testBigMessageIsFragmented() throws Exception {
+    doTestBigMessageIsFragmented(false, false);
+  }
+
+  @Test
+  public void testBigMessageIsFragmentedMcast() throws Exception {
+    doTestBigMessageIsFragmented(true, true);
+  }
+  
+  @Test
+  public void testBroadcastUDPMessage() throws Exception {
+    doTestBigMessageIsFragmented(false, true);
+  }
+
+  public void doTestBigMessageIsFragmented(boolean mcastEnabled, boolean mcastMsg) throws Exception {
+    initMocks(mcastEnabled);
     MessageHandler mh = mock(MessageHandler.class);
     messenger.addHandler(JoinRequestMessage.class, mh);
     
-    InternalDistributedMember sender = createAddress(8888);
+    InternalDistributedMember sender = messenger.getMemberID();
+    NetView v = new NetView(sender);
+    when(joinLeave.getView()).thenReturn(v);
+    messenger.installView(v);
     JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null);
+    if (mcastMsg) {
+      msg.setMulticast(true);
+    }
 
     messenger.send(msg);
-    assertTrue("expected 1 message to be sent but found "+ interceptor.unicastSentDataMessages,
-        interceptor.unicastSentDataMessages == 1);
+    int sentMessages = (mcastEnabled && mcastMsg) ? interceptor.mcastSentDataMessages
+        : interceptor.unicastSentDataMessages;
+    assertTrue("expected 1 message to be sent but found "+ sentMessages,
+        sentMessages == 1);
 
     // send a big message and expect fragmentation
     msg = new JoinRequestMessage(messenger.localAddress, sender, new byte[(int)(services.getConfig().getDistributionConfig().getUdpFragmentSize()*(1.5))]);
@@ -149,6 +190,28 @@ public class JGroupsMessengerJUnitTest {
   }
   
   
+  @Test
+  public void testSendToMultipleMembers() throws Exception {
+    initMocks(false);
+    InternalDistributedMember sender = messenger.getMemberID();
+    InternalDistributedMember other = new InternalDistributedMember("localhost", 8888);
+
+    NetView v = new NetView(sender);
+    v.add(other);
+    when(joinLeave.getView()).thenReturn(v);
+    messenger.installView(v);
+
+    List<InternalDistributedMember> recipients = v.getMembers();
+    SerialAckedMessage msg = new SerialAckedMessage();
+    msg.setRecipients(recipients);
+
+    messenger.send(msg);
+    int sentMessages = interceptor.unicastSentDataMessages;
+    assertTrue("expected 2 message to be sent but found "+ sentMessages,
+        sentMessages == 2);
+  }
+  
+  
   /**
    * creates an InternalDistributedMember address that can be used
    * with the doctored JGroups channel.  This includes a logical

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerJUnitDisabledTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerJUnitDisabledTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerJUnitDisabledTest.java
deleted file mode 100644
index 1cab817..0000000
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerJUnitDisabledTest.java
+++ /dev/null
@@ -1,203 +0,0 @@
-package com.gemstone.gemfire.distributed.internal.tcpserver;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.net.ConnectException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Properties;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import com.gemstone.gemfire.DataSerializable;
-import com.gemstone.gemfire.cache.GemFireCache;
-import com.gemstone.gemfire.distributed.DistributedSystem;
-import com.gemstone.gemfire.distributed.internal.PoolStatHelper;
-import com.gemstone.gemfire.distributed.internal.SharedConfiguration;
-import com.gemstone.gemfire.distributed.internal.tcpserver.TcpClient;
-import com.gemstone.gemfire.distributed.internal.tcpserver.TcpHandler;
-import com.gemstone.gemfire.distributed.internal.tcpserver.TcpServer;
-import com.gemstone.gemfire.internal.AvailablePort;
-//import com.gemstone.org.jgroups.stack.GossipClient;
-//import com.gemstone.org.jgroups.stack.IpAddress;
-
-public class TcpServerJUnitDisabledTest extends TestCase {
-  
-  protected/*GemStoneAddition*/ InetAddress localhost;
-  protected/*GemStoneAddition*/ int port;
-  private SimpleStats stats;
-  private TcpServer server;
-
-  public void start(TcpHandler handler) throws IOException {
-    localhost = InetAddress.getLocalHost();
-    port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    
-    stats = new SimpleStats();
-    server = new TcpServer(port, localhost , new Properties(), null, handler, stats, Thread.currentThread().getThreadGroup(), "server thread");
-    server.start();
-  }
-  
-  
-  public void test() throws UnknownHostException, IOException, ClassNotFoundException, InterruptedException {
-    EchoHandler handler = new EchoHandler();
-    start(handler);
-    
-    TestObject test = new TestObject();
-    test.id = 5;
-    TestObject result = (TestObject) TcpClient.requestToServer(localhost, port, test, 60 * 1000 );
-    Assert.assertEquals(test.id, result.id);
-    
-    String[] info = TcpClient.getInfo(localhost, port);
-    Assert.assertNotNull(info);
-    Assert.assertTrue(info.length > 1);
-   
-    try { 
-      TcpClient.stop(localhost, port);
-    } catch ( ConnectException ignore ) {
-      // must not be running 
-    }
-    server.join(60 * 1000);
-    Assert.assertFalse(server.isAlive());
-    Assert.assertTrue(handler.shutdown);
-    
-    Assert.assertEquals(3, stats.started.get());
-    Assert.assertEquals(3, stats.ended.get());
-    
-  }
-  
-  public void testConcurrency() throws UnknownHostException, IOException, ClassNotFoundException, InterruptedException {
-    CountDownLatch latch = new CountDownLatch(1);
-    DelayHandler handler = new DelayHandler(latch);
-    start(handler);
-    
-    final AtomicBoolean done = new AtomicBoolean();
-    Thread delayedThread = new Thread() {
-      public void run() {
-        Boolean delay = Boolean.valueOf(true);
-        try {
-          TcpClient.requestToServer(localhost, port, delay, 60 * 1000 );
-        } catch (IOException e) {
-          e.printStackTrace();
-        } catch (ClassNotFoundException e) {
-          e.printStackTrace();
-        }
-        done.set(true);
-      }
-    };
-    delayedThread.start();
-    try {
-      Thread.sleep(500);
-      Assert.assertFalse(done.get());
-      TcpClient.requestToServer(localhost, port, Boolean.valueOf(false), 60 * 1000 );
-      Assert.assertFalse(done.get());
-
-      latch.countDown();
-      Thread.sleep(500);
-      Assert.assertTrue(done.get());
-    } finally {
-      latch.countDown();
-      delayedThread.join(60 * 1000);
-      Assert.assertTrue(!delayedThread.isAlive()); // GemStoneAddition
-      try {
-        TcpClient.stop(localhost, port);
-      } catch ( ConnectException ignore ) {
-        // must not be running 
-      }
-      server.join(60 * 1000);
-    }
-  }
-  
-  public static class TestObject implements DataSerializable {
-    int id;
-    
-    public TestObject() {
-      
-    }
-
-    public void fromData(DataInput in) throws IOException {
-      id = in.readInt();
-    }
-
-    public void toData(DataOutput out) throws IOException {
-      out.writeInt(id);
-    }
-    
-  }
-
-  protected/*GemStoneAddition*/ static class EchoHandler implements TcpHandler {
-
-    protected/*GemStoneAddition*/ boolean shutdown;
-
-
-    public void init(TcpServer tcpServer) {
-      // TODO Auto-generated method stub
-      
-    }
-
-    public Object processRequest(Object request) throws IOException {
-      return request;
-    }
-
-    public void shutDown() {
-      shutdown = true;
-    }
-    
-    public void restarting(DistributedSystem ds, GemFireCache cache, SharedConfiguration sharedConfig) { }
-    public void endRequest(Object request,long startTime) { }
-    public void endResponse(Object request,long startTime) { }
-    
-  }
-  
-  private static class DelayHandler implements TcpHandler {
-
-    private CountDownLatch latch;
-
-    public DelayHandler(CountDownLatch latch) {
-      this.latch = latch;
-    }
-
-    public void init(TcpServer tcpServer) {
-    }
-
-    public Object processRequest(Object request) throws IOException {
-      Boolean delay = (Boolean) request;
-      if(delay.booleanValue()) {
-        try {
-          latch.await(120 * 1000, TimeUnit.MILLISECONDS);
-        } catch (InterruptedException e) {
-          Thread.currentThread().interrupt();
-        }
-        return delay;
-      }
-      else {
-        return delay;
-      }
-    }
-
-    public void shutDown() {
-    }
-    public void restarting(DistributedSystem ds, GemFireCache cache, SharedConfiguration sharedConfig) { }
-    public void endRequest(Object request,long startTime) { }
-    public void endResponse(Object request,long startTime) { }
-  }
-  
-  protected/*GemStoneAddition*/ static class SimpleStats implements PoolStatHelper {
-    AtomicInteger started = new AtomicInteger();
-    AtomicInteger ended = new AtomicInteger();
-    
-
-    public void endJob() {
-      started.incrementAndGet();
-    }
-
-    public void startJob() {
-      ended.incrementAndGet();
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerJUnitTest.java
new file mode 100644
index 0000000..f6c5b20
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerJUnitTest.java
@@ -0,0 +1,203 @@
+package com.gemstone.gemfire.distributed.internal.tcpserver;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.net.ConnectException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import com.gemstone.gemfire.DataSerializable;
+import com.gemstone.gemfire.cache.GemFireCache;
+import com.gemstone.gemfire.distributed.DistributedSystem;
+import com.gemstone.gemfire.distributed.internal.PoolStatHelper;
+import com.gemstone.gemfire.distributed.internal.SharedConfiguration;
+import com.gemstone.gemfire.distributed.internal.tcpserver.TcpClient;
+import com.gemstone.gemfire.distributed.internal.tcpserver.TcpHandler;
+import com.gemstone.gemfire.distributed.internal.tcpserver.TcpServer;
+import com.gemstone.gemfire.internal.AvailablePort;
+//import com.gemstone.org.jgroups.stack.GossipClient;
+//import com.gemstone.org.jgroups.stack.IpAddress;
+
+public class TcpServerJUnitTest extends TestCase {
+  
+  protected/*GemStoneAddition*/ InetAddress localhost;
+  protected/*GemStoneAddition*/ int port;
+  private SimpleStats stats;
+  private TcpServer server;
+
+  public void start(TcpHandler handler) throws IOException {
+    localhost = InetAddress.getLocalHost();
+    port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+    
+    stats = new SimpleStats();
+    server = new TcpServer(port, localhost , new Properties(), null, handler, stats, Thread.currentThread().getThreadGroup(), "server thread");
+    server.start();
+  }
+  
+  
+  public void test() throws UnknownHostException, IOException, ClassNotFoundException, InterruptedException {
+    EchoHandler handler = new EchoHandler();
+    start(handler);
+    
+    TestObject test = new TestObject();
+    test.id = 5;
+    TestObject result = (TestObject) TcpClient.requestToServer(localhost, port, test, 60 * 1000 );
+    Assert.assertEquals(test.id, result.id);
+    
+    String[] info = TcpClient.getInfo(localhost, port);
+    Assert.assertNotNull(info);
+    Assert.assertTrue(info.length > 1);
+   
+    try { 
+      TcpClient.stop(localhost, port);
+    } catch ( ConnectException ignore ) {
+      // must not be running 
+    }
+    server.join(60 * 1000);
+    Assert.assertFalse(server.isAlive());
+    Assert.assertTrue(handler.shutdown);
+    
+    Assert.assertEquals(4, stats.started.get());
+    Assert.assertEquals(4, stats.ended.get());
+    
+  }
+  
+  public void testConcurrency() throws UnknownHostException, IOException, ClassNotFoundException, InterruptedException {
+    CountDownLatch latch = new CountDownLatch(1);
+    DelayHandler handler = new DelayHandler(latch);
+    start(handler);
+    
+    final AtomicBoolean done = new AtomicBoolean();
+    Thread delayedThread = new Thread() {
+      public void run() {
+        Boolean delay = Boolean.valueOf(true);
+        try {
+          TcpClient.requestToServer(localhost, port, delay, 60 * 1000 );
+        } catch (IOException e) {
+          e.printStackTrace();
+        } catch (ClassNotFoundException e) {
+          e.printStackTrace();
+        }
+        done.set(true);
+      }
+    };
+    delayedThread.start();
+    try {
+      Thread.sleep(500);
+      Assert.assertFalse(done.get());
+      TcpClient.requestToServer(localhost, port, Boolean.valueOf(false), 60 * 1000 );
+      Assert.assertFalse(done.get());
+
+      latch.countDown();
+      Thread.sleep(500);
+      Assert.assertTrue(done.get());
+    } finally {
+      latch.countDown();
+      delayedThread.join(60 * 1000);
+      Assert.assertTrue(!delayedThread.isAlive()); // GemStoneAddition
+      try {
+        TcpClient.stop(localhost, port);
+      } catch ( ConnectException ignore ) {
+        // must not be running 
+      }
+      server.join(60 * 1000);
+    }
+  }
+  
+  public static class TestObject implements DataSerializable {
+    int id;
+    
+    public TestObject() {
+      
+    }
+
+    public void fromData(DataInput in) throws IOException {
+      id = in.readInt();
+    }
+
+    public void toData(DataOutput out) throws IOException {
+      out.writeInt(id);
+    }
+    
+  }
+
+  protected/*GemStoneAddition*/ static class EchoHandler implements TcpHandler {
+
+    protected/*GemStoneAddition*/ boolean shutdown;
+
+
+    public void init(TcpServer tcpServer) {
+      // TODO Auto-generated method stub
+      
+    }
+
+    public Object processRequest(Object request) throws IOException {
+      return request;
+    }
+
+    public void shutDown() {
+      shutdown = true;
+    }
+    
+    public void restarting(DistributedSystem ds, GemFireCache cache, SharedConfiguration sharedConfig) { }
+    public void endRequest(Object request,long startTime) { }
+    public void endResponse(Object request,long startTime) { }
+    
+  }
+  
+  private static class DelayHandler implements TcpHandler {
+
+    private CountDownLatch latch;
+
+    public DelayHandler(CountDownLatch latch) {
+      this.latch = latch;
+    }
+
+    public void init(TcpServer tcpServer) {
+    }
+
+    public Object processRequest(Object request) throws IOException {
+      Boolean delay = (Boolean) request;
+      if(delay.booleanValue()) {
+        try {
+          latch.await(120 * 1000, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException e) {
+          Thread.currentThread().interrupt();
+        }
+        return delay;
+      }
+      else {
+        return delay;
+      }
+    }
+
+    public void shutDown() {
+    }
+    public void restarting(DistributedSystem ds, GemFireCache cache, SharedConfiguration sharedConfig) { }
+    public void endRequest(Object request,long startTime) { }
+    public void endResponse(Object request,long startTime) { }
+  }
+  
+  protected/*GemStoneAddition*/ static class SimpleStats implements PoolStatHelper {
+    AtomicInteger started = new AtomicInteger();
+    AtomicInteger ended = new AtomicInteger();
+    
+
+    public void endJob() {
+      started.incrementAndGet();
+    }
+
+    public void startJob() {
+      ended.incrementAndGet();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java
index 4f4ab03..2d0c0db 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/redis/RedisDistDUnitTest.java
@@ -7,6 +7,7 @@ import redis.clients.jedis.Jedis;
 import com.gemstone.gemfire.cache.CacheFactory;
 import com.gemstone.gemfire.cache30.CacheTestCase;
 import com.gemstone.gemfire.internal.AvailablePortHelper;
+import com.gemstone.gemfire.internal.SocketCreator;
 
 import dunit.AsyncInvocation;
 import dunit.Host;
@@ -51,18 +52,24 @@ public class RedisDistDUnitTest extends CacheTestCase {
     server2 = host.getVM(1);
     client1 = host.getVM(2);
     client2 = host.getVM(3);  
+    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(3);
     final SerializableCallable<Object> startRedisAdapter = new SerializableCallable<Object>() {
 
       private static final long serialVersionUID = 1978017907725504294L;
 
       @Override
       public Object call() throws Exception {
-        int port = AvailablePortHelper.getRandomAvailableTCPPort();
+        int port = ports[VM.getCurrentVMNum()+1];
         CacheFactory cF = new CacheFactory();
+        String locator = SocketCreator.getLocalHost() + "[" + ports[2] + "]";
         cF.set("log-level", "info");
         cF.set("redis-bind-address", "localhost");
         cF.set("redis-port", ""+port);
-        cF.set("mcast-port", "40404");
+        cF.set("mcast-port", "");
+        cF.set("locators", locator);
+        if (VM.getCurrentVMNum() == 0) {
+          cF.set("start-locator", locator);
+        }
         cF.create();
         return Integer.valueOf(port);
       }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/edc81a75/gemfire-core/src/test/java/dunit/standalone/DUnitLauncher.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/dunit/standalone/DUnitLauncher.java b/gemfire-core/src/test/java/dunit/standalone/DUnitLauncher.java
index 34b1aa1..c21dd72 100644
--- a/gemfire-core/src/test/java/dunit/standalone/DUnitLauncher.java
+++ b/gemfire-core/src/test/java/dunit/standalone/DUnitLauncher.java
@@ -44,6 +44,7 @@ import batterytest.greplogs.ExpectedStrings;
 import batterytest.greplogs.LogConsumer;
 
 import com.gemstone.gemfire.distributed.Locator;
+import com.gemstone.gemfire.distributed.internal.membership.gms.membership.GMSJoinLeave;
 import com.gemstone.gemfire.internal.AvailablePortHelper;
 import com.gemstone.gemfire.internal.logging.LogService;
 
@@ -236,9 +237,14 @@ public class DUnitLauncher {
         p.setProperty("enable-cluster-configuration", "false");
         //Tell the locator it's the first in the system for
         //faster boot-up
-        System.setProperty("gemfire.first-member", "true");
         
-        Locator.startLocatorAndDS(locatorPort, locatorLogFile, p);
+        System.setProperty(GMSJoinLeave.BYPASS_DISCOVERY, "true");
+        try {
+          Locator.startLocatorAndDS(locatorPort, locatorLogFile, p);
+        } finally {
+          System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY);
+        }
+        
         return null;
       }
     }, "call");


Mime
View raw message