@Test public void testClientAddress() throws Exception { QuorumPeer quorumPeer = new QuorumPeer(); LocalPeerBean remotePeerBean = new LocalPeerBean(quorumPeer); String result = remotePeerBean.getClientAddress(); assertNotNull(result); assertEquals(0, result.length()); ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); int clientPort = PortAssignment.unique(); InetSocketAddress address = new InetSocketAddress(clientPort); cnxnFactory.configure(address, 5, false); quorumPeer.setCnxnFactory(cnxnFactory); result = remotePeerBean.getClientAddress(); String ipv4 = "0.0.0.0:" + clientPort; String ipv6 = "0:0:0:0:0:0:0:0:" + clientPort; assertTrue(result.equals(ipv4) || result.equals(ipv6)); cnxnFactory.shutdown(); clientPort = PortAssignment.unique(); InetAddress clientIP = InetAddress.getLoopbackAddress(); address = new InetSocketAddress(clientIP, clientPort); cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(address, 5, false); quorumPeer.setCnxnFactory(cnxnFactory); result = remotePeerBean.getClientAddress(); String expectedResult = clientIP.getHostAddress() + ":" + clientPort; assertEquals(expectedResult, result); cnxnFactory.shutdown(); }
public String getClientAddress() { if (null != peer.cnxnFactory) { return String.format("%s:%d", peer.cnxnFactory.getLocalAddress() .getHostString(), peer.getClientPort()); } else { return ""; } }
LocalPeerBean extends ServerBean implements LocalPeerMXBean { public String getClientAddress() { if (null != peer.cnxnFactory) { return String.format("%s:%d", peer.cnxnFactory.getLocalAddress() .getHostString(), peer.getClientPort()); } else { return ""; } } }
LocalPeerBean extends ServerBean implements LocalPeerMXBean { public String getClientAddress() { if (null != peer.cnxnFactory) { return String.format("%s:%d", peer.cnxnFactory.getLocalAddress() .getHostString(), peer.getClientPort()); } else { return ""; } } LocalPeerBean(QuorumPeer peer); }
LocalPeerBean extends ServerBean implements LocalPeerMXBean { public String getClientAddress() { if (null != peer.cnxnFactory) { return String.format("%s:%d", peer.cnxnFactory.getLocalAddress() .getHostString(), peer.getClientPort()); } else { return ""; } } LocalPeerBean(QuorumPeer peer); String getName(); boolean isHidden(); int getTickTime(); int getMaxClientCnxnsPerHost(); int getMinSessionTimeout(); int getMaxSessionTimeout(); int getInitLimit(); int getSyncLimit(); int getTick(); String getState(); String getQuorumAddress(); int getElectionType(); String getElectionAddress(); String getClientAddress(); String getLearnerType(); long getConfigVersion(); @Override String getQuorumSystemInfo(); @Override boolean isPartOfEnsemble(); @Override boolean isLeader(); }
LocalPeerBean extends ServerBean implements LocalPeerMXBean { public String getClientAddress() { if (null != peer.cnxnFactory) { return String.format("%s:%d", peer.cnxnFactory.getLocalAddress() .getHostString(), peer.getClientPort()); } else { return ""; } } LocalPeerBean(QuorumPeer peer); String getName(); boolean isHidden(); int getTickTime(); int getMaxClientCnxnsPerHost(); int getMinSessionTimeout(); int getMaxSessionTimeout(); int getInitLimit(); int getSyncLimit(); int getTick(); String getState(); String getQuorumAddress(); int getElectionType(); String getElectionAddress(); String getClientAddress(); String getLearnerType(); long getConfigVersion(); @Override String getQuorumSystemInfo(); @Override boolean isPartOfEnsemble(); @Override boolean isLeader();  }