use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class StatsReloadRaceTest method requestMetrics.
private void requestMetrics(boolean softFail) throws Exception {
SolrQueryResponse rsp = new SolrQueryResponse();
String registry = "solr.core." + h.coreName;
String key = "SEARCHER.searcher.indexVersion";
boolean found = false;
int count = 10;
while (!found && count-- > 0) {
h.getCoreContainer().getRequestHandler("/admin/metrics").handleRequest(req("prefix", "SEARCHER", "registry", registry, "compact", "true"), rsp);
NamedList values = rsp.getValues();
// this is not guaranteed to exist right away after core reload - there's a
// small window between core load and before searcher metrics are registered
// so we may have to check a few times, and then fail softly if reload is not complete yet
NamedList metrics = (NamedList) values.get("metrics");
if (metrics == null) {
if (softFail) {
return;
} else {
fail("missing 'metrics' element in handler's output: " + values.asMap(5).toString());
}
}
metrics = (NamedList) metrics.get(registry);
if (metrics.get(key) != null) {
found = true;
assertTrue(metrics.get(key) instanceof Long);
break;
} else {
Thread.sleep(500);
}
}
if (softFail && !found) {
return;
}
assertTrue("Key " + key + " not found in registry " + registry, found);
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class DistributedDebugComponentTest method testSimpleSearch.
@Test
@SuppressWarnings("unchecked")
public void testSimpleSearch() throws Exception {
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.set("debug", "track");
query.set("distrib", "true");
query.setFields("id", "text");
query.set("shards", shard1 + "," + shard2);
QueryResponse response = collection1.query(query);
NamedList<Object> track = (NamedList<Object>) response.getDebugMap().get("track");
assertNotNull(track);
assertNotNull(track.get("rid"));
assertNotNull(track.get("EXECUTE_QUERY"));
assertNotNull(((NamedList<Object>) track.get("EXECUTE_QUERY")).get(shard1));
assertNotNull(((NamedList<Object>) track.get("EXECUTE_QUERY")).get(shard2));
assertNotNull(((NamedList<Object>) track.get("GET_FIELDS")).get(shard1));
assertNotNull(((NamedList<Object>) track.get("GET_FIELDS")).get(shard2));
assertElementsPresent((NamedList<String>) ((NamedList<Object>) track.get("EXECUTE_QUERY")).get(shard1), "QTime", "ElapsedTime", "RequestPurpose", "NumFound", "Response");
assertElementsPresent((NamedList<String>) ((NamedList<Object>) track.get("EXECUTE_QUERY")).get(shard2), "QTime", "ElapsedTime", "RequestPurpose", "NumFound", "Response");
assertElementsPresent((NamedList<String>) ((NamedList<Object>) track.get("GET_FIELDS")).get(shard1), "QTime", "ElapsedTime", "RequestPurpose", "NumFound", "Response");
assertElementsPresent((NamedList<String>) ((NamedList<Object>) track.get("GET_FIELDS")).get(shard2), "QTime", "ElapsedTime", "RequestPurpose", "NumFound", "Response");
query.add("omitHeader", "true");
response = collection1.query(query);
assertNull("QTime is not included in the response when omitHeader is set to true", ((NamedList<Object>) response.getDebugMap().get("track")).findRecursive("EXECUTE_QUERY", shard1, "QTime"));
assertNull("QTime is not included in the response when omitHeader is set to true", ((NamedList<Object>) response.getDebugMap().get("track")).findRecursive("GET_FIELDS", shard2, "QTime"));
query.setQuery("id:1");
response = collection1.query(query);
track = (NamedList<Object>) response.getDebugMap().get("track");
assertNotNull(((NamedList<Object>) track.get("EXECUTE_QUERY")).get(shard1));
assertNotNull(((NamedList<Object>) track.get("EXECUTE_QUERY")).get(shard2));
assertNotNull(((NamedList<Object>) track.get("GET_FIELDS")).get(shard1));
// This test is invalid, as GET_FIELDS should not be executed in shard 2
assertNull(((NamedList<Object>) track.get("GET_FIELDS")).get(shard2));
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class PropertiesRequestHandlerTest method readProperties.
private NamedList<NamedList<NamedList<Object>>> readProperties() throws Exception {
String xml = h.query(req(CommonParams.QT, "/admin/properties", CommonParams.WT, "xml"));
XMLResponseParser parser = new XMLResponseParser();
return (NamedList<NamedList<NamedList<Object>>>) parser.processResponse(new StringReader(xml)).get("system.properties");
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class ShowFileRequestHandlerTest method testGetRawFile.
public void testGetRawFile() throws SolrServerException, IOException {
SolrClient client = getSolrClient();
//assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4
QueryRequest request = new QueryRequest(params("file", "managed-schema"));
request.setPath("/admin/file");
final AtomicBoolean readFile = new AtomicBoolean();
request.setResponseParser(new ResponseParser() {
@Override
public String getWriterType() {
//unfortunately this gets put onto params wt=mock but it apparently has no effect
return "mock";
}
@Override
public NamedList<Object> processResponse(InputStream body, String encoding) {
try {
if (body.read() >= 0)
readFile.set(true);
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
@Override
public NamedList<Object> processResponse(Reader reader) {
//TODO
throw new UnsupportedOperationException("TODO unimplemented");
}
});
//runs request
client.request(request);
//request.process(client); but we don't have a NamedList response
assertTrue(readFile.get());
}
use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.
the class V2ApiIntegrationTest method testSetPropertyValidationOfCluster.
@Test
public void testSetPropertyValidationOfCluster() throws IOException, SolrServerException {
NamedList resp = cluster.getSolrClient().request(new V2Request.Builder("/cluster").withMethod(SolrRequest.METHOD.POST).withPayload("{set-property: {name: autoAddReplicas, val:false}}").build());
assertTrue(resp.toString().contains("status=0"));
resp = cluster.getSolrClient().request(new V2Request.Builder("/cluster").withMethod(SolrRequest.METHOD.POST).withPayload("{set-property: {name: autoAddReplicas, val:null}}").build());
assertTrue(resp.toString().contains("status=0"));
}
Aggregations