use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class GMSJoinLeaveJUnitTest method testCoordinatorFindRequestFailure.
@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, null);
NetView view = createView();
JoinResponseMessage jrm = new JoinResponseMessage(mockMembers[0], view, 0);
gmsJoinLeave.setJoinResponseMessage(jrm);
TcpClientWrapper tcpClientWrapper = mock(TcpClientWrapper.class);
gmsJoinLeave.setTcpClientWrapper(tcpClientWrapper);
FindCoordinatorRequest fcreq = new FindCoordinatorRequest(gmsJoinLeaveMemberId, new HashSet<>(), -1, null, 0, "");
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 {
}
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class GMSHealthMonitorJUnitTest method testHMServiceStarted.
@Test
public void testHMServiceStarted() throws IOException {
InternalDistributedMember mbr = new InternalDistributedMember(SocketCreator.getLocalHost(), 12345);
mbr.setVmViewId(1);
when(messenger.getMemberID()).thenReturn(mbr);
gmsHealthMonitor.started();
NetView v = new NetView(mbr, 1, mockMembers);
gmsHealthMonitor.processMessage(new HeartbeatRequestMessage(mbr, 1));
verify(messenger, atLeastOnce()).send(any(HeartbeatMessage.class));
Assert.assertEquals(1, gmsHealthMonitor.getStats().getHeartbeatRequestsReceived());
Assert.assertEquals(1, gmsHealthMonitor.getStats().getHeartbeatsSent());
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class GMSJoinLeaveJUnitTest method testQuorumLossNotificationWithNetworkPartitionDetectionDisabled.
@Test
public void testQuorumLossNotificationWithNetworkPartitionDetectionDisabled() throws IOException {
initMocks(false);
prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
// set up a view with sufficient members, then create a new view
// where enough weight is lost to cause a network partition
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);
((GMSMember) mockMembers[1].getNetMember()).setMemberWeight((byte) 20);
NetView newView = new NetView(mockMembers[0], gmsJoinLeave.getView().getViewId() + 1, mbrs, shutdowns, crashes);
InstallViewMessage installViewMessage = getInstallViewMessage(newView, credentials, false);
gmsJoinLeave.processMessage(installViewMessage);
crashes = new HashSet<>(crashes);
crashes.add(mockMembers[1]);
crashes.add(mockMembers[2]);
mbrs = new LinkedList<>(mbrs);
mbrs.remove(mockMembers[1]);
mbrs.remove(mockMembers[2]);
NetView partitionView = new NetView(mockMembers[0], newView.getViewId() + 1, mbrs, shutdowns, crashes);
installViewMessage = getInstallViewMessage(partitionView, credentials, false);
gmsJoinLeave.processMessage(installViewMessage);
verify(manager, never()).forceDisconnect(isA(String.class));
verify(manager).quorumLost(crashes, newView);
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class GMSHealthMonitorJUnitTest method executeTestClientSocketHandler.
public void executeTestClientSocketHandler(GMSMember gmsMember, GMSMember otherMember, int expectedResult) throws Exception {
// We have already set the view id in the member but when creating the IDM it resets it to -1
// for some reason
int viewId = gmsMember.getVmViewId();
InternalDistributedMember testMember = new InternalDistributedMember("localhost", 9000, Version.CURRENT, gmsMember);
// We set to our expected test viewId in the IDM as well as reseting the gms member
testMember.setVmViewId(viewId);
gmsMember.setBirthViewId(viewId);
// Set up the incoming/received bytes. We just wrap output streams and write out the gms member
// information
byte[] receivedBytes = writeMemberToBytes(otherMember);
InputStream mockInputStream = new ByteArrayInputStream(receivedBytes);
// configure the mock to return the mocked incoming bytes and provide an outputstream that we
// will check
Socket fakeSocket = mock(Socket.class);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
when(fakeSocket.getInputStream()).thenReturn(mockInputStream);
when(fakeSocket.getOutputStream()).thenReturn(outputStream);
// run the socket handler
gmsHealthMonitor.setLocalAddress(testMember);
ClientSocketHandler handler = gmsHealthMonitor.new ClientSocketHandler(fakeSocket);
handler.run();
// verify the written bytes are as expected
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(outputStream.toByteArray()));
int byteReply = dis.read();
Assert.assertEquals(expectedResult, byteReply);
Assert.assertTrue(gmsHealthMonitor.getStats().getFinalCheckResponsesSent() > 0);
Assert.assertTrue(gmsHealthMonitor.getStats().getTcpFinalCheckResponsesSent() > 0);
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class GMSHealthMonitorJUnitTest method testCheckIfAvailableWithSimulatedHeartBeatWithTcpCheck.
@Test
public void testCheckIfAvailableWithSimulatedHeartBeatWithTcpCheck() {
System.out.println("testCheckIfAvailableWithSimulatedHeartBeatWithTcpCheck");
useGMSHealthMonitorTestClass = true;
try {
NetView v = installAView();
setFailureDetectionPorts(v);
InternalDistributedMember memberToCheck = mockMembers.get(1);
boolean retVal = gmsHealthMonitor.checkIfAvailable(memberToCheck, "Not responding", true);
assertTrue("CheckIfAvailable should have return true", retVal);
} finally {
useGMSHealthMonitorTestClass = false;
}
}
Aggregations