Search in sources :

Example 16 with SolrClient

use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.

the class TestInPlaceUpdatesDistrib method updatingDVsInAVeryOldSegment.

/**
   * Ingest many documents, keep committing. Then update a document from a very old segment.
   */
private void updatingDVsInAVeryOldSegment() throws Exception {
    clearIndex();
    commit();
    String id = String.valueOf(Integer.MAX_VALUE);
    index("id", id, "inplace_updatable_float", "1", "title_s", "newtitle");
    // create 10 more segments
    for (int i = 0; i < 10; i++) {
        buildRandomIndex(101.0F, Collections.emptyList());
    }
    index("id", id, "inplace_updatable_float", map("inc", "1"));
    for (SolrClient client : new SolrClient[] { LEADER, NONLEADERS.get(0), NONLEADERS.get(1) }) {
        assertEquals("newtitle", client.getById(id).get("title_s"));
        assertEquals(2.0f, client.getById(id).get("inplace_updatable_float"));
    }
    commit();
    for (SolrClient client : new SolrClient[] { LEADER, NONLEADERS.get(0), NONLEADERS.get(1) }) {
        assertEquals("newtitle", client.getById(id).get("title_s"));
        assertEquals(2.0f, client.getById(id).get("inplace_updatable_float"));
    }
    log.info("updatingDVsInAVeryOldSegment: This test passed fine...");
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient)

Example 17 with SolrClient

use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.

the class TestInPlaceUpdatesDistrib method clearIndex.

@Override
public void clearIndex() {
    super.clearIndex();
    try {
        for (SolrClient client : new SolrClient[] { LEADER, NONLEADERS.get(0), NONLEADERS.get(1) }) {
            if (client != null) {
                client.request(simulatedDeleteRequest("*:*", -Long.MAX_VALUE));
                client.commit();
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrServerException(org.apache.solr.client.solrj.SolrServerException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 18 with SolrClient

use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.

the class NoOpResponseParserTest method doBefore.

@Before
public void doBefore() throws IOException, SolrServerException {
    //add document and commit, and ensure it's there
    SolrClient client = getSolrClient();
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "1234");
    client.add(doc);
    client.commit();
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Before(org.junit.Before)

Example 19 with SolrClient

use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.

the class BaseDistributedSearchTestCase method query.

/**
   * Returns the QueryResponse from {@link #queryServer}  
   */
protected QueryResponse query(boolean setDistribParams, SolrParams p) throws Exception {
    final ModifiableSolrParams params = new ModifiableSolrParams(p);
    // TODO: look into why passing true causes fails
    params.set("distrib", "false");
    final QueryResponse controlRsp = controlClient.query(params);
    validateControlData(controlRsp);
    params.remove("distrib");
    if (setDistribParams)
        setDistributedParams(params);
    QueryResponse rsp = queryServer(params);
    compareResponses(rsp, controlRsp);
    if (stress > 0) {
        log.info("starting stress...");
        Thread[] threads = new Thread[nThreads];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread() {

                @Override
                public void run() {
                    for (int j = 0; j < stress; j++) {
                        int which = r.nextInt(clients.size());
                        SolrClient client = clients.get(which);
                        try {
                            QueryResponse rsp = client.query(new ModifiableSolrParams(params));
                            if (verifyStress) {
                                compareResponses(rsp, controlRsp);
                            }
                        } catch (SolrServerException | IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            };
            threads[i].start();
        }
        for (Thread thread : threads) {
            thread.join();
        }
    }
    return rsp;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 20 with SolrClient

use of org.apache.solr.client.solrj.SolrClient in project lucene-solr by apache.

the class TestRandomFlRTGCloud method addRandomDocument.

/**
   * Adds one randomly generated document with the specified docId, asserting success, and returns 
   * the document added
   */
private SolrInputDocument addRandomDocument(final int docId) throws IOException, SolrServerException {
    final SolrClient client = getRandClient(random());
    final SolrInputDocument doc = sdoc("id", "" + docId, "aaa_i", random().nextInt(), "bbb_i", random().nextInt(), //
    "ccc_s", TestUtil.randomSimpleString(random()), "ddd_s", TestUtil.randomSimpleString(random()), "eee_s", TestUtil.randomSimpleString(random()), "fff_s", TestUtil.randomSimpleString(random()), "ggg_s", TestUtil.randomSimpleString(random()), "hhh_s", TestUtil.randomSimpleString(random()), //
    "geo_1_srpt", GeoTransformerValidator.getValueForIndexing(random()), "geo_2_srpt", GeoTransformerValidator.getValueForIndexing(random()), // for testing subqueries
    "next_2_ids_ss", String.valueOf(docId + 1), "next_2_ids_ss", String.valueOf(docId + 2), // for testing prefix globbing
    "axx_i", random().nextInt(), "ayy_i", random().nextInt(), "azz_s", TestUtil.randomSimpleString(random()));
    log.info("ADD: {} = {}", docId, doc);
    assertEquals(0, client.add(doc).getStatus());
    return doc;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient)

Aggregations

SolrClient (org.apache.solr.client.solrj.SolrClient)170 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)104 Test (org.junit.Test)67 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)37 ArrayList (java.util.ArrayList)35 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)31 SolrQuery (org.apache.solr.client.solrj.SolrQuery)28 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)28 SolrInputDocument (org.apache.solr.common.SolrInputDocument)28 IOException (java.io.IOException)24 NamedList (org.apache.solr.common.util.NamedList)22 SolrException (org.apache.solr.common.SolrException)18 SolrServerException (org.apache.solr.client.solrj.SolrServerException)17 Map (java.util.Map)16 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)16 Replica (org.apache.solr.common.cloud.Replica)16 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)15 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)14 SolrDocument (org.apache.solr.common.SolrDocument)14 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)13