Search in sources :

Example 26 with UpdateRequest

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

the class TestTlogReplica method testBasicLeaderElection.

public void testBasicLeaderElection() throws Exception {
    createAndWaitForCollection(1, 0, 2, 0);
    CloudSolrClient cloudClient = cluster.getSolrClient();
    new UpdateRequest().deleteByQuery("*:*").commit(cluster.getSolrClient(), collectionName);
    new UpdateRequest().add(sdoc("id", "1")).add(sdoc("id", "2")).process(cloudClient, collectionName);
    JettySolrRunner oldLeaderJetty = getSolrRunner(true).get(0);
    ChaosMonkey.kill(oldLeaderJetty);
    waitForState("Replica not removed", collectionName, activeReplicaCount(0, 1, 0));
    new UpdateRequest().add(sdoc("id", "3")).add(sdoc("id", "4")).process(cloudClient, collectionName);
    ChaosMonkey.start(oldLeaderJetty);
    waitForState("Replica not added", collectionName, activeReplicaCount(0, 2, 0));
    checkRTG(1, 4, cluster.getJettySolrRunners());
    new UpdateRequest().commit(cloudClient, collectionName);
    waitForNumDocsInAllActiveReplicas(4, 0);
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 27 with UpdateRequest

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

the class TestStressCloudBlindAtomicUpdates method update.

public static UpdateRequest update(SolrParams params, SolrInputDocument... docs) {
    UpdateRequest r = new UpdateRequest();
    if (null != params) {
        r.setParams(new ModifiableSolrParams(params));
    }
    r.add(Arrays.asList(docs));
    return r;
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 28 with UpdateRequest

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

the class TestStressInPlaceUpdates method addDocAndGetVersion.

@SuppressWarnings("rawtypes")
protected long addDocAndGetVersion(Object... fields) throws Exception {
    SolrInputDocument doc = new SolrInputDocument();
    addFields(doc, fields);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("versions", "true");
    UpdateRequest ureq = new UpdateRequest();
    ureq.setParams(params);
    ureq.add(doc);
    UpdateResponse resp;
    // send updates to leader, to avoid SOLR-8733
    resp = ureq.process(leaderClient);
    long returnedVersion = Long.parseLong(((NamedList) resp.getResponse().get("adds")).getVal(0).toString());
    assertTrue("Due to SOLR-8733, sometimes returned version is 0. Let us assert that we have successfully" + " worked around that problem here.", returnedVersion > 0);
    return returnedVersion;
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) NamedList(org.apache.solr.common.util.NamedList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 29 with UpdateRequest

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

the class TestTlogReplica method simulatedDBQ.

private UpdateRequest simulatedDBQ(String query, long version) throws SolrServerException, IOException {
    String baseUrl = getBaseUrl();
    UpdateRequest ur = new UpdateRequest();
    ur.deleteByQuery(query);
    ur.setParam("_version_", "" + version);
    ur.setParam("update.distrib", "FROMLEADER");
    ur.setParam("distrib.from", baseUrl);
    return ur;
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest)

Example 30 with UpdateRequest

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

the class TestTlogReplica method testOutOfOrderDBQWithInPlaceUpdates.

public void testOutOfOrderDBQWithInPlaceUpdates() throws Exception {
    createAndWaitForCollection(1, 0, 2, 0);
    assertFalse(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").indexed());
    assertFalse(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").stored());
    assertTrue(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").hasDocValues());
    List<UpdateRequest> updates = new ArrayList<>();
    // full update
    updates.add(simulatedUpdateRequest(null, "id", 1, "title_s", "title0_new", "inplace_updatable_int", 5, "_version_", 1L));
    updates.add(simulatedDBQ("inplace_updatable_int:5", 3L));
    updates.add(simulatedUpdateRequest(1L, "id", 1, "inplace_updatable_int", 6, "_version_", 2L));
    for (JettySolrRunner solrRunner : getSolrRunner(false)) {
        try (SolrClient client = solrRunner.newClient()) {
            for (UpdateRequest up : updates) {
                up.process(client, collectionName);
            }
        }
    }
    JettySolrRunner oldLeaderJetty = getSolrRunner(true).get(0);
    ChaosMonkey.kill(oldLeaderJetty);
    waitForState("Replica not removed", collectionName, activeReplicaCount(0, 1, 0));
    ChaosMonkey.start(oldLeaderJetty);
    waitForState("Replica not added", collectionName, activeReplicaCount(0, 2, 0));
    checkRTG(1, 1, cluster.getJettySolrRunners());
    SolrDocument doc = cluster.getSolrClient().getById(collectionName, "1");
    assertNotNull(doc.get("title_s"));
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) ArrayList(java.util.ArrayList)

Aggregations

UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)273 Test (org.junit.Test)151 Tuple (org.apache.solr.client.solrj.io.Tuple)114 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)89 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)88 SolrInputDocument (org.apache.solr.common.SolrInputDocument)75 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)64 ArrayList (java.util.ArrayList)38 StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)36 IOException (java.io.IOException)29 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)26 SolrParams (org.apache.solr.common.params.SolrParams)26 SolrQuery (org.apache.solr.client.solrj.SolrQuery)24 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)23 FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)21 AbstractUpdateRequest (org.apache.solr.client.solrj.request.AbstractUpdateRequest)21 HashMap (java.util.HashMap)20 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)20 List (java.util.List)19 SolrServerException (org.apache.solr.client.solrj.SolrServerException)18