Skip to content
Permalink
Browse files
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()
  • Loading branch information
randgalt committed Feb 18, 2020
1 parent 7670ae3 commit 9c54babcf93d783eb301f11b2a14d78c3034c671
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
@@ -89,6 +89,7 @@ public static int getRandomPort()
try
{
server = new ServerSocket(0);
server.setReuseAddress(true);
return server.getLocalPort();
}
catch ( IOException e )
@@ -22,6 +22,7 @@
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 QuorumPeerConfig buildConfig(int instanceIndex) throws Exception
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 )
{
@@ -143,7 +143,9 @@ public void unregister(ZKMBeanInfo bean)
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 )
{
@@ -36,6 +36,7 @@
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 int connection()
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);

0 comments on commit 9c54bab

Please sign in to comment.