zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject zookeeper git commit: ZOOKEEPER-2470: ServerConfig#parse(String[]) ignores tickTime
Date Thu, 22 Dec 2016 03:11:24 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/master eac693cc7 -> ef0a8ae68


ZOOKEEPER-2470: ServerConfig#parse(String[]) ignores tickTime

Author: Edward Ribeiro <edward.ribeiro@gmail.com>

Reviewers: Michael Han <hanm@apache.org>, Rakesh Radhakrishnan <rakeshr@apache.org>

Closes #125 from eribeiro/ZOOKEEPER-2470

(cherry picked from commit 5de4fa3d8acdfdac353bb54fcaa8c8e732432891)
Signed-off-by: Michael Han <hanm@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/ef0a8ae6
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/ef0a8ae6
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/ef0a8ae6

Branch: refs/heads/master
Commit: ef0a8ae686c100f1dc71d7526af962c635696466
Parents: eac693c
Author: Edward Ribeiro <edward.ribeiro@gmail.com>
Authored: Wed Dec 21 19:10:14 2016 -0800
Committer: Michael Han <hanm@apache.org>
Committed: Wed Dec 21 19:11:20 2016 -0800

----------------------------------------------------------------------
 .../apache/zookeeper/server/ServerConfig.java   |  7 +--
 .../org/apache/zookeeper/ServerConfigTest.java  | 58 ++++++++++++++++++++
 2 files changed, 61 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/ef0a8ae6/src/java/main/org/apache/zookeeper/server/ServerConfig.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/ServerConfig.java b/src/java/main/org/apache/zookeeper/server/ServerConfig.java
index d4c32a1..444e126 100644
--- a/src/java/main/org/apache/zookeeper/server/ServerConfig.java
+++ b/src/java/main/org/apache/zookeeper/server/ServerConfig.java
@@ -49,20 +49,19 @@ public class ServerConfig {
 
     /**
      * Parse arguments for server configuration
-     * @param args clientPort dataDir and optional tickTime
+     * @param args clientPort dataDir and optional tickTime and maxClientCnxns
      * @return ServerConfig configured wrt arguments
      * @throws IllegalArgumentException on invalid usage
      */
     public void parse(String[] args) {
         if (args.length < 2 || args.length > 4) {
-            throw new IllegalArgumentException("Invalid args:"
-                    + Arrays.toString(args));
+            throw new IllegalArgumentException("Invalid number of arguments:" + Arrays.toString(args));
         }
 
         clientPortAddress = new InetSocketAddress(Integer.parseInt(args[0]));
         dataDir = new File(args[1]);
         dataLogDir = dataDir;
-        if (args.length == 3) {
+        if (args.length >= 3) {
             tickTime = Integer.parseInt(args[2]);
         }
         if (args.length == 4) {

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/ef0a8ae6/src/java/test/org/apache/zookeeper/ServerConfigTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/ServerConfigTest.java b/src/java/test/org/apache/zookeeper/ServerConfigTest.java
new file mode 100644
index 0000000..d4855fd
--- /dev/null
+++ b/src/java/test/org/apache/zookeeper/ServerConfigTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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;
+
+import org.apache.zookeeper.server.ServerConfig;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ServerConfigTest {
+
+    private ServerConfig serverConfig;
+
+    @Before
+    public void setUp() {
+        serverConfig = new ServerConfig();
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testFewArguments() {
+        String[] args = {"2181"};
+        serverConfig.parse(args);
+    }
+
+    @Test
+    public void testValidArguments() {
+        String[] args = {"2181", "/data/dir", "60000", "10000"};
+        serverConfig.parse(args);
+
+        assertEquals(2181, serverConfig.getClientPortAddress().getPort());
+        assertEquals("/data/dir", serverConfig.getDataDir());
+        assertEquals(60000, serverConfig.getTickTime());
+        assertEquals(10000, serverConfig.getMaxClientCnxns());
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testTooManyArguments() {
+        String[] args = {"2181", "/data/dir", "60000", "10000", "9999"};
+        serverConfig.parse(args);
+    }
+}


Mime
View raw message