geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [48/50] [abbrv] incubator-geode git commit: More JoinLeeve tests
Date Fri, 11 Dec 2015 22:06:21 GMT
More JoinLeeve tests


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

Branch: refs/heads/feature/GEODE-291
Commit: 7dfce7cd92c7f2d9e89374dd7799eb87dd8711b3
Parents: 81c472f
Author: Hitesh Khamesra <hiteshk25@yahoo.com>
Authored: Wed Dec 9 16:26:43 2015 -0800
Committer: Hitesh Khamesra <hiteshk25@yahoo.com>
Committed: Thu Dec 10 15:31:14 2015 -0800

----------------------------------------------------------------------
 .../gms/locator/FindCoordinatorRequest.java     | 33 ++++++++++
 .../membership/gms/membership/GMSJoinLeave.java | 31 ++++++++--
 .../gms/membership/GMSJoinLeaveJUnitTest.java   | 63 ++++++++++++++++++++
 3 files changed, 123 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dfce7cd/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 f1ec2a0..5c0a1d1 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
@@ -112,4 +112,37 @@ public class FindCoordinatorRequest extends HighPriorityDistributionMessage
     throw new IllegalStateException("this message should not be executed");
   }
 
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + lastViewId;
+    result = prime * result + ((memberID == null) ? 0 : memberID.hashCode());
+    result = prime * result + ((rejectedCoordinators == null) ? 0 : rejectedCoordinators.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    FindCoordinatorRequest other = (FindCoordinatorRequest) obj;
+    if (lastViewId != other.lastViewId)
+      return false;
+    if (memberID == null) {
+      if (other.memberID != null)
+        return false;
+    } else if (!memberID.equals(other.memberID))
+      return false;
+    if (rejectedCoordinators == null) {
+      if (other.rejectedCoordinators != null)
+        return false;
+    } else if (!rejectedCoordinators.equals(other.rejectedCoordinators))
+      return false;
+    return true;
+  }  
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dfce7cd/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 e1821db..3a3486b 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
@@ -313,7 +313,7 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
    * @param coord
    * @return true if the attempt succeeded, false if it timed out
    */
-  private boolean attemptToJoin() {
+   boolean attemptToJoin() {
     SearchState state = searchState;
 
     // send a join request to the coordinator and wait for a response
@@ -826,6 +826,15 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
     }
   }
 
