You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2013/05/13 18:01:43 UTC
svn commit: r1481948 - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/replicator/
lucene/replicator/src/test/org/apache/lucene/replicator/ReplicatorTestCase.java
Author: rmuir
Date: Mon May 13 16:01:43 2013
New Revision: 1481948
URL: http://svn.apache.org/r1481948
Log:
remove strange retry-port loop, and just bind to ephemeral port
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/replicator/ (props changed)
lucene/dev/branches/branch_4x/lucene/replicator/src/test/org/apache/lucene/replicator/ReplicatorTestCase.java
Modified: lucene/dev/branches/branch_4x/lucene/replicator/src/test/org/apache/lucene/replicator/ReplicatorTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/replicator/src/test/org/apache/lucene/replicator/ReplicatorTestCase.java?rev=1481948&r1=1481947&r2=1481948&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/replicator/src/test/org/apache/lucene/replicator/ReplicatorTestCase.java (original)
+++ lucene/dev/branches/branch_4x/lucene/replicator/src/test/org/apache/lucene/replicator/ReplicatorTestCase.java Mon May 13 16:01:43 2013
@@ -39,12 +39,6 @@ import org.junit.AfterClass;
@SuppressCodecs("Lucene3x")
public abstract class ReplicatorTestCase extends LuceneTestCase {
- private static final int BASE_PORT = 7000;
-
- // if a test calls newServer() multiple times, or some ports already failed,
- // don't start from BASE_PORT again
- private static int lastPortUsed = -1;
-
private static ClientConnectionManager clientConnectionManager;
@AfterClass
@@ -60,88 +54,75 @@ public abstract class ReplicatorTestCase
* {@link #serverPort(Server)}.
*/
public static synchronized Server newHttpServer(Handler handler) throws Exception {
- int port = lastPortUsed == -1 ? BASE_PORT : lastPortUsed + 1;
- Server server = null;
- while (true) {
- try {
- server = new Server(port);
-
- server.setHandler(handler);
-
- final String connectorName = System.getProperty("tests.jettyConnector", "SelectChannel");
-
- // if this property is true, then jetty will be configured to use SSL
- // leveraging the same system properties as java to specify
- // the keystore/truststore if they are set
- //
- // This means we will use the same truststore, keystore (and keys) for
- // the server as well as any client actions taken by this JVM in
- // talking to that server, but for the purposes of testing that should
- // be good enough
- final boolean useSsl = Boolean.getBoolean("tests.jettySsl");
- final SslContextFactory sslcontext = new SslContextFactory(false);
-
- if (useSsl) {
- if (null != System.getProperty("javax.net.ssl.keyStore")) {
- sslcontext.setKeyStorePath
- (System.getProperty("javax.net.ssl.keyStore"));
- }
- if (null != System.getProperty("javax.net.ssl.keyStorePassword")) {
- sslcontext.setKeyStorePassword
- (System.getProperty("javax.net.ssl.keyStorePassword"));
- }
- if (null != System.getProperty("javax.net.ssl.trustStore")) {
- sslcontext.setTrustStore
- (System.getProperty("javax.net.ssl.trustStore"));
- }
- if (null != System.getProperty("javax.net.ssl.trustStorePassword")) {
- sslcontext.setTrustStorePassword
- (System.getProperty("javax.net.ssl.trustStorePassword"));
- }
- sslcontext.setNeedClientAuth(Boolean.getBoolean("tests.jettySsl.clientAuth"));
- }
-
- final Connector connector;
- final QueuedThreadPool threadPool;
- if ("SelectChannel".equals(connectorName)) {
- final SelectChannelConnector c = useSsl ? new SslSelectChannelConnector(sslcontext) : new SelectChannelConnector();
- c.setReuseAddress(true);
- c.setLowResourcesMaxIdleTime(1500);
- connector = c;
- threadPool = (QueuedThreadPool) c.getThreadPool();
- } else if ("Socket".equals(connectorName)) {
- final SocketConnector c = useSsl ? new SslSocketConnector(sslcontext) : new SocketConnector();
- c.setReuseAddress(true);
- connector = c;
- threadPool = (QueuedThreadPool) c.getThreadPool();
- } else {
- throw new IllegalArgumentException("Illegal value for system property 'tests.jettyConnector': " + connectorName);
- }
-
- connector.setPort(port);
- connector.setHost("127.0.0.1");
- if (threadPool != null) {
- threadPool.setDaemon(true);
- threadPool.setMaxThreads(10000);
- threadPool.setMaxIdleTimeMs(5000);
- threadPool.setMaxStopTimeMs(30000);
- }
-
- server.setConnectors(new Connector[] {connector});
- server.setSessionIdManager(new HashSessionIdManager(new Random()));
-
- // this will test the port
- server.start();
-
- // if here, port is available
- lastPortUsed = port;
- return server;
- } catch (SocketException e) {
- stopHttpServer(server);
- // this is ok, we'll try the next port until successful.
- ++port;
+ Server server = new Server(0);
+
+ server.setHandler(handler);
+
+ final String connectorName = System.getProperty("tests.jettyConnector", "SelectChannel");
+
+ // if this property is true, then jetty will be configured to use SSL
+ // leveraging the same system properties as java to specify
+ // the keystore/truststore if they are set
+ //
+ // This means we will use the same truststore, keystore (and keys) for
+ // the server as well as any client actions taken by this JVM in
+ // talking to that server, but for the purposes of testing that should
+ // be good enough
+ final boolean useSsl = Boolean.getBoolean("tests.jettySsl");
+ final SslContextFactory sslcontext = new SslContextFactory(false);
+
+ if (useSsl) {
+ if (null != System.getProperty("javax.net.ssl.keyStore")) {
+ sslcontext.setKeyStorePath
+ (System.getProperty("javax.net.ssl.keyStore"));
+ }
+ if (null != System.getProperty("javax.net.ssl.keyStorePassword")) {
+ sslcontext.setKeyStorePassword
+ (System.getProperty("javax.net.ssl.keyStorePassword"));
+ }
+ if (null != System.getProperty("javax.net.ssl.trustStore")) {
+ sslcontext.setTrustStore
+ (System.getProperty("javax.net.ssl.trustStore"));
}
+ if (null != System.getProperty("javax.net.ssl.trustStorePassword")) {
+ sslcontext.setTrustStorePassword
+ (System.getProperty("javax.net.ssl.trustStorePassword"));
+ }
+ sslcontext.setNeedClientAuth(Boolean.getBoolean("tests.jettySsl.clientAuth"));
+ }
+
+ final Connector connector;
+ final QueuedThreadPool threadPool;
+ if ("SelectChannel".equals(connectorName)) {
+ final SelectChannelConnector c = useSsl ? new SslSelectChannelConnector(sslcontext) : new SelectChannelConnector();
+ c.setReuseAddress(true);
+ c.setLowResourcesMaxIdleTime(1500);
+ connector = c;
+ threadPool = (QueuedThreadPool) c.getThreadPool();
+ } else if ("Socket".equals(connectorName)) {
+ final SocketConnector c = useSsl ? new SslSocketConnector(sslcontext) : new SocketConnector();
+ c.setReuseAddress(true);
+ connector = c;
+ threadPool = (QueuedThreadPool) c.getThreadPool();
+ } else {
+ throw new IllegalArgumentException("Illegal value for system property 'tests.jettyConnector': " + connectorName);
+ }
+
+ connector.setPort(0);
+ connector.setHost("127.0.0.1");
+ if (threadPool != null) {
+ threadPool.setDaemon(true);
+ threadPool.setMaxThreads(10000);
+ threadPool.setMaxIdleTimeMs(5000);
+ threadPool.setMaxStopTimeMs(30000);
}
+
+ server.setConnectors(new Connector[] {connector});
+ server.setSessionIdManager(new HashSessionIdManager(new Random()));
+
+ server.start();
+
+ return server;
}
/**
@@ -149,7 +130,7 @@ public abstract class ReplicatorTestCase
* {@link Connector}s were added to the Server besides the default one.
*/
public static int serverPort(Server httpServer) {
- return httpServer.getConnectors()[0].getPort();
+ return httpServer.getConnectors()[0].getLocalPort();
}
/**