mirror of https://github.com/apache/lucene.git
SOLR-8194: Improve error reporting of nulls in UpdateRequest
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1715749 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1047e54916
commit
23dabd19ff
|
@ -554,6 +554,9 @@ Other Changes
|
|||
* SOLR-8303: CustomBufferedIndexInput now includes resource description when
|
||||
throwing EOFException. (Mike Drob via Uwe Schindler)
|
||||
|
||||
* SOLR-8194: Improve error reporting for null documents in UpdateRequest (Markus
|
||||
Jelsma, Alan Woodward)
|
||||
|
||||
================== 5.3.1 ==================
|
||||
|
||||
Bug Fixes
|
||||
|
|
|
@ -17,16 +17,6 @@
|
|||
|
||||
package org.apache.solr.client.solrj.request;
|
||||
|
||||
import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
|
||||
import org.apache.solr.client.solrj.util.ClientUtils;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.apache.solr.common.cloud.DocCollection;
|
||||
import org.apache.solr.common.cloud.DocRouter;
|
||||
import org.apache.solr.common.cloud.Slice;
|
||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||
import org.apache.solr.common.util.ContentStream;
|
||||
import org.apache.solr.common.util.XML;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
@ -38,8 +28,19 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
|
||||
import org.apache.solr.client.solrj.util.ClientUtils;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.apache.solr.common.cloud.DocCollection;
|
||||
import org.apache.solr.common.cloud.DocRouter;
|
||||
import org.apache.solr.common.cloud.Slice;
|
||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||
import org.apache.solr.common.util.ContentStream;
|
||||
import org.apache.solr.common.util.XML;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -88,25 +89,50 @@ public class UpdateRequest extends AbstractUpdateRequest {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Add a SolrInputDocument to this request
|
||||
*
|
||||
* @throws NullPointerException if the document is null
|
||||
*/
|
||||
public UpdateRequest add(final SolrInputDocument doc) {
|
||||
Objects.requireNonNull(doc, "Cannot add a null SolrInputDocument");
|
||||
if (documents == null) {
|
||||
documents = new LinkedHashMap<>();
|
||||
}
|
||||
documents.put(doc, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a SolrInputDocument to this request
|
||||
* @param doc the document
|
||||
* @param overwrite true if the document should overwrite existing docs with the same id
|
||||
* @throws NullPointerException if the document is null
|
||||
*/
|
||||
public UpdateRequest add(final SolrInputDocument doc, Boolean overwrite) {
|
||||
return add(doc, null, overwrite);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a SolrInputDocument to this request
|
||||
* @param doc the document
|
||||
* @param commitWithin the time horizon by which the document should be committed (in ms)
|
||||
* @throws NullPointerException if the document is null
|
||||
*/
|
||||
public UpdateRequest add(final SolrInputDocument doc, Integer commitWithin) {
|
||||
return add(doc, commitWithin, null);
|
||||
}
|
||||
|
||||
public UpdateRequest add(final SolrInputDocument doc, Integer commitWithin,
|
||||
Boolean overwrite) {
|
||||
|
||||
/**
|
||||
* Add a SolrInputDocument to this request
|
||||
* @param doc the document
|
||||
* @param commitWithin the time horizon by which the document should be committed (in ms)
|
||||
* @param overwrite true if the document should overwrite existing docs with the same id
|
||||
* @throws NullPointerException if the document is null
|
||||
*/
|
||||
public UpdateRequest add(final SolrInputDocument doc, Integer commitWithin, Boolean overwrite) {
|
||||
Objects.requireNonNull(doc, "Cannot add a null SolrInputDocument");
|
||||
if (documents == null) {
|
||||
documents = new LinkedHashMap<>();
|
||||
}
|
||||
|
@ -118,12 +144,18 @@ public class UpdateRequest extends AbstractUpdateRequest {
|
|||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a collection of SolrInputDocuments to this request
|
||||
*
|
||||
* @throws NullPointerException if any of the documents in the collection are null
|
||||
*/
|
||||
public UpdateRequest add(final Collection<SolrInputDocument> docs) {
|
||||
if (documents == null) {
|
||||
documents = new LinkedHashMap<>();
|
||||
}
|
||||
for (SolrInputDocument doc : docs) {
|
||||
Objects.requireNonNull(doc, "Cannot add a null SolrInputDocument");
|
||||
documents.put(doc, null);
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package org.apache.solr.client.solrj.request;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
public class TestUpdateRequest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void expectException() {
|
||||
exception.expect(NullPointerException.class);
|
||||
exception.expectMessage("Cannot add a null SolrInputDocument");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCannotAddNullSolrInputDocument() {
|
||||
UpdateRequest req = new UpdateRequest();
|
||||
req.add((SolrInputDocument) null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCannotAddNullDocumentWithOverwrite() {
|
||||
UpdateRequest req = new UpdateRequest();
|
||||
req.add(null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCannotAddNullDocumentWithCommitWithin() {
|
||||
UpdateRequest req = new UpdateRequest();
|
||||
req.add(null, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCannotAddNullDocumentWithParameters() {
|
||||
UpdateRequest req = new UpdateRequest();
|
||||
req.add(null, 1, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCannotAddNullDocumentAsPartOfList() {
|
||||
UpdateRequest req = new UpdateRequest();
|
||||
req.add(Arrays.asList(new SolrInputDocument(), new SolrInputDocument(), null));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue