org.apache.solr.client.solrj.request.UpdateRequest Java Examples

The following examples show how to use org.apache.solr.client.solrj.request.UpdateRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseCloudSolrClient.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private static boolean hasInfoToFindLeaders(UpdateRequest updateRequest, String idField) {
  final Map<SolrInputDocument,Map<String,Object>> documents = updateRequest.getDocumentsMap();
  final Map<String,Map<String,Object>> deleteById = updateRequest.getDeleteByIdMap();

  final boolean hasNoDocuments = (documents == null || documents.isEmpty());
  final boolean hasNoDeleteById = (deleteById == null || deleteById.isEmpty());
  if (hasNoDocuments && hasNoDeleteById) {
    // no documents and no delete-by-id, so no info to find leader(s)
    return false;
  }

  if (documents != null) {
    for (final Map.Entry<SolrInputDocument,Map<String,Object>> entry : documents.entrySet()) {
      final SolrInputDocument doc = entry.getKey();
      final Object fieldValue = doc.getFieldValue(idField);
      if (fieldValue == null) {
        // a document with no id field value, so can't find leader for it
        return false;
      }
    }
  }

  return true;
}
 
Example #2
Source File: BasicAuthIntegrationTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void addDocument(String user, String pass, String... fields) throws IOException, SolrServerException {
  SolrInputDocument doc = new SolrInputDocument();
  boolean isKey = true;
  String key = null;
  for (String field : fields) {
    if (isKey) {
      key = field;
      isKey = false;
    } else {
      doc.setField(key, field);
    }
  }
  UpdateRequest update = new UpdateRequest();
  update.setBasicAuthCredentials(user, pass);
  update.add(doc);
  cluster.getSolrClient().request(update, COLLECTION);
  update.commit(cluster.getSolrClient(), COLLECTION);
}
 
Example #3
Source File: Operations.java    From kafka-connect-solr with Apache License 2.0 6 votes vote down vote up
UpdateRequest addOperation(boolean delete) {
  UpdateRequest result;
  if (delete) {
    result = (this.lastDelete = new UpdateRequest());
  } else {
    result = (this.lastUpdate = new UpdateRequest());
  }
  this.operations.add(result);
  this.lastOperationIsDelete = delete;
  if (this.config.commitWithin > 0) {
    result.setCommitWithin(this.config.commitWithin);
  }
  if (this.config.useBasicAuthentication) {
    result.setBasicAuthCredentials(
        this.config.username,
        this.config.password
    );
  }
  return result;
}
 
Example #4
Source File: SolrCmdDistributor.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void distribCommit(CommitUpdateCommand cmd, List<Node> nodes,
    ModifiableSolrParams params) throws IOException {
  
  // we need to do any retries before commit...
  blockAndDoRetries();
  log.debug("Distrib commit to: {} params: {}", nodes, params);

  for (Node node : nodes) {
    UpdateRequest uReq = new UpdateRequest();
    uReq.setParams(params);

    addCommit(uReq, cmd);
    submit(new Req(cmd, node, uReq, false), true);
  }
  
}
 
Example #5
Source File: TestSolrCloudWithKerberosAlt.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void testCollectionCreateSearchDelete() throws Exception {
  CloudSolrClient client = cluster.getSolrClient();
  CollectionAdminRequest.createCollection(collectionName, configName, numShards, numReplicas)
      .setMaxShardsPerNode(maxShardsPerNode)
      .process(client);

  cluster.waitForActiveCollection(collectionName, numShards, numShards * numReplicas);

  // modify/query collection
  new UpdateRequest().add("id", "1").commit(client, collectionName);
  QueryResponse rsp = client.query(collectionName, new SolrQuery("*:*"));
  assertEquals(1, rsp.getResults().getNumFound());
      
  // delete the collection we created earlier
  CollectionAdminRequest.deleteCollection(collectionName).process(client);
      
  AbstractDistribZkTestBase.waitForCollectionToDisappear
      (collectionName, client.getZkStateReader(), true, 330);
}
 
Example #6
Source File: StreamExpressionTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testEvalStream() throws Exception {
  UpdateRequest updateRequest = new UpdateRequest();
  updateRequest.add(id, "hello", "test_t", "l b c d c");
  updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);

  String expr = "eval(select(echo(\"search("+COLLECTIONORALIAS+", q=\\\"*:*\\\", fl=id, sort=\\\"id desc\\\")\"), echo as expr_s))";
  ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
  paramsLoc.set("expr", expr);
  paramsLoc.set("qt", "/stream");

  String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
  TupleStream solrStream = new SolrStream(url, paramsLoc);

  StreamContext context = new StreamContext();
  solrStream.setStreamContext(context);
  List<Tuple> tuples = getTuples(solrStream);
  assertTrue(tuples.size() == 1);
  String s = (String)tuples.get(0).get("id");
  assertTrue(s.equals("hello"));
}
 
Example #7
Source File: CdcrTestsUtil.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public static void indexRandomDocs(Integer start, Integer count, CloudSolrClient solrClient) throws Exception {
  // ADD operation on cluster 1
  int docs = 0;
  if (count == 0) {
    docs = (TEST_NIGHTLY ? 100 : 10);
  } else {
    docs = count;
  }
  for (int k = start; k < docs; k++) {
    UpdateRequest req = new UpdateRequest();
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", k);
    req.add(doc);

    req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
    req.process(solrClient);
  }
}
 
Example #8
Source File: TestStressInPlaceUpdates.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #9
Source File: StreamExpressionTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testSearchBacktick() throws Exception {
  UpdateRequest updateRequest = new UpdateRequest();
  updateRequest.add(id, "hello", "test_t", "l b c d c e");
  updateRequest.add(id, "hello1", "test_t", "l b c d c");
  updateRequest.commit(cluster.getSolrClient(), COLLECTIONORALIAS);

  String expr = "search("+COLLECTIONORALIAS+", q=\"`c d c e`\", fl=\"id,test_t\", sort=\"id desc\")";

  ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
  paramsLoc.set("expr", expr);
  paramsLoc.set("qt", "/stream");

  String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
  TupleStream solrStream = new SolrStream(url, paramsLoc);

  StreamContext context = new StreamContext();
  solrStream.setStreamContext(context);
  List<Tuple> tuples = getTuples(solrStream);
  assertTrue(tuples.size() == 1);
  Tuple tuple = tuples.get(0);
  assertTrue(tuple.get("id").equals("hello"));
  assertTrue(tuple.get("test_t").equals("l b c d c e"));
}
 
Example #10
Source File: SolrClient.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the beans supplied by the given iterator.
 *
 * @param collection the Solr collection to add the documents to
 * @param beanIterator
 *          the iterator which returns Beans
 *
 * @return an {@link org.apache.solr.client.solrj.response.UpdateResponse} from the server
 *
 * @throws IOException         if there is a communication error with the server
 * @throws SolrServerException if there is an error on the server
 */
public UpdateResponse addBeans(String collection, final Iterator<?> beanIterator)
    throws SolrServerException, IOException {
  UpdateRequest req = new UpdateRequest();
  req.setDocIterator(new Iterator<SolrInputDocument>() {

    @Override
    public boolean hasNext() {
      return beanIterator.hasNext();
    }

    @Override
    public SolrInputDocument next() {
      Object o = beanIterator.next();
      if (o == null) return null;
      return getBinder().toSolrInputDocument(o);
    }

    @Override
    public void remove() {
      beanIterator.remove();
    }
  });
  return req.process(this, collection);
}
 
