/** * Reloads the first core listed in the response to the core admin handler STATUS command */ @Override public void reload() throws Exception { String coreName = (String)evaluateXPath (adminQuery("/admin/cores?wt=xml&action=STATUS"), "//lst[@name='status']/lst[1]/str[@name='name']", XPathConstants.STRING); String xml = checkAdminResponseStatus("/admin/cores?wt=xml&action=RELOAD&core=" + coreName, "0"); if (null != xml) { throw new RuntimeException("RELOAD failed:\n" + xml); } }
protected void closeRestTestHarnesses() throws IOException { for (RestTestHarness h : restTestHarnesses) { h.close(); } }
public String adminQuery(String request) throws Exception { return getResponse(new HttpGet(getAdminURL() + request)); }
/** * Processes a DELETE request using a URL path (with no context path) + optional query params, * e.g. "/schema/analysis/protwords/english", and returns the response content. * * @param request the URL path and optional query params * @return The response to the DELETE request */ public String delete(String request) throws IOException { HttpDelete httpDelete = new HttpDelete(getBaseURL() + request); return getResponse(httpDelete); }
public String checkAdminResponseStatus(String xml, String code) throws Exception { try { String response = adminQuery(xml); String valid = validateXPath(response, "//int[@name='status']="+code ); return (null == valid) ? null : response; } catch (XPathExpressionException e) { throw new RuntimeException("?!? static xpath has bug?", e); } } /**
protected void setupRestTestHarnesses() { for (final SolrClient client : clients) { RestTestHarness harness = new RestTestHarness(() -> ((HttpSolrClient) client).getBaseURL()); restTestHarnesses.add(harness); } }
public String getAdminURL() { return getBaseURL().replace("/collection1", ""); }
boolean failed = true; try { response = restTestHarness.post(request, content); failed = false; } finally {
boolean failed = true; try { response = restTestHarness.delete(request); failed = false; } finally {
/** * Processes a "query" using a URL path (with no context path) + optional query params, * e.g. "/schema/fields?indent=off" * * @param request the URL path and optional query params * @return The response to the query * @exception Exception any exception in the response. */ public String query(String request) throws Exception { return getResponse(new HttpGet(getBaseURL() + request)); }
public static void createJettyAndHarness (String solrHome, String configFile, String schemaFile, String context, boolean stopAtShutdown, SortedMap<ServletHolder,String> extraServlets) throws Exception { createJetty(solrHome, configFile, schemaFile, context, stopAtShutdown, extraServlets); restTestHarness = new RestTestHarness(() -> jetty.getBaseUrl().toString() + "/" + DEFAULT_TEST_CORENAME); }
/** * Processes a PUT request using a URL path (with no context path) + optional query params, * e.g. "/schema/fields/newfield", PUTs the given content, and returns the response content. * * @param request The URL path and optional query params * @param content The content to include with the PUT request * @return The response to the PUT request */ public String put(String request, String content) throws IOException { HttpPut httpPut = new HttpPut(getBaseURL() + request); httpPut.setEntity(new StringEntity(content, ContentType.create( "application/json", StandardCharsets.UTF_8))); return getResponse(httpPut); }
@AfterClass public static void cleanUpHarness() throws IOException { if (restTestHarness != null) { restTestHarness.close(); } restTestHarness = null; }
/** * Processes a POST request using a URL path (with no context path) + optional query params, * e.g. "/schema/fields/newfield", PUTs the given content, and returns the response content. * * @param request The URL path and optional query params * @param content The content to include with the POST request * @return The response to the POST request */ public String post(String request, String content) throws IOException { HttpPost httpPost = new HttpPost(getBaseURL() + request); httpPost.setEntity(new StringEntity(content, ContentType.create( "application/json", StandardCharsets.UTF_8))); return getResponse(httpPost); }