Search in sources :

Example 56 with SolrDocumentList

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

the class DistribCursorPagingTest method assertFullWalkNoDups.

/**
   * <p>
   * Given a set of params, executes a cursor query using {@link CursorMarkParams#CURSOR_MARK_START} 
   * and then continuously walks the results using {@link CursorMarkParams#CURSOR_MARK_START} as long 
   * as a non-0 number of docs ar returned.  This method records the the set of all id's
   * (must be positive ints) encountered and throws an assertion failure if any id is 
   * encountered more then once, or if the set grows above maxSize
   * </p>
   *
   * <p>
   * Note that this method explicitly uses the "cloudClient" for executing the queries, 
   * instead of relying on the test infrastructure to execute the queries redundently
   * against both the cloud client as well as a control client.  This is because term stat 
   * differences in a sharded setup can result in different scores for documents compared 
   * to the control index -- which can affect the sorting in some cases and cause false 
   * negatives in the response comparisons (even if we don't include "score" in the "fl")
   * </p>
   */
public SentinelIntSet assertFullWalkNoDups(int maxSize, SolrParams params) throws Exception {
    SentinelIntSet ids = new SentinelIntSet(maxSize, -1);
    String cursorMark = CURSOR_MARK_START;
    int docsOnThisPage = Integer.MAX_VALUE;
    while (0 < docsOnThisPage) {
        final SolrParams p = p(params, CURSOR_MARK_PARAM, cursorMark);
        QueryResponse rsp = cloudClient.query(p);
        String nextCursorMark = assertHashNextCursorMark(rsp);
        SolrDocumentList docs = extractDocList(rsp);
        docsOnThisPage = docs.size();
        if (null != params.getInt(CommonParams.ROWS)) {
            int rows = params.getInt(CommonParams.ROWS);
            assertTrue("Too many docs on this page: " + rows + " < " + docsOnThisPage, docsOnThisPage <= rows);
        }
        if (0 == docsOnThisPage) {
            assertEquals("no more docs, but " + CURSOR_MARK_NEXT + " isn't same", cursorMark, nextCursorMark);
        }
        for (SolrDocument doc : docs) {
            int id = ((Integer) doc.get("id")).intValue();
            if (ids.exists(id)) {
                String msg = "(" + p + ") walk already seen: " + id;
                try {
                    queryAndCompareShards(params("distrib", "false", "q", "id:" + id));
                } catch (AssertionError ae) {
                    throw new AssertionError(msg + ", found shard inconsistency that would explain it...", ae);
                }
                rsp = cloudClient.query(params("q", "id:" + id));
                throw new AssertionError(msg + ", don't know why; q=id:" + id + " gives: " + rsp.toString());
            }
            ids.put(id);
            assertFalse("id set bigger then max allowed (" + maxSize + "): " + ids.size(), maxSize < ids.size());
        }
        cursorMark = nextCursorMark;
    }
    return ids;
}
Also used : SentinelIntSet(org.apache.lucene.util.SentinelIntSet) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrParams(org.apache.solr.common.params.SolrParams) SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Example 57 with SolrDocumentList

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

the class DistribCursorPagingTest method assertDocList.

/**
   * Given a QueryResponse returned by SolrServer.query, asserts that the
   * "id" of the list of documents returned matches the expected list
   * @see org.apache.solr.client.solrj.SolrClient#query
   */
private void assertDocList(QueryResponse rsp, Object... ids) {
    SolrDocumentList docs = extractDocList(rsp);
    assertEquals("Wrong number of docs in response", ids.length, docs.size());
    int i = 0;
    for (Object id : ids) {
        assertEquals(rsp.toString(), id, docs.get(i).get("id"));
        i++;
    }
}
Also used : SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Example 58 with SolrDocumentList

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

the class DistribCursorPagingTest method extractDocList.

private SolrDocumentList extractDocList(QueryResponse rsp) {
    SolrDocumentList docs = rsp.getResults();
    assertNotNull("docList is null", docs);
    return docs;
}
Also used : SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Example 59 with SolrDocumentList

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

