tests: factor out common client creation code

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@927651 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-03-26 00:28:21 +00:00
parent eb1537e7da
commit 88534cd9ad
8 changed files with 25 additions and 93 deletions

View File

@ -1,6 +1,7 @@
package org.apache.solr.client.solrj; package org.apache.solr.client.solrj;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.embedded.JettySolrRunner; import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -34,7 +35,7 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
context = context==null ? "/solr" : context; context = context==null ? "/solr" : context;
SolrJettyTestBase.context = context; SolrJettyTestBase.context = context;
JettySolrRunner jetty = new JettySolrRunner( context, 0, configFile ); jetty = new JettySolrRunner( context, 0, configFile );
jetty.start(); jetty.start();
port = jetty.getLocalPort(); port = jetty.getLocalPort();
@ -62,7 +63,27 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
} }
/** /**
* Create a new solr server * Create a new solr server.
* If createJetty was called, an http implementation will be created,
* otherwise an embedded implementation will be created.
* Subclasses should override for other options.
*/ */
protected abstract SolrServer createNewSolrServer(); public SolrServer createNewSolrServer() {
if (jetty != null) {
try {
// setup the server...
String url = "http://localhost:"+port+context;
CommonsHttpSolrServer s = new CommonsHttpSolrServer( url );
s.setConnectionTimeout(100); // 1/10th sec
s.setDefaultMaxConnectionsPerHost(100);
s.setMaxTotalConnections(100);
return s;
}
catch( Exception ex ) {
throw new RuntimeException( ex );
}
} else {
return new EmbeddedSolrServer( h.getCoreContainer(), "" );
}
}
} }

View File

@ -23,31 +23,12 @@ import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.junit.BeforeClass; import org.junit.BeforeClass;
/** /**
* @version $Id$
* @see org.apache.solr.client.solrj.impl.BinaryRequestWriter * @see org.apache.solr.client.solrj.impl.BinaryRequestWriter
* @see org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec * @see org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec
* @since solr 1.4
*/ */
public class LargeVolumeBinaryJettyTest extends LargeVolumeTestBase { public class LargeVolumeBinaryJettyTest extends LargeVolumeTestBase {
@BeforeClass @BeforeClass
public static void beforeTest() throws Exception { public static void beforeTest() throws Exception {
createJetty(EXAMPLE_HOME, null, null); createJetty(EXAMPLE_HOME, null, null);
} }
@Override
protected SolrServer createNewSolrServer() {
try {
// setup the server...
String url = "http://localhost:" + port + context;
CommonsHttpSolrServer s = new CommonsHttpSolrServer(url);
s.setRequestWriter(new BinaryRequestWriter());
s.setConnectionTimeout(100); // 1/10th sec
s.setDefaultMaxConnectionsPerHost(100);
s.setMaxTotalConnections(100);
return s;
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
}
} }

View File

@ -21,19 +21,9 @@ import org.apache.solr.client.solrj.LargeVolumeTestBase;
import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServer;
import org.junit.BeforeClass; import org.junit.BeforeClass;
/**
* @version $Id$
* @since solr 1.3
*/
public class LargeVolumeEmbeddedTest extends LargeVolumeTestBase { public class LargeVolumeEmbeddedTest extends LargeVolumeTestBase {
@BeforeClass @BeforeClass
public static void beforeTest() throws Exception { public static void beforeTest() throws Exception {
initCore(EXAMPLE_CONFIG, EXAMPLE_SCHEMA, EXAMPLE_HOME); initCore(EXAMPLE_CONFIG, EXAMPLE_SCHEMA, EXAMPLE_HOME);
} }
@Override
protected SolrServer createNewSolrServer()
{
return new EmbeddedSolrServer( h.getCoreContainer(), "" );
}
} }

View File

@ -22,30 +22,9 @@ import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.junit.BeforeClass; import org.junit.BeforeClass;
/**
* @version $Id$
* @since solr 1.3
*/
public class LargeVolumeJettyTest extends LargeVolumeTestBase { public class LargeVolumeJettyTest extends LargeVolumeTestBase {
@BeforeClass @BeforeClass
public static void beforeTest() throws Exception { public static void beforeTest() throws Exception {
createJetty(EXAMPLE_HOME, null, null); createJetty(EXAMPLE_HOME, null, null);
} }
@Override
protected SolrServer createNewSolrServer()
{
try {
// setup the server...
String url = "http://localhost:"+port+context;
CommonsHttpSolrServer s = new CommonsHttpSolrServer( url );
s.setConnectionTimeout(100); // 1/10th sec
s.setDefaultMaxConnectionsPerHost(100);
s.setMaxTotalConnections(100);
return s;
}
catch( Exception ex ) {
throw new RuntimeException( ex );
}
}
} }

View File

@ -33,10 +33,4 @@ public class SolrExampleEmbeddedTest extends SolrExampleTests {
public static void beforeTest() throws Exception { public static void beforeTest() throws Exception {
initCore(EXAMPLE_CONFIG, EXAMPLE_SCHEMA, EXAMPLE_HOME); initCore(EXAMPLE_CONFIG, EXAMPLE_SCHEMA, EXAMPLE_HOME);
} }
@Override
protected SolrServer createNewSolrServer()
{
return new EmbeddedSolrServer( h.getCoreContainer(), "" );
}
} }

