@Test
public void testQuorumPeerListendOnSpecifiedClientIP() throws IOException {

    long myId = 1;
    File dataDir = ClientBase.createTmpDir();
    int clientPort = PortAssignment.unique();
    Map<Long, QuorumServer> peersView = new HashMap<Long, QuorumServer>();
    InetAddress clientIP = InetAddress.getLoopbackAddress();
    peersView.put(Long.valueOf(myId),
            new QuorumServer(myId, new InetSocketAddress(clientIP, PortAssignment.unique()),
                    new InetSocketAddress(clientIP, PortAssignment.unique()),
                    new InetSocketAddress(clientIP, clientPort), LearnerType.PARTICIPANT));
    /**
     * QuorumPeer constructor without QuorumVerifier
     */
    QuorumPeer peer1 = new QuorumPeer(peersView, dataDir, dataDir, clientPort, electionAlg, myId, tickTime,
            initLimit, syncLimit);
    String hostString1 = peer1.cnxnFactory.getLocalAddress().getHostString();
    assertEquals(clientIP.getHostAddress(), hostString1);
    // cleanup
    peer1.shutdown();
    /**
     * QuorumPeer constructor with QuorumVerifier
     */
    peersView.clear();
    clientPort = PortAssignment.unique();
    peersView.put(Long.valueOf(myId),
            new QuorumServer(myId, new InetSocketAddress(clientIP, PortAssignment.unique()),
                    new InetSocketAddress(clientIP, PortAssignment.unique()),
                    new InetSocketAddress(clientIP, clientPort), LearnerType.PARTICIPANT));
    QuorumPeer peer2 = new QuorumPeer(peersView, dataDir, dataDir, clientPort, electionAlg, myId, tickTime,
            initLimit, syncLimit);
    String hostString2 = peer2.cnxnFactory.getLocalAddress().getHostString();
    assertEquals(clientIP.getHostAddress(), hostString2);
    // cleanup
    peer2.shutdown();
}