mirror of
https://github.com/apache/lucene.git
synced 2025-02-08 11:05:29 +00:00
tests: try and prevent some spurious test failures that may be happening because jetty/solr isn't ready
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@819804 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fe2a788525
commit
3f64cb5dbc
@ -41,7 +41,7 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
jetty = new JettySolrRunner( context, 0 );
|
jetty = new JettySolrRunner( context, 0 );
|
||||||
jetty.start();
|
jetty.start(false);
|
||||||
port = jetty.getLocalPort();
|
port = jetty.getLocalPort();
|
||||||
|
|
||||||
h.getCoreContainer().setPersistent(false);
|
h.getCoreContainer().setPersistent(false);
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
package org.apache.solr.client.solrj.embedded;
|
package org.apache.solr.client.solrj.embedded;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -41,6 +43,7 @@ public class JettySolrRunner
|
|||||||
{
|
{
|
||||||
Server server;
|
Server server;
|
||||||
FilterHolder dispatchFilter;
|
FilterHolder dispatchFilter;
|
||||||
|
String context;
|
||||||
|
|
||||||
public JettySolrRunner( String context, int port )
|
public JettySolrRunner( String context, int port )
|
||||||
{
|
{
|
||||||
@ -70,6 +73,7 @@ public class JettySolrRunner
|
|||||||
|
|
||||||
private void init( String context, int port )
|
private void init( String context, int port )
|
||||||
{
|
{
|
||||||
|
this.context = context;
|
||||||
server = new Server( port );
|
server = new Server( port );
|
||||||
server.setStopAtShutdown( true );
|
server.setStopAtShutdown( true );
|
||||||
|
|
||||||
@ -85,12 +89,19 @@ public class JettySolrRunner
|
|||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
public void start() throws Exception
|
public void start() throws Exception
|
||||||
|
{
|
||||||
|
start(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start(boolean waitForSolr) throws Exception
|
||||||
{
|
{
|
||||||
if(!server.isRunning() ) {
|
if(!server.isRunning() ) {
|
||||||
server.start();
|
server.start();
|
||||||
}
|
}
|
||||||
|
if (waitForSolr) waitForSolr(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void stop() throws Exception
|
public void stop() throws Exception
|
||||||
{
|
{
|
||||||
if( server.isRunning() ) {
|
if( server.isRunning() ) {
|
||||||
@ -99,6 +110,35 @@ public class JettySolrRunner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Waits until a ping query to the solr server succeeds,
|
||||||
|
* retrying every 200 milliseconds for a total of 20 seconds.
|
||||||
|
*/
|
||||||
|
public void waitForSolr(String context) throws Exception
|
||||||
|
{
|
||||||
|
int port = getLocalPort();
|
||||||
|
|
||||||
|
// A raw term query type doesn't check the schema
|
||||||
|
URL url = new URL("http://localhost:"+port+context+"/select?q={!raw+f=junit_test_query}ping");
|
||||||
|
|
||||||
|
Exception ex = null;
|
||||||
|
// Wait for a total of 20 seconds: 100 tries, 200 milliseconds each
|
||||||
|
for (int i=0; i<100; i++) {
|
||||||
|
try {
|
||||||
|
InputStream stream = url.openStream();
|
||||||
|
stream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
ex = e;
|
||||||
|
Thread.sleep(200);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("Jetty/Solr unresponsive",ex);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Local Port of the first Connector found for the jetty Server.
|
* Returns the Local Port of the first Connector found for the jetty Server.
|
||||||
* @exception RuntimeException if there is no Connector
|
* @exception RuntimeException if there is no Connector
|
||||||
|
Loading…
x
Reference in New Issue
Block a user