SOLR-1835: convert some of the jetty/example tests to Junit4

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@927611 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-03-25 22:29:33 +00:00
parent 214bfc6f5f
commit babb0580e2
6 changed files with 111 additions and 87 deletions

View File

@ -43,6 +43,9 @@ import org.apache.solr.common.SolrInputDocument;
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.FacetParams;
* @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 extends SolrExampleTestBase
/**
* 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 extends SolrExampleTestBase
/**
* 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 extends SolrExampleTestBase
}
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 extends SolrExampleTestBase
}
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 extends SolrExampleTestBase
}
}
public void testAddDelete() throws Exception
@Test
public void testAddDelete() throws Exception
{
SolrServer server = getSolrServer();
@ -344,7 +352,8 @@ abstract public class SolrExampleTests extends SolrExampleTestBase
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 extends SolrExampleTestBase
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 extends SolrExampleTestBase
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 extends SolrExampleTestBase
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 extends SolrExampleTestBase
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 extends SolrExampleTestBase
}
}
public void testFaceting() throws Exception
@Test
public void testFaceting() throws Exception
{
SolrServer server = getSolrServer();

View File

@ -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();
}

View File

@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.embedded;
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.SolrServer;
*/
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

View File

@ -23,6 +23,8 @@ import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
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,36 +36,11 @@ 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();
}
@Override public void tearDown() throws Exception
{
super.tearDown();
jetty.stop(); // stop the server
@BeforeClass
public static void beforeTest() throws Exception {
createJetty(EXAMPLE_HOME, null, null);
}
@Override
protected SolrServer getSolrServer()
{
return server;
}
@Override
protected SolrServer createNewSolrServer()
{
@ -80,7 +57,8 @@ public class SolrExampleJettyTest extends SolrExampleTests {
throw new RuntimeException( ex );
}
}
@Test
public void testBadSetup()
{
try {

View File

@ -21,6 +21,7 @@ import org.apache.solr.client.solrj.SolrExampleTests;
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.StreamingUpdateSolrServer;
* @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

View File

@ -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 )