use of org.apache.geode.distributed.internal.membership.gms.fd.GMSHealthMonitor.ClientSocketHandler 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);
}
Aggregations