mirror of https://github.com/apache/lucene.git
remove strange retry-port loop, and just bind to ephemeral port
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1481947 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d9c6fa0b49
commit
7d04352542
|
@ -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,11 +54,7 @@ public abstract class ReplicatorTestCase extends LuceneTestCase {
|
|||
* {@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 server = new Server(0);
|
||||
|
||||
server.setHandler(handler);
|
||||
|
||||
|
@ -118,7 +108,7 @@ public abstract class ReplicatorTestCase extends LuceneTestCase {
|
|||
throw new IllegalArgumentException("Illegal value for system property 'tests.jettyConnector': " + connectorName);
|
||||
}
|
||||
|
||||
connector.setPort(port);
|
||||
connector.setPort(0);
|
||||
connector.setHost("127.0.0.1");
|
||||
if (threadPool != null) {
|
||||
threadPool.setDaemon(true);
|
||||
|
@ -130,18 +120,9 @@ public abstract class ReplicatorTestCase extends LuceneTestCase {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,7 +130,7 @@ public abstract class ReplicatorTestCase extends LuceneTestCase {
|
|||
* {@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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue