You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by eo...@apache.org on 2021/05/26 18:28:26 UTC

[curator] branch master updated: CURATOR-594: TestingZooKeeperMain isn't setting tickTime, if configured (#383)

This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git


The following commit(s) were added to refs/heads/master by this push:
     new c26dd85  CURATOR-594: TestingZooKeeperMain isn't setting tickTime, if configured (#383)
c26dd85 is described below

commit c26dd85fc3be8ac591c9d7daf69eedb4d7b45dbb
Author: Francesco Nigro <ni...@gmail.com>
AuthorDate: Wed May 26 20:28:08 2021 +0200

    CURATOR-594: TestingZooKeeperMain isn't setting tickTime, if configured (#383)
---
 .../org/apache/curator/test/TestingServer.java     |  4 ++
 .../apache/curator/test/TestingZooKeeperMain.java  |  6 +++
 .../curator/test/TestingZooKeeperServer.java       |  4 ++
 .../org/apache/curator/test/TestTestingServer.java | 53 ++++++++++++++++++++++
 4 files changed, 67 insertions(+)

diff --git a/curator-test/src/main/java/org/apache/curator/test/TestingServer.java b/curator-test/src/main/java/org/apache/curator/test/TestingServer.java
index 5228c8e..9d24243 100644
--- a/curator-test/src/main/java/org/apache/curator/test/TestingServer.java
+++ b/curator-test/src/main/java/org/apache/curator/test/TestingServer.java
@@ -31,6 +31,10 @@ public class TestingServer implements Closeable
     private final TestingZooKeeperServer testingZooKeeperServer;
     private final InstanceSpec spec;
 
+    TestingZooKeeperServer getTestingZooKeeperServer() {
+        return testingZooKeeperServer;
+    }
+
     /**
      * Create the server using a random port
      *
diff --git a/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java b/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
index cdf59d0..b1a873a 100644
--- a/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
+++ b/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
@@ -97,6 +97,10 @@ public class TestingZooKeeperMain implements ZooKeeperMainFace
         }
     }
 
+    TestZooKeeperServer getZkServer() {
+        return zkServer;
+    }
+
     @Override
     public void runFromConfig(QuorumPeerConfig config) throws Exception
     {
@@ -271,6 +275,8 @@ public class TestingZooKeeperMain implements ZooKeeperMainFace
         {
             this.txnLog = txnLog;
             this.setTxnLogFactory(txnLog);
+            // tickTime would affect min and max session timeout: should be set first
+            this.setTickTime(config.getTickTime());
             this.setMinSessionTimeout(config.getMinSessionTimeout());
             this.setMaxSessionTimeout(config.getMaxSessionTimeout());
         }
diff --git a/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperServer.java b/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperServer.java
index 58cf8d4..e80566a 100644
--- a/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperServer.java
+++ b/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperServer.java
@@ -40,6 +40,10 @@ public class TestingZooKeeperServer implements Closeable
     private volatile ZooKeeperMainFace main;
     private final AtomicReference<State> state = new AtomicReference<State>(State.LATENT);
 
+    ZooKeeperMainFace getMain() {
+        return main;
+    }
+
     private enum State
     {
         LATENT, STARTED, STOPPED, CLOSED
diff --git a/curator-test/src/test/java/org/apache/curator/test/TestTestingServer.java b/curator-test/src/test/java/org/apache/curator/test/TestTestingServer.java
new file mode 100644
index 0000000..1ddf960
--- /dev/null
+++ b/curator-test/src/test/java/org/apache/curator/test/TestTestingServer.java
@@ -0,0 +1,53 @@
+/**
+ * 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.curator.test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.File;
+
+import org.apache.zookeeper.server.ZooKeeperServer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+public class TestTestingServer {
+
+   @TempDir
+   File zkTmpDir;
+
+   @Test
+   public void setCustomTickTimeTest() throws Exception {
+      final int defaultZkTickTime = ZooKeeperServer.DEFAULT_TICK_TIME;
+      final int customTickMs;
+      if (defaultZkTickTime > 0) {
+         customTickMs = defaultZkTickTime + (defaultZkTickTime == Integer.MAX_VALUE ? -1 : +1);
+      } else {
+         customTickMs = 100;
+      }
+      final InstanceSpec spec = new InstanceSpec(zkTmpDir, -1, -1, -1, true, -1, customTickMs, -1);
+      final int zkTickTime;
+      try (TestingServer testingServer = new TestingServer(spec, true)) {
+         TestingZooKeeperMain main = (TestingZooKeeperMain) testingServer.getTestingZooKeeperServer().getMain();
+         zkTickTime = main.getZkServer().getTickTime();
+      }
+      assertEquals(customTickMs, zkTickTime);
+   }
+}