Example #11
Source File: SolrClientInterceptorTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateWithOptimize() throws Throwable {
    final int maxSegments = 1;
    AbstractUpdateRequest request = (new UpdateRequest()).setAction(AbstractUpdateRequest.ACTION.OPTIMIZE, false, true, maxSegments);
    arguments = new Object[] {
        request,
        null,
        collection
    };
    interceptor.beforeMethod(enhancedInstance, method, arguments, argumentType, null);
    interceptor.afterMethod(enhancedInstance, method, arguments, argumentType, getResponse());

    List<TraceSegment> segments = segmentStorage.getTraceSegments();
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segments.get(0));

    Assert.assertEquals(segments.size(), 1);
    Assert.assertEquals(spans.size(), 1);

    AbstractTracingSpan span = spans.get(0);
    int start = 0;
    if (Config.Plugin.SolrJ.TRACE_OPS_PARAMS) {
        SpanAssert.assertTag(span, ++start, String.valueOf(maxSegments));
    }
    spanCommonAssert(span, start, "solrJ/collection/update/OPTIMIZE");
}
 
Example #12
Source File: TestAuthenticationFramework.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void collectionCreateSearchDeleteTwice() throws Exception {
  final CloudSolrClient client = cluster.getSolrClient();

  for (int i = 0 ; i < 2 ; ++i) {
    // create collection
    createCollection(collectionName);

    // check that there's no left-over state
    assertEquals(0, client.query(collectionName, new SolrQuery("*:*")).getResults().getNumFound());

    // modify/query collection
    Thread.sleep(100); // not everyone is up to date just because we waited to make sure one was - pause a moment
    new UpdateRequest().add("id", "1").commit(client, collectionName);
    QueryResponse rsp = client.query(collectionName, new SolrQuery("*:*"));
    assertEquals(1, rsp.getResults().getNumFound());

    // delete the collection
   cluster.deleteAllCollections();
  }
}
 
Example #13
Source File: SolrWriter.java    From anthelion with Apache License 2.0 6 votes vote down vote up
public void close() throws IOException {
  try {
    if (!inputDocs.isEmpty()) {
      LOG.info("Indexing " + Integer.toString(inputDocs.size()) + " documents");
      if (numDeletes > 0) {
        LOG.info("Deleting " + Integer.toString(numDeletes) + " documents");
      }
      UpdateRequest req = new UpdateRequest();
      req.add(inputDocs);
      req.setParams(params);
      req.process(solr);
      inputDocs.clear();
    }
    // solr.commit();
  } catch (final SolrServerException e) {
    throw makeIOException(e);
  }
}
 
Example #14
Source File: TestTlogReplica.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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<>();
  updates.add(simulatedUpdateRequest(null, "id", 1, "title_s", "title0_new", "inplace_updatable_int", 5, "_version_", 1L)); // full update
  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);
  oldLeaderJetty.stop();
  waitForState("Replica not removed", collectionName, activeReplicaCount(0, 1, 0));
  waitForLeaderChange(oldLeaderJetty, "shard1");
  oldLeaderJetty.start();
  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"));
}
 
Example #15
Source File: TestTlogReplica.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private UpdateRequest simulatedUpdateRequest(Long prevVersion, Object... fields) throws SolrServerException, IOException {
  SolrInputDocument doc = sdoc(fields);

  // get baseUrl of the leader
  String baseUrl = getBaseUrl();

  UpdateRequest ur = new UpdateRequest();
  ur.add(doc);
  ur.setParam("update.distrib", "FROMLEADER");
  if (prevVersion != null) {
    ur.setParam("distrib.inplace.prevversion", String.valueOf(prevVersion));
    ur.setParam("distrib.inplace.update", "true");
  }
  ur.setParam("distrib.from", baseUrl);
  return ur;
}
 
Example #16
Source File: DeleteStream.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Overrides implementation to extract the <code>"id"</code> and <code>"_version_"</code> 
 * (if included) from each document and use that information to construct a "Delete By Id" request.  
 * Any other fields (ie: Tuple values) are ignored.
 */
