lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r819804 - in /lucene/solr/trunk/src: test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
Date Tue, 29 Sep 2009 02:55:49 GMT
Author: yonik
Date: Tue Sep 29 02:55:49 2009
New Revision: 819804

URL: http://svn.apache.org/viewvc?rev=819804&view=rev
Log:
tests: try and prevent some spurious test failures that may be happening because jetty/solr
isn't ready

Modified:
    lucene/solr/trunk/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java
    lucene/solr/trunk/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java

Modified: lucene/solr/trunk/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java?rev=819804&r1=819803&r2=819804&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java
(original)
+++ lucene/solr/trunk/src/test/org/apache/solr/client/solrj/embedded/MultiCoreExampleJettyTest.java
Tue Sep 29 02:55:49 2009
@@ -41,7 +41,7 @@
     super.setUp();
 
     jetty = new JettySolrRunner( context, 0 );
-    jetty.start();
+    jetty.start(false);
     port = jetty.getLocalPort();
 
     h.getCoreContainer().setPersistent(false);    

Modified: lucene/solr/trunk/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java?rev=819804&r1=819803&r2=819804&view=diff
==============================================================================
--- lucene/solr/trunk/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
(original)
+++ lucene/solr/trunk/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
Tue Sep 29 02:55:49 2009
@@ -18,6 +18,8 @@
 package org.apache.solr.client.solrj.embedded;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
 
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -41,6 +43,7 @@
 {
   Server server;
   FilterHolder dispatchFilter;
+  String context;
   
   public JettySolrRunner( String context, int port )
   {
@@ -70,6 +73,7 @@
   
   private void init( String context, int port )
   {
+    this.context = context;
     server = new Server( port );    
     server.setStopAtShutdown( true );
     
@@ -86,11 +90,18 @@
   
   public void start() throws Exception
   {
+    start(true);
+  }
+
+  public void start(boolean waitForSolr) throws Exception
+  {
     if(!server.isRunning() ) {
       server.start();
     }
+    if (waitForSolr) waitForSolr(context);
   }
-  
+
+
   public void stop() throws Exception
   {
     if( server.isRunning() ) {
@@ -99,6 +110,35 @@
     }
   }
 
+  /** 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.
    * @exception RuntimeException if there is no Connector
@@ -110,7 +150,7 @@
     }
     return conns[0].getLocalPort();
   }
-  
+
   //--------------------------------------------------------------
   //--------------------------------------------------------------
     



Mime
View raw message