Search in sources :

Example 6 with NamedList

use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.

the class DistributedVersionInfoTest method assertDocExists.

/**
   * Query the real-time get handler for a specific doc by ID to verify it
   * exists in the provided server, using distrib=false so it doesn't route to another replica.
   */
@SuppressWarnings("rawtypes")
protected Long assertDocExists(HttpSolrClient solr, String coll, String docId, Long expVers) throws Exception {
    QueryRequest qr = new QueryRequest(params("qt", "/get", "id", docId, "distrib", "false", "fl", "id,_version_"));
    NamedList rsp = solr.request(qr);
    SolrDocument doc = (SolrDocument) rsp.get("doc");
    String match = JSONTestUtil.matchObj("/id", doc, docId);
    assertTrue("Doc with id=" + docId + " not found in " + solr.getBaseURL() + " due to: " + match + "; rsp=" + rsp, match == null);
    Long vers = (Long) doc.getFirstValue("_version_");
    assertNotNull(vers);
    if (expVers != null)
        assertEquals("expected version of doc " + docId + " to be " + expVers, expVers, vers);
    return vers;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList)

Example 7 with NamedList

use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.

the class HttpPartitionTest method assertDocNotExists.

protected void assertDocNotExists(HttpSolrClient solr, String coll, String docId) throws Exception {
    NamedList rsp = realTimeGetDocId(solr, docId);
    String match = JSONTestUtil.matchObj("/id", rsp.get("doc"), new Integer(docId));
    assertTrue("Doc with id=" + docId + " is found in " + solr.getBaseURL() + " due to: " + match + "; rsp=" + rsp, match != null);
}
Also used : NamedList(org.apache.solr.common.util.NamedList)

Example 8 with NamedList

use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.

the class CdcrReplicationDistributedZkTest method testTargetCollectionNotAvailable.

@Test
@ShardsFixed(num = 4)
public void testTargetCollectionNotAvailable() throws Exception {
    // send start action to first shard
    NamedList rsp = invokeCdcrAction(shardToLeaderJetty.get(SOURCE_COLLECTION).get(SHARD1), CdcrParams.CdcrAction.START);
    NamedList status = (NamedList) rsp.get(CdcrParams.CdcrAction.STATUS.toLower());
    assertEquals(CdcrParams.ProcessState.STARTED.toLower(), status.get(CdcrParams.ProcessState.getParam()));
    // check status
    this.assertState(SOURCE_COLLECTION, CdcrParams.ProcessState.STARTED, CdcrParams.BufferState.ENABLED);
    this.waitForBootstrapToComplete(TARGET_COLLECTION, SHARD2);
    // sleep for a bit to ensure that replicator threads are started
    Thread.sleep(3000);
    // Kill all the servers of the target
    this.deleteCollection(TARGET_COLLECTION);
    // Index a few documents to trigger the replication
    index(SOURCE_COLLECTION, getDoc(id, "a"));
    index(SOURCE_COLLECTION, getDoc(id, "b"));
    index(SOURCE_COLLECTION, getDoc(id, "c"));
    index(SOURCE_COLLECTION, getDoc(id, "d"));
    index(SOURCE_COLLECTION, getDoc(id, "e"));
    index(SOURCE_COLLECTION, getDoc(id, "f"));
    assertNumDocs(6, SOURCE_COLLECTION);
    // we need to wait until the replicator thread is triggered
    // timeout after 15 seconds
    int cnt = 15;
    AssertionError lastAssertionError = null;
    while (cnt > 0) {
        try {
            rsp = invokeCdcrAction(shardToLeaderJetty.get(SOURCE_COLLECTION).get(SHARD2), CdcrParams.CdcrAction.ERRORS);
            NamedList collections = (NamedList) ((NamedList) rsp.get(CdcrParams.ERRORS)).getVal(0);
            NamedList errors = (NamedList) collections.get(TARGET_COLLECTION);
            assertTrue(0 < (Long) errors.get(CdcrParams.CONSECUTIVE_ERRORS));
            NamedList lastErrors = (NamedList) errors.get(CdcrParams.LAST);
            assertNotNull(lastErrors);
            assertTrue(0 < lastErrors.size());
            return;
        } catch (AssertionError e) {
            lastAssertionError = e;
            cnt--;
            Thread.sleep(1000);
        }
    }
    throw new AssertionError("Timeout while trying to assert replication errors", lastAssertionError);
}
Also used : NamedList(org.apache.solr.common.util.NamedList) Test(org.junit.Test)

Example 9 with NamedList

use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.

the class CollectionsAPISolrJTest method testCreateAndDeleteCollection.

@Test
public void testCreateAndDeleteCollection() throws Exception {
    String collectionName = "solrj_test";
    CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).setStateFormat(1).process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
    assertEquals(4, coresStatus.size());
    for (int i = 0; i < 4; i++) {
        NamedList<Integer> status = coresStatus.get(Assign.buildCoreName(collectionName, "shard" + (i / 2 + 1), Replica.Type.NRT, (i % 2 + 1)));
        assertEquals(0, (int) status.get("status"));
        assertTrue(status.get("QTime") > 0);
    }
    response = CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    Map<String, NamedList<Integer>> nodesStatus = response.getCollectionNodesStatus();
    assertEquals(4, nodesStatus.size());
    waitForState("Expected " + collectionName + " to disappear from cluster state", collectionName, (n, c) -> c == null);
    // Test Creating a collection with new stateformat.
    collectionName = "solrj_newstateformat";
    response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).setStateFormat(2).process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    waitForState("Expected " + collectionName + " to appear in cluster state", collectionName, (n, c) -> c != null);
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) NamedList(org.apache.solr.common.util.NamedList) Test(org.junit.Test)

Example 10 with NamedList

use of org.apache.solr.common.util.NamedList in project lucene-solr by apache.

the class TestCollectionAPI method clusterStatusNoCollection.

private void clusterStatusNoCollection() throws Exception {
    try (CloudSolrClient client = createCloudClient(null)) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        NamedList<Object> rsp = client.request(request);
        NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
        assertNotNull("Cluster state should not be null", cluster);
        NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
        assertNotNull("Collections should not be null in cluster state", collections);
        assertNotNull(collections.get(COLLECTION_NAME1));
        assertEquals(4, collections.size());
        List<String> liveNodes = (List<String>) cluster.get("live_nodes");
        assertNotNull("Live nodes should not be null", liveNodes);
        assertFalse(liveNodes.isEmpty());
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

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