+  private TcpClientWrapper tcpClientWrapper = new TcpClientWrapper();
+  
+  /***
+   * testing purpose
+   * @param tcpClientWrapper
+   */
+  void setTcpClientWrapper(TcpClientWrapper tcpClientWrapper) {
+    this.tcpClientWrapper = tcpClientWrapper;
+  }
   /**
    * This contacts the locators to find out who the current coordinator is.
    * All locators are contacted. If they don't agree then we choose the oldest
@@ -861,9 +870,7 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
     do {
       for (InetSocketAddress addr : locators) {
         try {
-          Object o = TcpClient.requestToServer(
-              addr.getAddress(), addr.getPort(), request, connectTimeout, 
-              true);
+          Object o = tcpClientWrapper.sendCoordinatorFindRequest(addr, request, connectTimeout);
           FindCoordinatorResponse response = (o instanceof FindCoordinatorResponse) ? (FindCoordinatorResponse)o
: null;
           if (response != null) {
             state.locatorsContacted++;
@@ -937,6 +944,15 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
     }
     return true;
   }
+  
+  protected class TcpClientWrapper {
+    protected Object sendCoordinatorFindRequest(InetSocketAddress addr, FindCoordinatorRequest
request, int connectTimeout) 
+        throws ClassNotFoundException, IOException{
+      return TcpClient.requestToServer(
+          addr.getAddress(), addr.getPort(), request, connectTimeout, 
+          true);
+    }
+  }    
 
   boolean findCoordinatorFromView() {
     ArrayList<FindCoordinatorResponse> result;
@@ -1051,6 +1067,13 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
   JoinResponseMessage[] getJoinResponseMessage() {
     return joinResponse;
   }
+  /***
+   * for testing purpose
+   * @param jrm
+   */
+  void setJoinResponseMessage(JoinResponseMessage jrm) {
+    joinResponse[0] = jrm;
+  }
 
   private void processFindCoordinatorRequest(FindCoordinatorRequest req) {
     FindCoordinatorResponse resp;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dfce7cd/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 01c0695..05b0996 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
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.io.IOException;
+import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -59,9 +60,11 @@ import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.Authe
 import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.HealthMonitor;
 import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.Manager;
 import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.Messenger;
+import com.gemstone.gemfire.distributed.internal.membership.gms.locator.FindCoordinatorRequest;
 import com.gemstone.gemfire.distributed.internal.membership.gms.locator.FindCoordinatorResponse;
 import com.gemstone.gemfire.distributed.internal.membership.gms.membership.GMSJoinLeave.SearchState;
 import com.gemstone.gemfire.distributed.internal.membership.gms.membership.GMSJoinLeave.ViewCreator;
+import com.gemstone.gemfire.distributed.internal.membership.gms.membership.GMSJoinLeave.TcpClientWrapper;
 import com.gemstone.gemfire.distributed.internal.membership.gms.membership.GMSJoinLeave.ViewReplyProcessor;
 import com.gemstone.gemfire.distributed.internal.membership.gms.messages.InstallViewMessage;
 import com.gemstone.gemfire.distributed.internal.membership.gms.messages.JoinRequestMessage;
@@ -99,6 +102,7 @@ public class GMSJoinLeaveJUnitTest {
     when(mockDistConfig.getEnableNetworkPartitionDetection()).thenReturn(enableNetworkPartition);
     when(mockDistConfig.getLocators()).thenReturn("localhost[8888]");
     mockConfig = mock(ServiceConfig.class);
+    when(mockDistConfig.getStartLocator()).thenReturn("localhost[12345]");
     when(mockConfig.getDistributionConfig()).thenReturn(mockDistConfig);
     when(mockDistConfig.getLocators()).thenReturn("localhost[12345]");
     when(mockDistConfig.getMcastPort()).thenReturn(0);
@@ -1028,5 +1032,64 @@ public class GMSJoinLeaveJUnitTest {
     assertTrue(newView.contains(mockMembers[1]));
     assertTrue(newView.getViewId() > preparedView.getViewId());
   }
+
+  private NetView createView() {
+    List<InternalDistributedMember> mbrs = new LinkedList<>();
+    Set<InternalDistributedMember> shutdowns = new HashSet<>();
+    Set<InternalDistributedMember> crashes = new HashSet<>();
+    mbrs.add(mockMembers[0]);
+    mbrs.add(mockMembers[1]);
+    mbrs.add(mockMembers[2]);
+    mbrs.add(gmsJoinLeaveMemberId);
+    
+    //prepare the view
+    NetView netView = new NetView(mockMembers[0], 1, mbrs, shutdowns, crashes);
+    return netView;
+  }
+  
+  @Test
+  public void testCoordinatorFindRequestSuccess()  throws Exception {
+    try{
+      initMocks(false);
+      HashSet<InternalDistributedMember> registrants = new HashSet<>();
+      registrants.add(mockMembers[0]);
+      FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0],
false, null, registrants, false, true);
+      NetView view = createView();
+      JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view);
+      gmsJoinLeave.setJoinResponseMessage(jrm);
+      
+      TcpClientWrapper tcpClientWrapper = mock(TcpClientWrapper.class);
+      gmsJoinLeave.setTcpClientWrapper(tcpClientWrapper);
+      FindCoordinatorRequest fcreq = new FindCoordinatorRequest(gmsJoinLeaveMemberId, new
HashSet<>(), -1);
+      int connectTimeout = (int)services.getConfig().getMemberTimeout() * 2;
+      when(tcpClientWrapper.sendCoordinatorFindRequest(new InetSocketAddress("localhost",
12345), fcreq, connectTimeout)).thenReturn(fcr);
+      assertTrue("Should be able to join ", gmsJoinLeave.join());
+    }finally{
+      
+    }   
+  }
+  
+  @Test
+  public void testCoordinatorFindRequestFailure()  throws Exception {
+    try{
+      initMocks(false);
+      HashSet<InternalDistributedMember> registrants = new HashSet<>();
+      registrants.add(mockMembers[0]);
+      FindCoordinatorResponse fcr = new FindCoordinatorResponse(mockMembers[0], mockMembers[0],
false, null, registrants, false, true);
+      NetView view = createView();
+      JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view);
+      gmsJoinLeave.setJoinResponseMessage(jrm);
+      
+      TcpClientWrapper tcpClientWrapper = mock(TcpClientWrapper.class);
+      gmsJoinLeave.setTcpClientWrapper(tcpClientWrapper);
+      FindCoordinatorRequest fcreq = new FindCoordinatorRequest(gmsJoinLeaveMemberId, new
HashSet<>(), -1);
+      int connectTimeout = (int)services.getConfig().getMemberTimeout() * 2;
+      //passing wrong port here, so ot will fail
+      when(tcpClientWrapper.sendCoordinatorFindRequest(new InetSocketAddress("localhost",
12346), fcreq, connectTimeout)).thenReturn(fcr);
+      assertFalse("Should not be able to join ", gmsJoinLeave.join());
+    }finally{
+      
+    }   
+  }
 }
 


Mime
View raw message