@Override
protected void uploadBatchToCollection(List<SolrInputDocument> documentBatch) throws IOException {
  if (documentBatch.size() == 0) {
    return;
  }

  try {
    // convert each doc into a deleteById request...
    final UpdateRequest req = new UpdateRequest();
    for (SolrInputDocument doc : documentBatch) {
      final String id = doc.getFieldValue(ID_TUPLE_KEY).toString();
      final Long version = getVersion(doc);
      req.deleteById(id, version);
    }
    req.process(getCloudSolrClient(), getCollectionName());
  } catch (SolrServerException | NumberFormatException| IOException e) {
    log.warn("Unable to delete documents from collection due to unexpected error.", e);
    String className = e.getClass().getName();
    String message = e.getMessage();
    throw new IOException(String.format(Locale.ROOT,"Unexpected error when deleting documents from collection %s- %s:%s", getCollectionName(), className, message));
  }
}
 
Example #17
Source File: CloudAuthStreamTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testSimpleDeleteStreamInsufficientCredentials() throws Exception {
  assertEquals(0,
               (setBasicAuthCredentials(new UpdateRequest(), WRITE_X_USER)
                .add(sdoc("id", "42"))
                .commit(cluster.getSolrClient(), COLLECTION_X)).getStatus());
  assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));
  
  // both of these users have valid credentials and authz read COLLECTION_X, but neither has
  // authz to write to X...
  for (String user : Arrays.asList(READ_ONLY_USER, WRITE_Y_USER)) {
    final SolrStream solrStream = new SolrStream(solrUrl + "/" + COLLECTION_X,
                                                 params("qt", "/stream", "expr",
                                                        "update("+COLLECTION_X+",batchSize=1," +
                                                        "tuple(id=42))"));
    
    solrStream.setCredentials(user, user);
  
    // NOTE: Can't make any assertions about Exception: SOLR-14226
    expectThrows(Exception.class, () -> {
        final List<Tuple> ignored = getTuples(solrStream);
      });
  }
  
  assertEquals(1L, commitAndCountDocsInCollection(COLLECTION_X, WRITE_X_USER));
}
 
Example #18
Source File: BasicHttpSolrClientTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void setReqParamsOf(UpdateRequest req, String... keys) {
  if (keys != null) {
    for (String k : keys) {
      req.setParam(k, k+"Value");
    }
  }
}
 
Example #19
Source File: TestTlogReplica.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #20
Source File: SolrIOTestUtils.java    From beam with Apache License 2.0 5 votes vote down vote up
/** Inserts the given number of test documents into Solr. */
static void insertTestDocuments(String collection, long numDocs, AuthorizedSolrClient client)
    throws IOException {
  List<SolrInputDocument> data = createDocuments(numDocs);
  try {
    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.setAction(UpdateRequest.ACTION.COMMIT, true, true);
    updateRequest.add(data);
    client.process(collection, updateRequest);
  } catch (SolrServerException e) {
    throw new IOException("Failed to insert test documents to collection", e);
  }
}
 
Example #21
Source File: JdbcTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupCluster() throws Exception {
  configureCluster(2)
      .addConfig("conf", getFile("solrj").toPath().resolve("solr").resolve("configsets").resolve("streaming").resolve("conf"))
      .configure();

  String collection;
  boolean useAlias = random().nextBoolean();
  if (useAlias) {
    collection = COLLECTIONORALIAS + "_collection";
  } else {
    collection = COLLECTIONORALIAS;
  }
  CollectionAdminRequest.createCollection(collection, "conf", 2, 1).process(cluster.getSolrClient());
  
  cluster.waitForActiveCollection(collection, 2, 2);
  
  AbstractDistribZkTestBase.waitForRecoveriesToFinish(collection, cluster.getSolrClient().getZkStateReader(),
      false, true, DEFAULT_TIMEOUT);
  if (useAlias) {
    CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection).process(cluster.getSolrClient());
  }

  new UpdateRequest()
      .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1", "testnull_i", null)
      .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2", "testnull_i", "2")
      .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "testnull_i", null)
      .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "testnull_i", "4")
      .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5", "testnull_i", null)
      .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6", "testnull_i", "6")
      .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7", "testnull_i", null)
      .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8", "testnull_i", "8")
      .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9", "testnull_i", null)
      .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10", "testnull_i", "10")
      .commit(cluster.getSolrClient(), collection);

  zkHost = cluster.getZkServer().getZkAddress();
}
 
