mirror of https://github.com/apache/lucene.git
SOLR-1930: remove doLegacyUpdate, use DirectSolrConnection for tests
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1054124 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c918763e9b
commit
2d796fae1a
|
@ -84,47 +84,6 @@ public class XmlUpdateRequestHandler extends ContentStreamHandlerBase {
|
||||||
return new XMLLoader(processor, inputFactory);
|
return new XMLLoader(processor, inputFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Convenience method for getting back a simple XML string indicating
|
|
||||||
* success or failure from an XML formated Update (from the Reader)
|
|
||||||
*
|
|
||||||
* @since solr 1.2
|
|
||||||
* @deprecated Direct updates fro ma Reader, as well as the response
|
|
||||||
* format produced by this method, have been deprecated
|
|
||||||
* and will be removed in future versions. Any code using
|
|
||||||
* this method should be changed to use {@link #handleRequest}
|
|
||||||
* method with a ContentStream.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public void doLegacyUpdate(Reader input, Writer output) {
|
|
||||||
SolrCore core = SolrCore.getSolrCore();
|
|
||||||
SolrQueryRequest req = new LocalSolrQueryRequest(core, new HashMap<String,String[]>());
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Old style requests do not choose a custom handler
|
|
||||||
UpdateRequestProcessorChain processorFactory = core.getUpdateProcessingChain(null);
|
|
||||||
|
|
||||||
SolrQueryResponse rsp = new SolrQueryResponse(); // ignored
|
|
||||||
XMLStreamReader parser = inputFactory.createXMLStreamReader(input);
|
|
||||||
UpdateRequestProcessor processor = processorFactory.createProcessor(req, rsp);
|
|
||||||
XMLLoader loader = (XMLLoader) newLoader(req, processor);
|
|
||||||
loader.processUpdate(req, processor, parser);
|
|
||||||
processor.finish();
|
|
||||||
output.write("<result status=\"0\"></result>");
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
try {
|
|
||||||
SolrException.logOnce(log, "Error processing \"legacy\" update command", ex);
|
|
||||||
XML.writeXML(output, "result", SolrException.toStr(ex), "status", "1");
|
|
||||||
} catch (Exception ee) {
|
|
||||||
log.error("Error writing to output stream: " + ee);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
req.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//////////////////////// SolrInfoMBeans methods //////////////////////
|
//////////////////////// SolrInfoMBeans methods //////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.apache.solr.util;
|
package org.apache.solr.util;
|
||||||
|
|
||||||
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.params.CommonParams;
|
import org.apache.solr.common.params.CommonParams;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.common.util.XML;
|
import org.apache.solr.common.util.XML;
|
||||||
|
@ -25,13 +26,16 @@ import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import org.apache.solr.core.CoreDescriptor;
|
import org.apache.solr.core.CoreDescriptor;
|
||||||
import org.apache.solr.core.SolrResourceLoader;
|
import org.apache.solr.core.SolrResourceLoader;
|
||||||
|
import org.apache.solr.handler.JsonUpdateRequestHandler;
|
||||||
import org.apache.solr.handler.XmlUpdateRequestHandler;
|
import org.apache.solr.handler.XmlUpdateRequestHandler;
|
||||||
import org.apache.solr.request.LocalSolrQueryRequest;
|
import org.apache.solr.request.LocalSolrQueryRequest;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
|
import org.apache.solr.request.SolrRequestHandler;
|
||||||
import org.apache.solr.request.SolrRequestInfo;
|
import org.apache.solr.request.SolrRequestInfo;
|
||||||
import org.apache.solr.response.QueryResponseWriter;
|
import org.apache.solr.response.QueryResponseWriter;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
import org.apache.solr.response.SolrQueryResponse;
|
||||||
import org.apache.solr.schema.IndexSchema;
|
import org.apache.solr.schema.IndexSchema;
|
||||||
|
import org.apache.solr.servlet.DirectSolrConnection;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.apache.solr.common.util.NamedList.NamedListEntry;
|
import org.apache.solr.common.util.NamedList.NamedListEntry;
|
||||||
|
@ -203,19 +207,24 @@ public class TestHarness {
|
||||||
* Processes an "update" (add, commit or optimize) and
|
* Processes an "update" (add, commit or optimize) and
|
||||||
* returns the response as a String.
|
* returns the response as a String.
|
||||||
*
|
*
|
||||||
* @deprecated The better approach is to instantiate an Updatehandler directly
|
|
||||||
*
|
|
||||||
* @param xml The XML of the update
|
* @param xml The XML of the update
|
||||||
* @return The XML response to the update
|
* @return The XML response to the update
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public String update(String xml) {
|
public String update(String xml) {
|
||||||
|
DirectSolrConnection connection = new DirectSolrConnection(core);
|
||||||
StringReader req = new StringReader(xml);
|
SolrRequestHandler handler = core.getRequestHandler("/update");
|
||||||
StringWriter writer = new StringWriter(32000);
|
// prefer the handler mapped to /update, but use our generic backup handler
|
||||||
|
// if that lookup fails
|
||||||
updater.doLegacyUpdate(req, writer);
|
if (handler == null) {
|
||||||
return writer.toString();
|
handler = updater;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return connection.request(handler, null, xml);
|
||||||
|
} catch (SolrException e) {
|
||||||
|
throw (SolrException)e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -240,7 +249,12 @@ public class TestHarness {
|
||||||
* @return null if successful, otherwise the XML response to the update
|
* @return null if successful, otherwise the XML response to the update
|
||||||
*/
|
*/
|
||||||
public String validateErrorUpdate(String xml) throws SAXException {
|
public String validateErrorUpdate(String xml) throws SAXException {
|
||||||
return checkUpdateStatus(xml, "1");
|
try {
|
||||||
|
return checkUpdateStatus(xml, "1");
|
||||||
|
} catch (SolrException e) {
|
||||||
|
// return ((SolrException)e).getMessage();
|
||||||
|
return null; // success
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -254,7 +268,7 @@ public class TestHarness {
|
||||||
public String checkUpdateStatus(String xml, String code) throws SAXException {
|
public String checkUpdateStatus(String xml, String code) throws SAXException {
|
||||||
try {
|
try {
|
||||||
String res = update(xml);
|
String res = update(xml);
|
||||||
String valid = validateXPath(res, "//result[@status="+code+"]" );
|
String valid = validateXPath(res, "//int[@name='status']="+code );
|
||||||
return (null == valid) ? null : res;
|
return (null == valid) ? null : res;
|
||||||
} catch (XPathExpressionException e) {
|
} catch (XPathExpressionException e) {
|
||||||
throw new RuntimeException
|
throw new RuntimeException
|
||||||
|
@ -262,27 +276,6 @@ public class TestHarness {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates that an add of a single document results in success.
|
|
||||||
*
|
|
||||||
* @param fieldsAndValues Odds are field names, Evens are values
|
|
||||||
* @return null if successful, otherwise the XML response to the update
|
|
||||||
* @see #appendSimpleDoc
|
|
||||||
*/
|
|
||||||
public String validateAddDoc(String... fieldsAndValues)
|
|
||||||
throws XPathExpressionException, SAXException, IOException {
|
|
||||||
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
buf.append("<add>");
|
|
||||||
appendSimpleDoc(buf, fieldsAndValues);
|
|
||||||
buf.append("</add>");
|
|
||||||
|
|
||||||
String res = update(buf.toString());
|
|
||||||
String valid = validateXPath(res, "//result[@status=0]" );
|
|
||||||
return (null == valid) ? null : res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates a "query" response against an array of XPath test strings
|
* Validates a "query" response against an array of XPath test strings
|
||||||
|
@ -409,29 +402,6 @@ public class TestHarness {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A helper that adds an xml <doc> containing all of the
|
|
||||||
* fields and values specified (odds are fields, evens are values)
|
|
||||||
* to a StringBuilder
|
|
||||||
*/
|
|
||||||
public void appendSimpleDoc(StringBuilder buf, String... fieldsAndValues)
|
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
buf.append(makeSimpleDoc(fieldsAndValues));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A helper that adds an xml <doc> containing all of the
|
|
||||||
* fields and values specified (odds are fields, evens are values)
|
|
||||||
* to a StringBuffer.
|
|
||||||
* @deprecated see {@link #appendSimpleDoc(StringBuilder, String...)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public void appendSimpleDoc(StringBuffer buf, String... fieldsAndValues)
|
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
buf.append(makeSimpleDoc(fieldsAndValues));
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* A helper that creates an xml <doc> containing all of the
|
* A helper that creates an xml <doc> containing all of the
|
||||||
* fields and values specified
|
* fields and values specified
|
||||||
|
|
|
@ -247,7 +247,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 {
|
||||||
clearIndex();
|
clearIndex();
|
||||||
// big freaking kludge since the response is currently not well formed.
|
// big freaking kludge since the response is currently not well formed.
|
||||||
String res = h.update("<add><doc><field name=\"id\">1</field></doc><doc><field name=\"id\">2</field></doc></add>");
|
String res = h.update("<add><doc><field name=\"id\">1</field></doc><doc><field name=\"id\">2</field></doc></add>");
|
||||||
assertEquals("<result status=\"0\"></result>", res);
|
// assertEquals("<result status=\"0\"></result>", res);
|
||||||
assertU("<commit/>");
|
assertU("<commit/>");
|
||||||
assertQ(req("id:[0 TO 99]")
|
assertQ(req("id:[0 TO 99]")
|
||||||
,"//*[@numFound='2']"
|
,"//*[@numFound='2']"
|
||||||
|
@ -263,7 +263,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 {
|
||||||
"<field name=\"text\">hello</field></doc>" +
|
"<field name=\"text\">hello</field></doc>" +
|
||||||
"</add>");
|
"</add>");
|
||||||
|
|
||||||
assertEquals("<result status=\"0\"></result>", res);
|
// assertEquals("<result status=\"0\"></result>", res);
|
||||||
assertU("<commit/>");
|
assertU("<commit/>");
|
||||||
assertQ(req("text:hello")
|
assertQ(req("text:hello")
|
||||||
,"//*[@numFound='2']"
|
,"//*[@numFound='2']"
|
||||||
|
@ -282,7 +282,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 {
|
||||||
"<field boost=\"2.0\" name=\"text\">hello</field></doc>" +
|
"<field boost=\"2.0\" name=\"text\">hello</field></doc>" +
|
||||||
"</add>");
|
"</add>");
|
||||||
|
|
||||||
assertEquals("<result status=\"0\"></result>", res);
|
// assertEquals("<result status=\"0\"></result>", res);
|
||||||
assertU("<commit/>");
|
assertU("<commit/>");
|
||||||
assertQ(req("text:hello"),
|
assertQ(req("text:hello"),
|
||||||
"//*[@numFound='2']"
|
"//*[@numFound='2']"
|
||||||
|
|
|
@ -60,10 +60,12 @@ public class DirectUpdateHandlerTest extends SolrTestCaseJ4 {
|
||||||
assertU(adoc("id","1"));
|
assertU(adoc("id","1"));
|
||||||
|
|
||||||
// More than one id should fail
|
// More than one id should fail
|
||||||
assertFailedU(adoc("id","2", "id","3", "text","ignore_exception"));
|
assertFailedU(adoc("id","2", "id","ignore_exception", "text","foo"));
|
||||||
|
|
||||||
// No id should fail
|
// No id should fail
|
||||||
assertFailedU(adoc("text","ignore_exception"));
|
ignoreException("id");
|
||||||
|
assertFailedU(adoc("text","foo"));
|
||||||
|
resetExceptionIgnores();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,12 @@
|
||||||
<requestHandler name="standard" class="solr.StandardRequestHandler"/>
|
<requestHandler name="standard" class="solr.StandardRequestHandler"/>
|
||||||
|
|
||||||
<updateHandler class="solr.DirectUpdateHandler2"/>
|
<updateHandler class="solr.DirectUpdateHandler2"/>
|
||||||
|
<requestHandler name="/update" class="solr.XmlUpdateRequestHandler" />
|
||||||
|
|
||||||
<!-- test ValueSourceParser plugins -->
|
<!-- test ValueSourceParser plugins -->
|
||||||
<valueSourceParser name="nvl" class="org.apache.solr.search.function.NvlValueSourceParser">
|
<valueSourceParser name="nvl" class="org.apache.solr.search.function.NvlValueSourceParser">
|
||||||
<float name="nvlFloatValue">0.0</float>
|
<float name="nvlFloatValue">0.0</float>
|
||||||
</valueSourceParser>
|
</valueSourceParser>
|
||||||
|
|
||||||
|
|
||||||
</config>
|
</config>
|
||||||
|
|
Loading…
Reference in New Issue