Search in sources :

Example 1 with SocketCloser

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));
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InetSocketAddress(java.net.InetSocketAddress) InputStream(java.io.InputStream) CancelCriterion(org.apache.geode.CancelCriterion) DM(org.apache.geode.distributed.internal.DM) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) SocketCloser(org.apache.geode.internal.net.SocketCloser) Socket(java.net.Socket) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Aggregations

InputStream (java.io.InputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 CancelCriterion (org.apache.geode.CancelCriterion)1 DM (org.apache.geode.distributed.internal.DM)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 MembershipManager (org.apache.geode.distributed.internal.membership.MembershipManager)1 SocketCloser (org.apache.geode.internal.net.SocketCloser)1 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1 Test (org.junit.Test)1