Search in sources :

Example 16 with NamedList

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);
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) NamedList(org.apache.solr.common.util.NamedList)

Example 17 with NamedList

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));
}
Also used : NamedList(org.apache.solr.common.util.NamedList) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 18 with NamedList

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");
}
Also used : NamedList(org.apache.solr.common.util.NamedList) StringReader(java.io.StringReader) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser)

Example 19 with NamedList

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) ResponseParser(org.apache.solr.client.solrj.ResponseParser) SolrClient(org.apache.solr.client.solrj.SolrClient) InputStream(java.io.InputStream) NamedList(org.apache.solr.common.util.NamedList) Reader(java.io.Reader) IOException(java.io.IOException)

Example 20 with NamedList

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"));
}
Also used : NamedList(org.apache.solr.common.util.NamedList) V2Request(org.apache.solr.client.solrj.request.V2Request) Test(org.junit.Test)

Aggregations

NamedList (org.apache.solr.common.util.NamedList)438 Test (org.junit.Test)125 ArrayList (java.util.ArrayList)110 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)83 Map (java.util.Map)82 SolrException (org.apache.solr.common.SolrException)80 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)78 List (java.util.List)75 HashMap (java.util.HashMap)64 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)55 IOException (java.io.IOException)53 SolrDocumentList (org.apache.solr.common.SolrDocumentList)45 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)35 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)35 SolrParams (org.apache.solr.common.params.SolrParams)31 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)31 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)30 SolrCore (org.apache.solr.core.SolrCore)30 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)27 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)27