This is an automated email from the ASF dual-hosted git repository. randgalt pushed a commit to branch CURATOR-560-set-tick-time in repository https://gitbox.apache.org/repos/asf/curator.git
commit 9c54babcf93d783eb301f11b2a14d78c3034c671 Author: randgalt <[email protected]> AuthorDate: Tue Feb 18 13:59:52 2020 -0500 CURATOR-560 a) make sure setReuseAddress is set for server when getting a random port b) always set "tickTime" and "minSessionTimeout" to make our tests run a bit faster c) fixed incorrect exception message in blockUntilStarted() --- .../src/main/java/org/apache/curator/test/InstanceSpec.java | 1 + .../java/org/apache/curator/test/QuorumConfigBuilder.java | 11 +++++------ .../java/org/apache/curator/test/TestingZooKeeperMain.java | 4 +++- .../java/org/apache/curator/test/compatibility/Timing2.java | 11 +++++++++++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java b/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java index d04e09f..8948f4d 100644 --- a/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java +++ b/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java @@ -89,6 +89,7 @@ public class InstanceSpec try { server = new ServerSocket(0); + server.setReuseAddress(true); return server.getLocalPort(); } catch ( IOException e ) diff --git a/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java b/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java index d385103..fbfe864 100644 --- a/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java +++ b/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java @@ -22,6 +22,7 @@ package org.apache.curator.test; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.io.Files; +import org.apache.curator.test.compatibility.Timing2; import org.apache.zookeeper.server.quorum.QuorumPeerConfig; import java.io.Closeable; import java.io.File; @@ -40,7 +41,7 @@ public class QuorumConfigBuilder implements Closeable public QuorumConfigBuilder(Collection<InstanceSpec> specs) { - this(specs.toArray(new InstanceSpec[specs.size()])); + this(specs.toArray(new InstanceSpec[0])); } public QuorumConfigBuilder(InstanceSpec... specs) @@ -109,11 +110,9 @@ public class QuorumConfigBuilder implements Closeable properties.setProperty("syncLimit", "5"); properties.setProperty("dataDir", spec.getDataDirectory().getCanonicalPath()); properties.setProperty("clientPort", Integer.toString(spec.getPort())); - int tickTime = spec.getTickTime(); - if ( tickTime >= 0 ) - { - properties.setProperty("tickTime", Integer.toString(tickTime)); - } + String tickTime = Integer.toString((spec.getTickTime() >= 0) ? spec.getTickTime() : new Timing2().tickTime()); + properties.setProperty("tickTime", tickTime); + properties.setProperty("minSessionTimeout", tickTime); int maxClientCnxns = spec.getMaxClientCnxns(); if ( maxClientCnxns >= 0 ) { 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 841df77..574b4f5 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 @@ -143,7 +143,9 @@ public class TestingZooKeeperMain implements ZooKeeperMainFace public void blockUntilStarted() throws Exception { if(!timing.awaitLatch(latch)) - throw new IllegalStateException("Timed out waiting for watch removal"); + { + throw new IllegalStateException("Timed out waiting for server startup"); + } if ( zkServer != null ) { diff --git a/curator-test/src/main/java/org/apache/curator/test/compatibility/Timing2.java b/curator-test/src/main/java/org/apache/curator/test/compatibility/Timing2.java index ad105eb..f9ee75b 100644 --- a/curator-test/src/main/java/org/apache/curator/test/compatibility/Timing2.java +++ b/curator-test/src/main/java/org/apache/curator/test/compatibility/Timing2.java @@ -36,6 +36,7 @@ public class Timing2 private final TimeUnit unit; private final int waitingMultiple; + private static final double TICK_TIME_MULTIPLE = .10; private static final int DEFAULT_SECONDS = 10; private static final int DEFAULT_WAITING_MULTIPLE = 5; private static final double SESSION_MULTIPLE = 1.5; @@ -292,6 +293,16 @@ public class Timing2 return milliseconds(); } + /** + * Value to use for server "tickTime" + * + * @return tick time + */ + public int tickTime() + { + return (int)Math.max(1, milliseconds() * TICK_TIME_MULTIPLE); + } + private static Integer getWaitingMultiple() { return Integer.getInteger("timing-waiting-multiple", DEFAULT_WAITING_MULTIPLE);
