Question

Solr comes with packaged jetty jar start.jar in example folder . For my scalatest automation I need to control solr start and stop from my scalatest module . How can I do that ? Please guide and suggest.

Was it helpful?

Solution

I have written a JUnit rule is intended for integration tests. This rule starts and stops the Jetty server that is wrapped by Solr on behalf of the class JettySolrRunner.

The relevant part to start Solr with the embedded Jetty is

File solrXml = new File("/solr/home/solr.xml");
File solrHomeDir = solrXml.getParentFile();

int port = 8080;
String context = "/solr";
// use org.apache.solr.client.solrj.embedded.JettySolrRunner
JettySolrRunner jettySolr 
  = new JettySolrRunner(solrHomeDir.getAbsolutePath(), context, port);

boolean waitUntilTheSolrWebAppHasStarted = true;
jettySolr.start(waitUntilTheSolrWebAppHasStarted);

Stopping that server is rather straight forward

jettySolr.stop();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top