SOLR-533: Fixed tests so they don't use hardcoded port numbers

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@647048 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2008-04-11 05:22:54 +00:00
parent e1aa232a51
commit aca45bce71
8 changed files with 47 additions and 30 deletions

View File

@ -333,6 +333,9 @@ Bug Fixes
23. SOLR-528: Better error message when defaultSearchField is bogus or not
indexed. (Lars Kotthoff via hossman)
24. SOLR-533: Fixed tests so they don't use hardcoded port numbers.
(hossman)
Other Changes
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the

View File

@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.FilterHolder;
import org.mortbay.log.Logger;
@ -97,6 +98,18 @@ public class JettySolrRunner
server.join();
}
}
/**
* Returns the Local Port of the first Connector found for the jetty Server.
* @exception RuntimeException if there is no Connector
*/
public int getLocalPort() {
Connector[] conns = server.getConnectors();
if (0 == conns.length) {
throw new RuntimeException("Jetty Server has no Connectors");
}
return conns[0].getLocalPort();
}
//--------------------------------------------------------------
//--------------------------------------------------------------

View File

@ -33,7 +33,7 @@ import org.mortbay.jetty.webapp.WebAppContext;
*/
public class JettyWebappTest extends TestCase
{
static final int port = 8985; // not 8983
int port = 0;
static final String context = "/test";
Server server;
@ -50,11 +50,12 @@ public class JettyWebappTest extends TestCase
SocketConnector connector = new SocketConnector();
connector.setMaxIdleTime(1000 * 60 * 60);
connector.setSoLingerTime(-1);
connector.setPort(port);
connector.setPort(0);
server.setConnectors(new Connector[]{connector});
server.setStopAtShutdown( true );
server.start();
port = connector.getLocalPort();
}
@Override

View File

@ -30,7 +30,7 @@ public class LargeVolumeJettyTest extends LargeVolumeTestBase {
SolrServer server;
JettySolrRunner jetty;
static final int port = 8984; // not 8983
int port = 0;
static final String context = "/example";
@ -38,8 +38,9 @@ public class LargeVolumeJettyTest extends LargeVolumeTestBase {
{
super.setUp();
jetty = new JettySolrRunner( context, port );
jetty = new JettySolrRunner( context, 0 );
jetty.start();
port = jetty.getLocalPort();
server = this.createNewSolrServer();
}

View File

@ -33,15 +33,16 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
JettySolrRunner jetty;
static final int port = 8984; // not 8983
int port = 0;
static final String context = "/example";
@Override public void setUp() throws Exception
{
super.setUp();
jetty = new JettySolrRunner( context, port );
jetty = new JettySolrRunner( context, 0 );
jetty.start();
port = jetty.getLocalPort();
}

View File

@ -36,16 +36,17 @@ public class SolrExampleJettyTest extends SolrExampleTests {
SolrServer server;
JettySolrRunner jetty;
static final int port = 8984; // not 8983
int port = 0;
static final String context = "/example";
@Override public void setUp() throws Exception
{
super.setUp();
jetty = new JettySolrRunner( context, port );
jetty = new JettySolrRunner( context, 0 );
jetty.start();
port = jetty.getLocalPort();
System.out.println("Assigned Port#" + port);
server = this.createNewSolrServer();
}

View File

@ -52,13 +52,11 @@ public class TestDistributedSearch extends TestCase {
Random r = new Random(0);
File testDir;
int controlPort = 8985;
SolrServer controlClient;
JettySolrRunner controlJetty;
int[] ports = new int[] {7574, 7576};
List<SolrServer> clients = new ArrayList<SolrServer>();
List<JettySolrRunner> jettys = new ArrayList<JettySolrRunner>();
private List<SolrServer> clients = new ArrayList<SolrServer>();
private List<JettySolrRunner> jettys = new ArrayList<JettySolrRunner>();
String context = "/solr";
String shards;
@ -88,16 +86,17 @@ public class TestDistributedSearch extends TestCase {
}
private void createServers() throws Exception {
controlJetty = createJetty(controlPort);
controlClient = createNewSolrServer(controlPort);
private void createServers(int numShards) throws Exception {
controlJetty = createJetty("control");
controlClient = createNewSolrServer(controlJetty.getLocalPort());
StringBuilder sb = new StringBuilder();
for (int port : ports) {
for (int i = 1; i <= numShards; i++) {
if (sb.length()>0) sb.append(',');
sb.append("localhost:"+port+context);
jettys.add(createJetty(port));
clients.add(createNewSolrServer(port));
JettySolrRunner j = createJetty("shard"+i);
jettys.add(j);
clients.add(createNewSolrServer(j.getLocalPort()));
sb.append("localhost:"+j.getLocalPort()+context);
}
shards = sb.toString();
@ -110,12 +109,13 @@ public class TestDistributedSearch extends TestCase {
jettys.clear();
}
private JettySolrRunner createJetty(int port) throws Exception {
File subDir = new File(testDir, ""+port);
private JettySolrRunner createJetty(String dataDirName) throws Exception {
File subDir = new File(testDir, dataDirName);
subDir.mkdirs();
System.setProperty("solr.data.dir", subDir.toString());
JettySolrRunner jetty = new JettySolrRunner("/solr", 0);
JettySolrRunner jetty = new JettySolrRunner("/solr", port);
jetty.start();
return jetty;
}
@ -415,16 +415,12 @@ public class TestDistributedSearch extends TestCase {
public void testDistribSearch() throws Exception {
for (int nServers=1; nServers<4; nServers++) {
ports = new int[nServers];
for (int i=0; i<nServers; i++) {
ports[i] = 7574 + i*2;
}
createServers(nServers);
doTest();
}
}
public void doTest() throws Exception {
createServers();
del("*:*");
index(id,1, i1, 100,t1,"now is the time for all good men");
index(id,2, i1, 50 ,t1,"to come to the aid of their country.");

View File

@ -38,7 +38,7 @@ public abstract class CacheHeaderTestBase extends SolrExampleTestBase {
JettySolrRunner jetty;
static final int port = 8985; // not 8983
int port = 0;
static final String context = "/example";
@ -46,8 +46,9 @@ public abstract class CacheHeaderTestBase extends SolrExampleTestBase {
public void setUp() throws Exception {
super.setUp();
jetty = new JettySolrRunner(context, port, getSolrConfigFilename());
jetty = new JettySolrRunner(context, 0, getSolrConfigFilename());
jetty.start();
port = jetty.getLocalPort();
server = this.createNewSolrServer();
}