View File

@ -31,8 +31,6 @@ import org.junit.Test;
* http://docs.codehaus.org/display/JETTY/ServletTester * http://docs.codehaus.org/display/JETTY/ServletTester
* rather then open a real connection? * rather then open a real connection?
* *
* @version $Id$
* @since solr 1.3
*/ */
public class SolrExampleJettyTest extends SolrExampleTests { public class SolrExampleJettyTest extends SolrExampleTests {
@ -40,23 +38,6 @@ public class SolrExampleJettyTest extends SolrExampleTests {
public static void beforeTest() throws Exception { public static void beforeTest() throws Exception {
createJetty(EXAMPLE_HOME, null, null); createJetty(EXAMPLE_HOME, null, null);
} }
@Override
protected SolrServer createNewSolrServer()
{
try {
// setup the server...
String url = "http://localhost:"+port+context;
CommonsHttpSolrServer s = new CommonsHttpSolrServer( url );
s.setConnectionTimeout(100); // 1/10th sec
s.setDefaultMaxConnectionsPerHost(100);
s.setMaxTotalConnections(100);
return s;
}
catch( Exception ex ) {
throw new RuntimeException( ex );
}
}
@Test @Test
public void testBadSetup() public void testBadSetup()

View File

@ -36,7 +36,7 @@ public class SolrExampleStreamingTest extends SolrExampleTests {
} }
@Override @Override
protected SolrServer createNewSolrServer() public SolrServer createNewSolrServer()
{ {
try { try {
// setup the server... // setup the server...

View File

@ -33,20 +33,6 @@ import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public abstract class CacheHeaderTestBase extends SolrJettyTestBase { public abstract class CacheHeaderTestBase extends SolrJettyTestBase {
@Override
protected CommonsHttpSolrServer createNewSolrServer() {
try {
// setup the server...
String url = "http://localhost:" + port + context;
CommonsHttpSolrServer s = new CommonsHttpSolrServer(url);
s.setConnectionTimeout(100); // 1/10th sec
s.setDefaultMaxConnectionsPerHost(100);
s.setMaxTotalConnections(100);
return s;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
protected HttpMethodBase getSelectMethod(String method) { protected HttpMethodBase getSelectMethod(String method) {
CommonsHttpSolrServer httpserver = (CommonsHttpSolrServer)getSolrServer(); CommonsHttpSolrServer httpserver = (CommonsHttpSolrServer)getSolrServer();