فهرست منبع

ZOOKEEPER-1725. Zookeeper Dynamic Conf writes out hostnames when IPs are supplied (Alexander Shraer via michim)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1583495 13f79535-47bb-0310-9956-ffa450edef68
Michi Mutsuzaki 11 سال پیش
والد
کامیت
256f95f52c

+ 3 - 0
CHANGES.txt

@@ -590,6 +590,9 @@ BUGFIXES:
   ZOOKEEPER-1904. WatcherTest#testWatchAutoResetWithPending is failing
   (Rakesh R via michim)
 
+  ZOOKEEPER-1725. Zookeeper Dynamic Conf writes out hostnames when IPs are
+  supplied (Alexander Shraer via michim)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

+ 1 - 1
src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java

@@ -222,7 +222,7 @@ public class QuorumPeer extends ZooKeeperThread implements QuorumStats.Provider
             StringWriter sw = new StringWriter();            
             //addr should never be null, but just to make sure
             if (addr !=null) { 
-                sw.append(addr.getHostName());
+                sw.append(HostNameUtils.getHostString(addr));
                 sw.append(":");
                 sw.append(String.valueOf(addr.getPort()));
             }

+ 60 - 0
src/java/test/org/apache/zookeeper/server/quorum/QuorumServerTest.java

@@ -0,0 +1,60 @@
+/*
+ * 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 org.apache.zookeeper.ZKTestCase;
+import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class QuorumServerTest extends ZKTestCase {
+    @Test
+    public void testToString() throws ConfigException {
+        String config = "127.0.0.1:1234:1236:participant;0.0.0.0:1237";
+        String expected = "127.0.0.1:1234:1236:participant;0.0.0.0:1237";
+        QuorumServer qs = new QuorumServer(0, config);
+        Assert.assertEquals("Use IP address", expected, qs.toString());
+
+        config = "127.0.0.1:1234:1236;0.0.0.0:1237";
+        expected = "127.0.0.1:1234:1236:participant;0.0.0.0:1237";
+        qs = new QuorumServer(0, config);
+        Assert.assertEquals("Type unspecified", expected, qs.toString());
+
+        config = "127.0.0.1:1234:1236:observer;0.0.0.0:1237";
+        expected = "127.0.0.1:1234:1236:observer;0.0.0.0:1237";
+        qs = new QuorumServer(0, config);
+        Assert.assertEquals("Observer type", expected, qs.toString());
+
+        config = "127.0.0.1:1234:1236:participant;1237";
+        expected = "127.0.0.1:1234:1236:participant;0.0.0.0:1237";
+        qs = new QuorumServer(0, config);
+        Assert.assertEquals("Client address unspecified",
+                            expected, qs.toString());
+
+        config = "127.0.0.1:1234:1236:participant;1.2.3.4:1237";
+        expected = "127.0.0.1:1234:1236:participant;1.2.3.4:1237";
+        qs = new QuorumServer(0, config);
+        Assert.assertEquals("Client address specified",
+                            expected, qs.toString());
+
+        config = "example.com:1234:1236:participant;1237";
+        expected = "example.com:1234:1236:participant;0.0.0.0:1237";
+        qs = new QuorumServer(0, config);
+        Assert.assertEquals("Use hostname", expected, qs.toString());
+    }
+}