the class TestCloudPseudoReturnFields method testFilterAndOneRealFieldRTG.

public void testFilterAndOneRealFieldRTG() throws Exception {
    SolrParams params = params("fl", "id,val_i", "fq", "{!field f='subject' v=$my_var}", "my_var", "uncommitted");
    SolrDocumentList docs = getRandClient(random()).getById(Arrays.asList("42", "99"), params);
    final String msg = params + " => " + docs;
    assertEquals(msg, 1, docs.size());
    assertEquals(msg, 1, docs.getNumFound());
    SolrDocument doc = docs.get(0);
    assertEquals(msg, 2, doc.size());
    assertEquals(msg, "99", doc.getFieldValue("id"));
    assertEquals(msg, 1, doc.getFieldValue("val_i"));
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Example 60 with SolrDocumentList

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

the class TestCloudInspectUtil method testCheckIfDiffIsLegal.

@Test
public void testCheckIfDiffIsLegal() throws Exception {
    Set<String> addFails = null;
    Set<String> deleteFails = null;
    SolrDocumentList a = getDocList("2", "3");
    SolrDocumentList b = getDocList("1");
    boolean legal = CloudInspectUtil.checkIfDiffIsLegal(a, b, "control", "cloud", addFails, deleteFails);
    assertFalse(legal);
    // ################################
    addFails = new HashSet<String>();
    deleteFails = new HashSet<String>();
    a = getDocList("2", "3", "4");
    b = getDocList("2", "3");
    addFails.add("4");
    legal = CloudInspectUtil.checkIfDiffIsLegal(a, b, "control", "cloud", addFails, deleteFails);
    assertTrue(legal);
    // ################################
    addFails = new HashSet<String>();
    deleteFails = new HashSet<String>();
    a = getDocList("2", "3", "4");
    b = getDocList("2", "3", "5");
    addFails.add("4");
    deleteFails.add("5");
    legal = CloudInspectUtil.checkIfDiffIsLegal(a, b, "control", "cloud", addFails, deleteFails);
    assertTrue(legal);
    // ################################
    addFails = new HashSet<String>();
    deleteFails = new HashSet<String>();
    a = getDocList("2", "3", "4");
    b = getDocList("2", "3", "5");
    addFails.add("4");
    deleteFails.add("6");
    legal = CloudInspectUtil.checkIfDiffIsLegal(a, b, "control", "cloud", addFails, deleteFails);
    assertFalse(legal);
    // ################################
    addFails = new HashSet<String>();
    deleteFails = new HashSet<String>();
    a = getDocList("2", "3", "4");
    b = getDocList("2", "3", "4");
    try {
        legal = CloudInspectUtil.checkIfDiffIsLegal(a, b, "control", "cloud", addFails, deleteFails);
        fail("Expected exception because lists have no diff");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : SolrDocumentList(org.apache.solr.common.SolrDocumentList) Test(org.junit.Test)

Aggregations

SolrDocumentList (org.apache.solr.common.SolrDocumentList)161 SolrDocument (org.apache.solr.common.SolrDocument)89 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)52 Test (org.junit.Test)52 NamedList (org.apache.solr.common.util.NamedList)36 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)33 SolrQuery (org.apache.solr.client.solrj.SolrQuery)32 ArrayList (java.util.ArrayList)29 SolrParams (org.apache.solr.common.params.SolrParams)28 SolrServerException (org.apache.solr.client.solrj.SolrServerException)20 SolrInputDocument (org.apache.solr.common.SolrInputDocument)18 IOException (java.io.IOException)15 Map (java.util.Map)14 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)14 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)13 HashMap (java.util.HashMap)12 List (java.util.List)10 Date (java.util.Date)8 LinkedHashMap (java.util.LinkedHashMap)8 SolrClient (org.apache.solr.client.solrj.SolrClient)8