lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r927611 - in /lucene/dev/trunk/solr/src: test/org/apache/solr/client/solrj/ test/org/apache/solr/client/solrj/embedded/ webapp/src/org/apache/solr/client/solrj/embedded/
Date Thu, 25 Mar 2010 22:29:33 GMT
Author: yonik
Date: Thu Mar 25 22:29:33 2010
New Revision: 927611

URL: http://svn.apache.org/viewvc?rev=927611&view=rev
Log:
SOLR-1835: convert some of the jetty/example tests to Junit4

Added:
    lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java   (with
props)
Modified:
    lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleEmbeddedTest.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java
    lucene/dev/trunk/solr/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java?rev=927611&r1=927610&r2=927611&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java Thu
Mar 25 22:29:33 2010
@@ -43,6 +43,9 @@ import org.apache.solr.common.SolrInputD
 import org.apache.solr.common.util.XML;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.params.FacetParams;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
 
 /**
  * This should include tests against the example solr config
@@ -52,11 +55,12 @@ import org.apache.solr.common.params.Fac
  * @version $Id$
  * @since solr 1.3
  */
-abstract public class SolrExampleTests extends SolrExampleTestBase
+abstract public class SolrExampleTests extends SolrJettyTestBase
 {
   /**
    * query the example
    */
+  @Test
   public void testExampleConfig() throws Exception
   {    
     SolrServer server = getSolrServer();
@@ -160,7 +164,8 @@ abstract public class SolrExampleTests e
   /**
    * query the example
    */
-  public void testAddRetrieve() throws Exception
+ @Test
+ public void testAddRetrieve() throws Exception
   {    
     SolrServer server = getSolrServer();
     
@@ -212,7 +217,8 @@ abstract public class SolrExampleTests e
   /**
    * query the example
    */
-  public void testCommitWithin() throws Exception
+ @Test
+ public void testCommitWithin() throws Exception
   {    
     // make sure it is empty...
     SolrServer server = getSolrServer();
@@ -250,7 +256,8 @@ abstract public class SolrExampleTests e
   }
 
 
-  public void testContentStreamRequest() throws Exception {
+ @Test
+ public void testContentStreamRequest() throws Exception {
     SolrServer server = getSolrServer();
     server.deleteByQuery( "*:*" );// delete everything!
     server.commit();
@@ -283,7 +290,7 @@ abstract public class SolrExampleTests e
   }
 
 
-  protected void assertNumFound( String query, int num ) throws SolrServerException, IOException
+ protected void assertNumFound( String query, int num ) throws SolrServerException, IOException
   {
     QueryResponse rsp = getSolrServer().query( new SolrQuery( query ) );
     if( num != rsp.getResults().getNumFound() ) {
@@ -291,7 +298,8 @@ abstract public class SolrExampleTests e
     }
   }
 
-  public void testAddDelete() throws Exception
+ @Test
+ public void testAddDelete() throws Exception
   {    
     SolrServer server = getSolrServer();
     
@@ -344,7 +352,8 @@ abstract public class SolrExampleTests e
     assertNumFound( "*:*", 0 ); // make sure it got out
   }
   
-  public void testLukeHandler() throws Exception
+ @Test
+ public void testLukeHandler() throws Exception
   {    
     SolrServer server = getSolrServer();
     
@@ -370,7 +379,8 @@ abstract public class SolrExampleTests e
     assertNotNull( rsp.getFieldTypeInfo() ); 
   }
 
-  public void testStatistics() throws Exception
+ @Test
+ public void testStatistics() throws Exception
   {    
     SolrServer server = getSolrServer();
     
@@ -401,8 +411,8 @@ abstract public class SolrExampleTests e
     FieldStatsInfo stats = rsp.getFieldStatsInfo().get( f );
     assertNotNull( stats );
     
-    assertEquals( 23.0, stats.getMin() );
-    assertEquals( 94.0, stats.getMax() );
+    assertEquals( 23.0, stats.getMin().doubleValue(), 0 );
+    assertEquals( 94.0, stats.getMax().doubleValue(), 0 );
     assertEquals( new Long(nums.length), stats.getCount() );
     assertEquals( new Long(0), stats.getMissing() );
     assertEquals( "26.4", stats.getStddev().toString().substring(0,4) );
@@ -427,8 +437,8 @@ abstract public class SolrExampleTests e
     stats = rsp.getFieldStatsInfo().get( f );
     assertNotNull( stats );
     
-    assertEquals( 5.0, stats.getMin() );
-    assertEquals( 20.0, stats.getMax() );
+    assertEquals( 5.0, stats.getMin().doubleValue(), 0 );
+    assertEquals( 20.0, stats.getMax().doubleValue(), 0 );
     assertEquals( new Long(nums.length), stats.getCount() );
     assertEquals( new Long(0), stats.getMissing() );
     
@@ -476,7 +486,8 @@ abstract public class SolrExampleTests e
     assertEquals( "they have the same distribution", inStockF.getStddev(), inStockT.getStddev()
);
   }
 
-  public void testPingHandler() throws Exception
+ @Test
+ public void testPingHandler() throws Exception
   {    
     SolrServer server = getSolrServer();
     
@@ -499,7 +510,8 @@ abstract public class SolrExampleTests e
     }
   }
   
-  public void testFaceting() throws Exception
+ @Test
+ public void testFaceting() throws Exception
   {    
     SolrServer server = getSolrServer();
     

Added: lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java?rev=927611&view=auto
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java (added)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java Thu
Mar 25 22:29:33 2010
@@ -0,0 +1,68 @@
+package org.apache.solr.client.solrj;
+
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.embedded.JettySolrRunner;
+import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
+import org.junit.AfterClass;
+
+abstract public class SolrJettyTestBase extends SolrTestCaseJ4 
+{
+  // Try not introduce a dependency on the example schema or config unless you need to.
+  // using configs in the test directory allows more flexibility to change "example"
+  // without breaking configs.
+
+  public static String EXAMPLE_HOME="../../../example/solr/";
+  public static String EXAMPLE_SCHEMA=EXAMPLE_HOME+"conf/schema.xml";
+  public static String EXAMPLE_CONFIG=EXAMPLE_HOME+"conf/solrconfig.xml";
+
+  public String getSolrHome() { return EXAMPLE_HOME; }
+
+  public static JettySolrRunner jetty;
+  public static int port;
+  public static SolrServer server;
+  public static String context;
+
+  public static JettySolrRunner createJetty(String solrHome, String configFile, String context)
throws Exception {
+    // creates the data dir
+    initCore(null, null);
+
+    ignoreException("maxWarmingSearchers");
+
+    // this sets the property for jetty starting SolrDispatchFilter
+    System.setProperty( "solr.solr.home", solrHome);
+    System.setProperty( "solr.data.dir", dataDir.getCanonicalPath() );
+
+    context = context==null ? "/solr" : context;
+    SolrJettyTestBase.context = context;
+    JettySolrRunner jetty = new JettySolrRunner( context, 0, configFile );
+
+    jetty.start();
+    port = jetty.getLocalPort();
+    log.info("Jetty Assigned Port#" + port);
+    return jetty;
+  }
+
+
+  @AfterClass
+  public static void afterSolrJettyTestBase() throws Exception {
+    if (jetty != null) {
+      jetty.stop();
+      jetty = null;
+    }
+  }
+
+
+  public SolrServer getSolrServer() {
+    {
+      if (server == null) {
+        server = createNewSolrServer();
+      }
+      return server;
+    }
+  }
+
+  /**
+   * Create a new solr server
+   */
+  protected abstract SolrServer createNewSolrServer();
+}

Propchange: lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/SolrJettyTestBase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleEmbeddedTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleEmbeddedTest.java?rev=927611&r1=927610&r2=927611&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleEmbeddedTest.java
(original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleEmbeddedTest.java
Thu Mar 25 22:29:33 2010
@@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.emb
 
 import org.apache.solr.client.solrj.SolrExampleTests;
 import org.apache.solr.client.solrj.SolrServer;
+import org.junit.BeforeClass;
 
 /**
  * This runs SolrServer test using 
@@ -28,20 +29,9 @@ import org.apache.solr.client.solrj.Solr
  */
 public class SolrExampleEmbeddedTest extends SolrExampleTests {
 
-  SolrServer server;
-  
-  @Override public void setUp() throws Exception 
-  {
-    super.setUp();
-    
-    // setup the server...
-    server = createNewSolrServer();
-  }
-
-  @Override
-  protected SolrServer getSolrServer()
-  {
-    return server;
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    initCore(EXAMPLE_CONFIG, EXAMPLE_SCHEMA);
   }
 
   @Override

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java?rev=927611&r1=927610&r2=927611&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
(original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java
Thu Mar 25 22:29:33 2010
@@ -23,6 +23,8 @@ import org.apache.solr.client.solrj.impl
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.schema.SchemaField;
 import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
 
 /**
  * TODO? perhaps use:
@@ -34,37 +36,12 @@ import org.junit.Assert;
  */
 public class SolrExampleJettyTest extends SolrExampleTests {
 
-  SolrServer server;
-  JettySolrRunner jetty;
-
-  int port = 0;
-  static final String context = "/example";
-  
-  @Override public void setUp() throws Exception 
-  {
-    super.setUp();
-    
-    jetty = new JettySolrRunner( context, 0 );
-    jetty.start();
-    port = jetty.getLocalPort();
-    log.info("Assigned Port#" + port);
-    server = this.createNewSolrServer();
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    createJetty(EXAMPLE_HOME, null, null);
   }
-
-  @Override public void tearDown() throws Exception 
-  {
-    super.tearDown();
-    jetty.stop();  // stop the server
-  }
-  
   
   @Override
-  protected SolrServer getSolrServer()
-  {
-    return server;
-  }
-
-  @Override
   protected SolrServer createNewSolrServer()
   {
     try {
@@ -80,7 +57,8 @@ public class SolrExampleJettyTest extend
       throw new RuntimeException( ex );
     }
   }
-  
+
+  @Test
   public void testBadSetup()
   {
     try {

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java?rev=927611&r1=927610&r2=927611&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java
(original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingTest.java
Thu Mar 25 22:29:33 2010
@@ -21,6 +21,7 @@ import org.apache.solr.client.solrj.Solr
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
 import org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer;
+import org.junit.BeforeClass;
 
 
 /**
@@ -29,35 +30,9 @@ import org.apache.solr.client.solrj.impl
  * @since solr 1.3
  */
 public class SolrExampleStreamingTest extends SolrExampleTests {
-
-  SolrServer server;
-  JettySolrRunner jetty;
-
-  int port = 0;
-  static final String context = "/example";
-  
-  @Override public void setUp() throws Exception 
-  {
-    super.setUp();
-    
-    jetty = new JettySolrRunner( context, 0 );
-    jetty.start();
-    port = jetty.getLocalPort();
-    log.info("Assigned Port#" + port);
-    server = this.createNewSolrServer();
-  }
-
-  @Override public void tearDown() throws Exception 
-  {
-    super.tearDown();
-    jetty.stop();  // stop the server
-  }
-  
-  
-  @Override
-  protected SolrServer getSolrServer()
-  {
-    return server;
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    createJetty(EXAMPLE_HOME, null, null);
   }
 
   @Override

Modified: lucene/dev/trunk/solr/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java?rev=927611&r1=927610&r2=927611&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
(original)
+++ lucene/dev/trunk/solr/src/webapp/src/org/apache/solr/client/solrj/embedded/JettySolrRunner.java
Thu Mar 25 22:29:33 2010
@@ -53,7 +53,8 @@ public class JettySolrRunner 
   public JettySolrRunner( String context, int port, String solrConfigFilename )
   {
     this.init( context, port );
-    dispatchFilter.setInitParameter("solrconfig-filename", solrConfigFilename);
+    if (solrConfigFilename != null)
+      dispatchFilter.setInitParameter("solrconfig-filename", solrConfigFilename);
   }
   
 //  public JettySolrRunner( String context, String home, String dataDir, int port, boolean
log )



Mime
View raw message