SOLR-467 -- remove "core" options from solrj

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@617933 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2008-02-03 00:15:33 +00:00
parent 40a9f64a0e
commit 7735a84c2a
8 changed files with 77 additions and 117 deletions

View File

@ -38,7 +38,6 @@ public abstract class SolrRequest implements Serializable
private METHOD method = METHOD.GET;
private String path = null;
private String core = null;
//---------------------------------------------------------
//---------------------------------------------------------
@ -66,15 +65,6 @@ public abstract class SolrRequest implements Serializable
this.path = path;
}
public String getCore() {
return core;
}
public void setCore(String core) {
this.core = core;
}
public abstract SolrParams getParams();
public abstract Collection<ContentStream> getContentStreams() throws IOException;
public abstract SolrResponse process( SolrServer server ) throws SolrServerException, IOException;

View File

@ -36,8 +36,6 @@ import org.apache.solr.common.util.NamedList;
*/
public abstract class SolrServer
{
protected String defaultCore = null;
public UpdateResponse add(Collection<SolrInputDocument> docs, boolean overwrite ) throws SolrServerException, IOException {
UpdateRequest req = new UpdateRequest();
req.add(docs);
@ -97,14 +95,6 @@ public abstract class SolrServer
public QueryResponse query(SolrParams params) throws SolrServerException {
return new QueryRequest( params ).process( this );
}
public String getDefaultCore() {
return defaultCore;
}
public void setDefaultCore(String defaultCore) {
this.defaultCore = defaultCore;
}
/**
* SolrServer implementations need to implement a how a request is actually processed

View File

@ -56,22 +56,24 @@ public class EmbeddedSolrServer extends SolrServer
protected final SolrCore core;
protected final SolrRequestParsers parser;
protected boolean useMultiCore;
protected final String coreName; // use MultiCore registry
public EmbeddedSolrServer( SolrCore core )
{
this.core = core;
this.useMultiCore = false;
this.coreName = null;
this.parser = init();
}
public EmbeddedSolrServer()
public EmbeddedSolrServer( String coreName )
{
this( null );
if( MultiCore.getRegistry().getDefaultCore() == null ) {
throw new RuntimeException( "Must initialize multicore if you want to use this" );
this.core = null;
this.coreName = coreName;
SolrCore c = MultiCore.getRegistry().getCore( coreName );
if( c == null ) {
throw new RuntimeException( "Unknown core: "+coreName );
}
this.useMultiCore = true;
this.parser = init();
}
private SolrRequestParsers init()
@ -94,32 +96,13 @@ public class EmbeddedSolrServer extends SolrServer
}
// Check for multicore action
SolrCore core = this.core;
MultiCore multicore = MultiCore.getRegistry();
if( useMultiCore ) {
String c = getDefaultCore();
if( request.getCore() != null ) {
c = request.getCore();
}
if( c != null ) {
if( !multicore.isEnabled() ) {
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
"multicore access is not enabled" );
}
if( c.length() > 0 ) {
core = multicore.getCore( c );
}
else {
core = multicore.getDefaultCore();
}
if( core == null ) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"Unknown core: "+c );
}
}
else {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"missing core" );
SolrCore core = this.core;
if( core == null ) {
core = multicore.getCore( coreName );
if( core == null ) {
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
"Unknown core: "+coreName );
}
}
@ -143,7 +126,7 @@ public class EmbeddedSolrServer extends SolrServer
}
// Perhaps the path is to manage the cores
if( handler == null &&
useMultiCore &&
coreName != null &&
path.equals( multicore.getAdminPath() ) &&
multicore.isEnabled() ) {
handler = multicore.getMultiCoreHandler();

View File

@ -142,16 +142,7 @@ public class CommonsHttpSolrServer extends SolrServer
if( path == null || !path.startsWith( "/" ) ) {
path = "/select";
}
// modify the path for multicore access
String core = getDefaultCore();
if( request.getCore() != null ) {
core= request.getCore();
}
if( core != null && core.length() > 0 ) {
path = "/"+core+path;
}
if( params == null ) {
params = new ModifiableSolrParams();
}

View File

@ -54,18 +54,6 @@ public class MultiCoreRequest extends SolrRequest
{
this.core = v;
}
@Override
public final void setCore( String v )
{
throw new UnsupportedOperationException( "MultiCoreRequest does not use a core.");
}
@Override
public final String getCore()
{
return ""; // force it to invalid core
}
//---------------------------------------------------------------------------------------
//

View File

@ -23,6 +23,7 @@ import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.request.UpdateRequest.ACTION;
import org.apache.solr.client.solrj.response.MultiCoreResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.SolrCore;
/**
@ -37,17 +38,30 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
@Override public String getSolrConfigFile() { return getSolrHome()+"core0/conf/solrconfig.xml"; }
@Override
protected final SolrServer getSolrServer()
{
throw new UnsupportedOperationException();
}
@Override
protected final SolrServer createNewSolrServer()
{
throw new UnsupportedOperationException();
}
protected abstract SolrServer getSolrCore0();
protected abstract SolrServer getSolrCore1();
protected abstract SolrServer getSolrAdmin();
public void testMultiCore() throws Exception
{
SolrServer solr = getSolrServer();
UpdateRequest up = new UpdateRequest();
up.setAction( ACTION.COMMIT, true, true );
up.setCore( "core0" );
up.deleteByQuery( "*:*" );
up.process( solr );
up.setCore( "core1" );
up.process( solr );
up.process( getSolrCore0() );
up.process( getSolrCore1() );
up.clear();
// Add something to each core
@ -56,30 +70,26 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
doc.setField( "core0", "yup" );
// Add to core0
up.setCore( "core0" );
up.add( doc );
up.process( solr );
up.process( getSolrCore0() );
// You can't add it to core1
try {
up.setCore( "core1" );
up.process( solr );
up.process( getSolrCore1() );
fail( "Can't add core0 field to core1!" );
}
catch( Exception ex ) {}
// Add to core1
up.setCore( "core1" );
doc.setField( "id", "BBB" );
doc.setField( "core1", "yup" );
doc.removeField( "core0" );
up.add( doc );
up.process( solr );
up.process( getSolrCore1() );
// You can't add it to core1
try {
up.setCore( "core0" );
up.process( solr );
up.process( getSolrCore0() );
fail( "Can't add core1 field to core0!" );
}
catch( Exception ex ) {}
@ -87,28 +97,25 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase
// now Make sure AAA is in 0 and BBB in 1
SolrQuery q = new SolrQuery();
QueryRequest r = new QueryRequest( q );
r.setCore( "core0" );
q.setQuery( "id:AAA" );
assertEquals( 1, r.process( solr ).getResults().size() );
r.setCore( "core1" );
assertEquals( 0, r.process( solr ).getResults().size() );
assertEquals( 1, r.process( getSolrCore0() ).getResults().size() );
assertEquals( 0, r.process( getSolrCore1() ).getResults().size() );
// Now test Changing the default core
solr.setDefaultCore( "core0" );
assertEquals( 1, solr.query( new SolrQuery( "id:AAA" ) ).getResults().size() );
assertEquals( 0, solr.query( new SolrQuery( "id:BBB" ) ).getResults().size() );
assertEquals( 1, getSolrCore0().query( new SolrQuery( "id:AAA" ) ).getResults().size() );
assertEquals( 0, getSolrCore0().query( new SolrQuery( "id:BBB" ) ).getResults().size() );
solr.setDefaultCore( "core1" );
assertEquals( 0, solr.query( new SolrQuery( "id:AAA" ) ).getResults().size() );
assertEquals( 1, solr.query( new SolrQuery( "id:BBB" ) ).getResults().size() );
assertEquals( 0, getSolrCore1().query( new SolrQuery( "id:AAA" ) ).getResults().size() );
assertEquals( 1, getSolrCore1().query( new SolrQuery( "id:BBB" ) ).getResults().size() );
// Now test reloading it should have a newer open time
String name = "core0";
MultiCoreResponse mcr = MultiCoreRequest.getStatus( name, solr );
SolrServer coreadmin = getSolrAdmin();
MultiCoreResponse mcr = MultiCoreRequest.getStatus( name, coreadmin );
long before = mcr.getStartTime( name ).getTime();
MultiCoreRequest.reloadCore( name, solr );
MultiCoreRequest.reloadCore( name, coreadmin );
mcr = MultiCoreRequest.getStatus( name, solr );
mcr = MultiCoreRequest.getStatus( name, coreadmin );
long after = mcr.getStartTime( name ).getTime();
assertTrue( "should have more recent time: "+after+","+before, after > before );
}

View File

@ -31,8 +31,6 @@ import org.apache.solr.core.MultiCore;
*/
public class MultiCoreEmbeddedTest extends MultiCoreExampleTestBase {
SolrServer server;
@Override public void setUp() throws Exception
{
super.setUp();
@ -40,20 +38,23 @@ public class MultiCoreEmbeddedTest extends MultiCoreExampleTestBase {
File home = new File( getSolrHome() );
File f = new File( home, "multicore.xml" );
MultiCore.getRegistry().load( getSolrHome(), f );
// setup the server...
server = createNewSolrServer();
}
@Override
protected SolrServer getSolrServer()
protected SolrServer getSolrCore0()
{
return server;
return new EmbeddedSolrServer( "core0" );
}
@Override
protected SolrServer createNewSolrServer()
protected SolrServer getSolrCore1()
{
return new EmbeddedSolrServer();
return new EmbeddedSolrServer( "core1" );
}
@Override
protected SolrServer getSolrAdmin()
{
return new EmbeddedSolrServer( "core0" );
}
}

View File

@ -31,7 +31,6 @@ import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
*/
public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
SolrServer server;
JettySolrRunner jetty;
static final int port = 8984; // not 8983
@ -44,7 +43,6 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
jetty = new JettySolrRunner( context, port );
jetty.start();
server = this.createNewSolrServer();
}
@Override public void tearDown() throws Exception
@ -53,18 +51,30 @@ public class MultiCoreExampleJettyTest extends MultiCoreExampleTestBase {
jetty.stop(); // stop the server
}
@Override
protected SolrServer getSolrServer()
protected SolrServer getSolrCore0()
{
return server;
return createServer( "core0" );
}
@Override
protected SolrServer createNewSolrServer()
protected SolrServer getSolrCore1()
{
return createServer( "core1" );
}
@Override
protected SolrServer getSolrAdmin()
{
return createServer( "" );
}
private SolrServer createServer( String name )
{
try {
// setup the server...
String url = "http://localhost:"+port+context;
String url = "http://localhost:"+port+context+"/"+name;
CommonsHttpSolrServer s = new CommonsHttpSolrServer( url );
s.setConnectionTimeout(100); // 1/10th sec
s.setDefaultMaxConnectionsPerHost(100);