You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2013/09/04 06:15:43 UTC
git commit: ADD tickTime AND maxClientCnxns SUPPORT TO CURATOR TESTS
Updated Branches:
refs/heads/CURATOR-37 [created] f5b1fd589
ADD tickTime AND maxClientCnxns SUPPORT TO CURATOR TESTS
Project: http://git-wip-us.apache.org/repos/asf/incubator-curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-curator/commit/f5b1fd58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-curator/tree/f5b1fd58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-curator/diff/f5b1fd58
Branch: refs/heads/CURATOR-37
Commit: f5b1fd5894d69de7a5e1537b15e4168516352aff
Parents: 1e9ac36
Author: randgalt <ra...@apache.org>
Authored: Tue Sep 3 21:14:38 2013 -0700
Committer: randgalt <ra...@apache.org>
Committed: Tue Sep 3 21:14:38 2013 -0700
----------------------------------------------------------------------
.../org/apache/curator/test/InstanceSpec.java | 73 ++++++++++++++------
.../curator/test/QuorumConfigBuilder.java | 20 ++++--
2 files changed, 69 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/f5b1fd58/curator-test/src/main/java/org/apache/curator/test/InstanceSpec.java
----------------------------------------------------------------------
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 df564e3..b39a949 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
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.curator.test;
import com.google.common.io.Files;
@@ -31,8 +32,9 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public class InstanceSpec
{
- private static final AtomicInteger nextServerId = new AtomicInteger(1);
- private static final String localhost;
+ private static final AtomicInteger nextServerId = new AtomicInteger(1);
+ private static final String localhost;
+
static
{
String address = "localhost";
@@ -45,11 +47,11 @@ public class InstanceSpec
// we'll fall back to the default lof just looking up 'localhost'.
for ( InetAddress a : InetAddress.getAllByName("localhost") )
{
- if ( !a.isLinkLocalAddress() )
- {
- address = a.getHostAddress();
- break;
- }
+ if ( !a.isLinkLocalAddress() )
+ {
+ address = a.getHostAddress();
+ break;
+ }
}
}
catch ( UnknownHostException e )
@@ -59,16 +61,18 @@ public class InstanceSpec
localhost = address;
}
- private final File dataDirectory;
- private final int port;
- private final int electionPort;
- private final int quorumPort;
- private final boolean deleteDataDirectoryOnClose;
+ private final File dataDirectory;
+ private final int port;
+ private final int electionPort;
+ private final int quorumPort;
+ private final boolean deleteDataDirectoryOnClose;
private final int serverId;
+ private final int tickTime;
+ private final int maxClientCnxns;
- public static InstanceSpec newInstanceSpec()
+ public static InstanceSpec newInstanceSpec()
{
- return new InstanceSpec(null, -1, -1, -1, true, -1);
+ return new InstanceSpec(null, -1, -1, -1, true, -1, -1, -1);
}
public static int getRandomPort()
@@ -100,21 +104,38 @@ public class InstanceSpec
}
/**
- * @param dataDirectory where to store data/logs/etc.
- * @param port the port to listen on - each server in the ensemble must use a unique port
- * @param electionPort the electionPort to listen on - each server in the ensemble must use a unique electionPort
- * @param quorumPort the quorumPort to listen on - each server in the ensemble must use a unique quorumPort
+ * @param dataDirectory where to store data/logs/etc.
+ * @param port the port to listen on - each server in the ensemble must use a unique port
+ * @param electionPort the electionPort to listen on - each server in the ensemble must use a unique electionPort
+ * @param quorumPort the quorumPort to listen on - each server in the ensemble must use a unique quorumPort
* @param deleteDataDirectoryOnClose if true, the data directory will be deleted when {@link TestingCluster#close()} is called
- * @param serverId the server ID for the instance
+ * @param serverId the server ID for the instance
*/
public InstanceSpec(File dataDirectory, int port, int electionPort, int quorumPort, boolean deleteDataDirectoryOnClose, int serverId)
{
+ this(dataDirectory, port, electionPort, quorumPort, deleteDataDirectoryOnClose, serverId, -1, -1);
+ }
+
+ /**
+ * @param dataDirectory where to store data/logs/etc.
+ * @param port the port to listen on - each server in the ensemble must use a unique port
+ * @param electionPort the electionPort to listen on - each server in the ensemble must use a unique electionPort
+ * @param quorumPort the quorumPort to listen on - each server in the ensemble must use a unique quorumPort
+ * @param deleteDataDirectoryOnClose if true, the data directory will be deleted when {@link TestingCluster#close()} is called
+ * @param serverId the server ID for the instance
+ * @param tickTime tickTime. Set -1 to used fault server configuration
+ * @param maxClientCnxns max number of client connections from the same IP. Set -1 to use default server configuration
+ */
+ public InstanceSpec(File dataDirectory, int port, int electionPort, int quorumPort, boolean deleteDataDirectoryOnClose, int serverId, int tickTime, int maxClientCnxns)
+ {
this.dataDirectory = (dataDirectory != null) ? dataDirectory : Files.createTempDir();
this.port = (port >= 0) ? port : getRandomPort();
this.electionPort = (electionPort >= 0) ? electionPort : getRandomPort();
this.quorumPort = (quorumPort >= 0) ? quorumPort : getRandomPort();
this.deleteDataDirectoryOnClose = deleteDataDirectoryOnClose;
this.serverId = (serverId >= 0) ? serverId : nextServerId.getAndIncrement();
+ this.tickTime = (tickTime > 0 ? tickTime : -1); // -1 to set default value
+ this.maxClientCnxns = (maxClientCnxns >= 0 ? maxClientCnxns : -1); // -1 to set default value
}
public int getServerId()
@@ -147,6 +168,16 @@ public class InstanceSpec
return localhost + ":" + port;
}
+ public int getTickTime()
+ {
+ return tickTime;
+ }
+
+ public int getMaxClientCnxns()
+ {
+ return maxClientCnxns;
+ }
+
public boolean deleteDataDirectoryOnClose()
{
return deleteDataDirectoryOnClose;
@@ -162,7 +193,9 @@ public class InstanceSpec
", quorumPort=" + quorumPort +
", deleteDataDirectoryOnClose=" + deleteDataDirectoryOnClose +
", serverId=" + serverId +
- '}';
+ ", tickTime=" + tickTime +
+ ", maxClientCnxns=" + maxClientCnxns +
+ "} " + super.toString();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/f5b1fd58/curator-test/src/main/java/org/apache/curator/test/QuorumConfigBuilder.java
----------------------------------------------------------------------
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 fc1cc90..8add08e 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
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.curator.test;
import com.google.common.collect.ImmutableList;
@@ -53,7 +54,7 @@ public class QuorumConfigBuilder
return buildConfig(0);
}
- public InstanceSpec getInstanceSpec(int index)
+ public InstanceSpec getInstanceSpec(int index)
{
return instanceSpecs.get(index);
}
@@ -63,15 +64,15 @@ public class QuorumConfigBuilder
return instanceSpecs;
}
- public int size()
+ public int size()
{
return instanceSpecs.size();
}
public QuorumPeerConfig buildConfig(int instanceIndex) throws Exception
{
- boolean isCluster = (instanceSpecs.size() > 1);
- InstanceSpec spec = instanceSpecs.get(instanceIndex);
+ boolean isCluster = (instanceSpecs.size() > 1);
+ InstanceSpec spec = instanceSpecs.get(instanceIndex);
if ( isCluster )
{
@@ -83,6 +84,17 @@ public class QuorumConfigBuilder
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));
+ }
+ int maxClientCnxns = spec.getMaxClientCnxns();
+ if ( maxClientCnxns >= 0 )
+ {
+ properties.setProperty("maxClientCnxns", Integer.toString(maxClientCnxns));
+ }
+
if ( isCluster )
{
for ( InstanceSpec thisSpec : instanceSpecs )