Example #22
Source File: ReplicationFactorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private int runAndGetAchievedRf(UpdateRequest up, boolean minRfExplicit, int minRf) throws SolrServerException, IOException {
  NamedList<Object> response = cloudClient.request(up);
  if (minRfExplicit) {
    assertMinRfInResponse(minRf, response);
  }
  return cloudClient.getMinAchievedReplicationFactor(cloudClient.getDefaultCollection(), response);
}
 
Example #23
Source File: MergeIndexesExampleTestBase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testMergeIndexesByDirName() throws Exception {
  UpdateRequest up = setupCores();

  // Now get the index directory of core1 and merge with core0
  CoreAdminRequest.mergeIndexes("core0", new String[] {getIndexDirCore1()}, new String[0], getSolrAdmin());

  // Now commit the merged index
  up.clear(); // just do commit
  up.process(getSolrCore0());

  assertEquals(1,
      getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
  assertEquals(1,
      getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());
}
 
Example #24
Source File: TestInPlaceUpdateWithRouteField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdatingDocValuesWithRouteField() throws Exception {

   new UpdateRequest()
    .deleteByQuery("*:*").commit(cluster.getSolrClient(), COLLECTION);
  
   new UpdateRequest().add(createDocs(NUMBER_OF_DOCS)).commit(cluster.getSolrClient(), COLLECTION);

  int id = TestUtil.nextInt(random(), 1, NUMBER_OF_DOCS - 1);
  SolrDocument solrDocument = queryDoc(id);
  Long initialVersion = (Long) solrDocument.get("_version_");
  Integer luceneDocId = (Integer) solrDocument.get("[docid]");
  String shardName = (String) solrDocument.get("shardName");
  Assert.assertThat(solrDocument.get("inplace_updatable_int"), is(id));

  int newDocValue = TestUtil.nextInt(random(), 1, 2 * NUMBER_OF_DOCS - 1);
  SolrInputDocument sdoc = sdoc("id", ""+id,
      // use route field in update command
      "shardName", shardName,
      "inplace_updatable_int", map("set", newDocValue));
  
  UpdateRequest updateRequest = new UpdateRequest()
      .add(sdoc);
  updateRequest.commit(cluster.getSolrClient(), COLLECTION);
  solrDocument = queryDoc(id);
  Long newVersion = (Long) solrDocument.get("_version_");
  Assert.assertTrue("Version of updated document must be greater than original one",
      newVersion > initialVersion);
  Assert.assertThat( "Doc value must be updated", solrDocument.get("inplace_updatable_int"), is(newDocValue));
  Assert.assertThat("Lucene doc id should not be changed for In-Place Updates.", solrDocument.get("[docid]"), is(luceneDocId));

  sdoc.remove("shardName");
  checkWrongCommandFailure(sdoc);

  sdoc.addField("shardName",  map("set", "newShardName"));
  checkWrongCommandFailure(sdoc);
}
 
Example #25
Source File: ReplicationFactorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected int sendDoc(int docId, int minRf) throws Exception {
  UpdateRequest up = new UpdateRequest();
  boolean minRfExplicit = maybeAddMinRfExplicitly(minRf, up);
  SolrInputDocument doc = new SolrInputDocument();
  doc.addField(id, String.valueOf(docId));
  doc.addField("a_t", "hello" + docId);
  up.add(doc);
  return runAndGetAchievedRf(up, minRfExplicit, minRf);
}
 
Example #26
Source File: Http2SolrClientTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void setReqParamsOf(UpdateRequest req, String... keys) {
  if (keys != null) {
    for (String k : keys) {
      req.setParam(k, k+"Value");
    }
  }
}
 
Example #27
Source File: TestDynamicURP.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testUrp() throws Exception {

  ByteBuffer jar = getFileContent("runtimecode/runtimeurp.jar.bin");

  String blobName = "urptest";
  TestBlobHandler.postAndCheck(cluster.getSolrClient(), cluster.getRandomJetty(random()).getBaseUrl().toString(),
      blobName, jar, 1);

  new V2Request.Builder("/c/" + COLLECTION + "/config")
      .withPayload(singletonMap("add-runtimelib", (MapWriter) ew1 -> ew1
          .put("name", blobName)
          .put("version", "1")))
      .withMethod(POST)
      .build()
      .process(cluster.getSolrClient());
  TestSolrConfigHandler.testForResponseElement(null,
      cluster.getRandomJetty(random()).getBaseUrl().toString(),
      "/"+COLLECTION+"/config/overlay",
      cluster.getSolrClient(),
      Arrays.asList("overlay", "runtimeLib", blobName, "version")
      ,"1",10);

  SolrInputDocument doc = new SolrInputDocument();
  doc.addField("id", "123");
  doc.addField("name_s", "Test URP");
  new UpdateRequest()
      .add(doc)
      .commit(cluster.getSolrClient(), COLLECTION);
  QueryResponse result = cluster.getSolrClient().query(COLLECTION, new SolrQuery("id:123"));
  assertEquals(1, result.getResults().getNumFound());
  Object time_s = result.getResults().get(0).getFirstValue("time_s");
  assertNotNull(time_s);



}
 
Example #28
Source File: CloudAuthStreamTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that uses the specified user to (first commit, and then) count the total 
 * number of documents in the collection
 */
protected static long commitAndCountDocsInCollection(final String collection,
                                                 final String user) throws Exception {
  assertEquals(0, setBasicAuthCredentials(new UpdateRequest(), user).commit(cluster.getSolrClient(),
                                                                            collection).getStatus());
  return countDocsInCollection(collection, user);
}
 
Example #29
Source File: BinaryRequestWriter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void write(@SuppressWarnings({"rawtypes"})SolrRequest request, OutputStream os) throws IOException {
  if (request instanceof UpdateRequest) {
    UpdateRequest updateRequest = (UpdateRequest) request;
    new JavaBinUpdateRequestCodec().marshal(updateRequest, os);
  }
}
 
Example #30
Source File: StreamingTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
// commented out on: 17-Feb-2019   @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 6-Sep-2018
public void testZeroParallelReducerStream() throws Exception {

  new UpdateRequest()
      .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1")
      .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2")
      .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3")
      .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4")
      .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5")
      .add(id, "5", "a_s", "hello3", "a_i", "10", "a_f", "6")
      .add(id, "6", "a_s", "hello4", "a_i", "11", "a_f", "7")
      .add(id, "7", "a_s", "hello3", "a_i", "12", "a_f", "8")
      .add(id, "8", "a_s", "hello3", "a_i", "13", "a_f", "9")
      .add(id, "9", "a_s", "hello0", "a_i", "14", "a_f", "10")
      .commit(cluster.getSolrClient(), COLLECTIONORALIAS);

  StreamContext streamContext = new StreamContext();
  SolrClientCache solrClientCache = new SolrClientCache();
  streamContext.setSolrClientCache(solrClientCache);
  try {
    SolrParams sParamsA = mapParams("q", "a_s:blah", "fl", "id,a_s,a_i,a_f", "sort", "a_s asc,a_f asc", "partitionKeys", "a_s", "qt", "/export");
    CloudSolrStream stream = new CloudSolrStream(zkHost, COLLECTIONORALIAS, sParamsA);
    ReducerStream rstream = new ReducerStream(stream,
        new FieldEqualitor("a_s"),
        new GroupOperation(new FieldComparator("a_s", ComparatorOrder.ASCENDING), 2));
    ParallelStream pstream = parallelStream(rstream, new FieldComparator("a_s", ComparatorOrder.ASCENDING));
    attachStreamFactory(pstream);
    pstream.setStreamContext(streamContext);
    List<Tuple> tuples = getTuples(pstream);
    assert (tuples.size() == 0);
  } finally {
    solrClientCache.close();
  }

}