Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start and stop solr server from scala program

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.

like image 375
Harsh Gupta Avatar asked May 09 '26 14:05

Harsh Gupta


1 Answers

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();
like image 96
cheffe Avatar answered May 11 '26 10:05

cheffe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!