use of org.apache.geode.internal.net.SocketCloser in project geode by apache.
the class ConnectionJUnitTest method testSuspicionRaised.
/**
* Test whether suspicion is raised about a member that closes its shared/unordered TCPConduit
* connection
*/
@Test
public void testSuspicionRaised() throws Exception {
// this test has to create a lot of mocks because Connection
// uses a lot of objects
// mock the socket
ConnectionTable table = mock(ConnectionTable.class);
DM distMgr = mock(DM.class);
MembershipManager membership = mock(MembershipManager.class);
TCPConduit conduit = mock(TCPConduit.class);
// mock the connection table and conduit
when(table.getConduit()).thenReturn(conduit);
CancelCriterion stopper = mock(CancelCriterion.class);
when(stopper.cancelInProgress()).thenReturn(null);
when(conduit.getCancelCriterion()).thenReturn(stopper);
when(conduit.getSocketId()).thenReturn(new InetSocketAddress(SocketCreator.getLocalHost(), 10337));
// NIO can't be mocked because SocketChannel has a final method that
// is used by Connection - configureBlocking
when(conduit.useNIO()).thenReturn(false);
// mock the distribution manager and membership manager
when(distMgr.getMembershipManager()).thenReturn(membership);
when(conduit.getDM()).thenReturn(distMgr);
when(table.getDM()).thenReturn(distMgr);
SocketCloser closer = mock(SocketCloser.class);
when(table.getSocketCloser()).thenReturn(closer);
InputStream instream = mock(InputStream.class);
when(instream.read()).thenReturn(-1);
Socket socket = mock(Socket.class);
when(socket.getInputStream()).thenReturn(instream);
Connection conn = new Connection(table, socket);
conn.setSharedUnorderedForTest();
conn.run();
verify(membership).suspectMember(any(InternalDistributedMember.class), any(String.class));
}
Aggregations