You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by rg...@apache.org on 2015/12/07 06:06:45 UTC
svn commit: r1718253 - in /zookeeper/trunk: CHANGES.txt
src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java
src/java/test/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java
Author: rgs
Date: Mon Dec 7 05:06:45 2015
New Revision: 1718253
URL: http://svn.apache.org/viewvc?rev=1718253&view=rev
Log:
ZOOKEEPER-2299: NullPointerException in LocalPeerBean for ClientAddress
(Arshad Mohammad via rgs)
Added:
zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java
Modified:
zookeeper/trunk/CHANGES.txt
zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java
Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1718253&r1=1718252&r2=1718253&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Mon Dec 7 05:06:45 2015
@@ -232,6 +232,9 @@ BUGFIXES:
ZOOKEEPER-2301: QuorumPeer does not listen on passed client IP in the constructor
(Arshad Mohammad via rgs)
+ ZOOKEEPER-2299: NullPointerException in LocalPeerBean for ClientAddress
+ (Arshad Mohammad via rgs)
+
IMPROVEMENTS:
ZOOKEEPER-1660 Documentation for Dynamic Reconfiguration (Reed Wanderman-Milne via shralex)
Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java?rev=1718253&r1=1718252&r2=1718253&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LocalPeerBean.java Mon Dec 7 05:06:45 2015
@@ -19,6 +19,7 @@
package org.apache.zookeeper.server.quorum;
+
/**
* Implementation of the local peer MBean interface.
*/
@@ -83,8 +84,12 @@ public class LocalPeerBean extends Serve
}
public String getClientAddress() {
- return peer.getClientAddress().getHostString() + ":" +
- peer.getClientAddress().getPort();
+ if (null != peer.cnxnFactory) {
+ return String.format("%s:%d", peer.cnxnFactory.getLocalAddress()
+ .getHostString(), peer.getClientPort());
+ } else {
+ return "";
+ }
}
public String getLearnerType(){
Added: zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java?rev=1718253&view=auto
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java (added)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java Mon Dec 7 05:06:45 2015
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.server.quorum;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.junit.Test;
+
+public class LocalPeerBeanTest {
+
+ /**
+ * Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2299
+ */
+ @Test
+ public void testClientAddress() throws Exception {
+ QuorumPeer quorumPeer = new QuorumPeer();
+ LocalPeerBean remotePeerBean = new LocalPeerBean(quorumPeer);
+
+ /**
+ * Case 1: When cnxnFactory is null
+ */
+ String result = remotePeerBean.getClientAddress();
+ assertNotNull(result);
+ assertEquals(0, result.length());
+
+ /**
+ * Case 2: When only client port is configured
+ */
+ ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
+ int clientPort = 2181;
+ 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));
+ // cleanup
+ cnxnFactory.shutdown();
+
+ /**
+ * Case 3: When both client port and client address is configured
+ */
+ InetAddress clientIP = InetAddress.getByAddress(new byte[] { 127, 0, 0,
+ 2 });
+ address = new InetSocketAddress(clientIP, clientPort);
+ cnxnFactory = ServerCnxnFactory.createFactory();
+ cnxnFactory.configure(address, 5, false);
+ quorumPeer.setCnxnFactory(cnxnFactory);
+
+ result = remotePeerBean.getClientAddress();
+ String expectedResult = "127.0.0.2:" + clientPort;
+ assertEquals(expectedResult, result);
+ // cleanup
+ cnxnFactory.shutdown();
+ }
+
+}