use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class SolrRequestParserTest method testAddHttpRequestToContext.
@Test
public void testAddHttpRequestToContext() throws Exception {
HttpServletRequest request = getMock("/solr/select", null, -1);
when(request.getMethod()).thenReturn("GET");
when(request.getQueryString()).thenReturn("q=title:solr");
Map<String, String> headers = new HashMap<>();
headers.put("X-Forwarded-For", "10.0.0.1");
when(request.getHeaderNames()).thenReturn(new Vector<>(headers.keySet()).elements());
for (Map.Entry<String, String> entry : headers.entrySet()) {
Vector<String> v = new Vector<>();
v.add(entry.getValue());
when(request.getHeaders(entry.getKey())).thenReturn(v.elements());
}
SolrRequestParsers parsers = new SolrRequestParsers(h.getCore().getSolrConfig());
assertFalse(parsers.isAddRequestHeadersToContext());
SolrQueryRequest solrReq = parsers.parse(h.getCore(), "/select", request);
assertFalse(solrReq.getContext().containsKey("httpRequest"));
parsers.setAddRequestHeadersToContext(true);
solrReq = parsers.parse(h.getCore(), "/select", request);
assertEquals(request, solrReq.getContext().get("httpRequest"));
assertEquals("10.0.0.1", ((HttpServletRequest) solrReq.getContext().get("httpRequest")).getHeaders("X-Forwarded-For").nextElement());
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class IgnoreCommitOptimizeUpdateProcessorFactoryTest method processCommit.
SolrQueryResponse processCommit(final String chain, boolean optimize, Boolean commitEndPoint) throws IOException {
SolrCore core = h.getCore();
UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
assertNotNull("No Chain named: " + chain, pc);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
if (commitEndPoint != null) {
((ModifiableSolrParams) req.getParams()).set(DistributedUpdateProcessor.COMMIT_END_POINT, commitEndPoint.booleanValue());
}
try {
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
CommitUpdateCommand cmd = new CommitUpdateCommand(req, false);
cmd.optimize = optimize;
UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
processor.processCommit(cmd);
} finally {
SolrRequestInfo.clearRequestInfo();
req.close();
}
return rsp;
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class SolrTestCaseHS method clearQueryCache.
/***
public static void clearNCache() {
SolrQueryRequest req = req();
req.getSearcher().getnCache().clear(); // OFF-HEAP
req.close();
}***/
public static void clearQueryCache() {
SolrQueryRequest req = req();
req.getSearcher();
req.close();
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class DebugComponentTest method ensureRidPresent.
@SuppressWarnings("unchecked")
private void ensureRidPresent(ResponseBuilder rb, String expectedRid) {
SolrQueryRequest req = rb.req;
SolrQueryResponse resp = rb.rsp;
//a generated request ID should be added to the request
String rid = req.getParams().get(CommonParams.REQUEST_ID);
if (expectedRid == null) {
assertTrue(rid + " Doesn't match expected pattern.", Pattern.matches(".*-collection1-[0-9]*-[0-9]+", rid));
} else {
assertEquals("Expecting " + expectedRid + " but found " + rid, expectedRid, rid);
}
//The request ID is added to the debug/track section
assertEquals(rid, ((NamedList<Object>) rb.getDebugInfo().get("track")).get(CommonParams.REQUEST_ID));
//RID must be added to the toLog, so that it's included in the main request log
assertEquals(rid, resp.getToLog().get(CommonParams.REQUEST_ID));
}
use of org.apache.solr.request.SolrQueryRequest in project lucene-solr by apache.
the class LukeRequestHandlerTest method testFlParam.
@Test
public void testFlParam() {
SolrQueryRequest req = req("qt", "/admin/luke", "fl", "solr_t solr_s", "show", "all");
try {
// First, determine that the two fields ARE there
String response = h.query(req);
assertNull(TestHarness.validateXPath(response, getFieldXPathPrefix("solr_t") + "[@name='index']", getFieldXPathPrefix("solr_s") + "[@name='index']"));
// Now test that the other fields are NOT there
for (String f : Arrays.asList("solr_ti", "solr_td", "solr_dt", "solr_b")) {
assertNotNull(TestHarness.validateXPath(response, getFieldXPathPrefix(f) + "[@name='index']"));
}
// Insure * works
req = req("qt", "/admin/luke", "fl", "*");
response = h.query(req);
for (String f : Arrays.asList("solr_t", "solr_s", "solr_ti", "solr_td", "solr_dt", "solr_b")) {
if (h.getCore().getLatestSchema().getField(f).getType().isPointField())
continue;
assertNull(TestHarness.validateXPath(response, getFieldXPathPrefix(f) + "[@name='index']"));
}
} catch (Exception e) {
fail("Caught unexpected exception " + e.getMessage());
}
}
Aggregations