You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by gu...@apache.org on 2019/02/19 14:53:40 UTC
[lucene-solr] 03/09: SOLR-13150: fix CRA max cardinality test
compatiblity with TolerantUpdateProcessor
This is an automated email from the ASF dual-hosted git repository.
gus pushed a commit to branch solr-13131
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit 1208d694d82610cfd4c30ad306f4e8d789578133
Author: internet <in...@localhost.localdomain>
AuthorDate: Sun Feb 17 11:46:21 2019 +0200
SOLR-13150: fix CRA max cardinality test compatiblity with TolerantUpdateProcessor
---
.../cloud/api/collections/CategoryRoutedAlias.java | 8 ++++----
.../CategoryRoutedAliasUpdateProcessorTest.java | 21 +++++++++++++++------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/cloud/api/collections/CategoryRoutedAlias.java b/solr/core/src/java/org/apache/solr/cloud/api/collections/CategoryRoutedAlias.java
index c337ed5..0cd0176 100644
--- a/solr/core/src/java/org/apache/solr/cloud/api/collections/CategoryRoutedAlias.java
+++ b/solr/core/src/java/org/apache/solr/cloud/api/collections/CategoryRoutedAlias.java
@@ -117,15 +117,15 @@ public class CategoryRoutedAlias implements RoutedAlias {
String dataValue = String.valueOf(cmd.getSolrInputDocument().getFieldValue(getRouteField()));
String candidateCollectionName = buildCollectionNameFromValue(dataValue);
- List<String> colls = getCollectionList(this.parsedAliases);
+ List<String> cols = getCollectionList(this.parsedAliases);
- if (colls.contains(candidateCollectionName)) {
+ if (cols.contains(candidateCollectionName)) {
return;
}
- if (colls.stream()
+ if (cols.stream()
.filter(x -> !x.contains(UNINITIALIZED)).count() >= Integer.valueOf(maxCardinality)) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "max cardinality can not be exceeded for a Category Routed Alias: " + maxCardinality);
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "max cardinality can not be exceeded for a Category Routed Alias: " + maxCardinality);
}
}
diff --git a/solr/core/src/test/org/apache/solr/update/processor/CategoryRoutedAliasUpdateProcessorTest.java b/solr/core/src/test/org/apache/solr/update/processor/CategoryRoutedAliasUpdateProcessorTest.java
index 9cd44fc..d269f8f 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/CategoryRoutedAliasUpdateProcessorTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/CategoryRoutedAliasUpdateProcessorTest.java
@@ -30,6 +30,7 @@ import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.ConfigSetAdminRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.cloud.api.collections.CategoryRoutedAlias;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
@@ -62,6 +63,7 @@ public class CategoryRoutedAliasUpdateProcessorTest extends RoutedAliasUpdatePro
private int lastDocId = 0;
private static CloudSolrClient solrClient;
+ private int numDocsDeletedOrFailed = 0;
@Before
public void doBefore() throws Exception {
@@ -257,11 +259,7 @@ public class CategoryRoutedAliasUpdateProcessorTest extends RoutedAliasUpdatePro
assertInvariants(colVogon, colHoG);
// should fail since max cardinality is reached
- SolrException e = expectThrows(SolrException.class, () ->
- solrClient.add(getAlias(), Collections.singleton(newDoc(SHIPS[2])), -1));
- assertTrue("update should fail because CRA max cardinality is reached",
- e.getMessage().contains("max cardinality can not be exceeded for a Category Routed Alias"));
- --lastDocId; // since last doc was not indexed
+ testFailedDocument(newDoc(SHIPS[2]), "max cardinality can not be exceeded for a Category Routed Alias");
assertInvariants(colVogon, colHoG);
}
@@ -326,7 +324,6 @@ public class CategoryRoutedAliasUpdateProcessorTest extends RoutedAliasUpdatePro
private void assertInvariants(String... expectedColls) throws IOException, SolrServerException {
- int numDocsDeletedOrFailed = 0;
final int expectNumFound = lastDocId - numDocsDeletedOrFailed; //lastDocId is effectively # generated docs
List<String> cols = new CollectionAdminRequest.ListAliases().process(solrClient).getAliasesAsLists().get(getAlias());
@@ -384,4 +381,16 @@ public class CategoryRoutedAliasUpdateProcessorTest extends RoutedAliasUpdatePro
}
}
+ private void testFailedDocument(SolrInputDocument sdoc, String errorMsg) throws SolrServerException, IOException {
+ try {
+ final UpdateResponse resp = solrClient.add(getAlias(), sdoc);
+ // if we have a TolerantUpdateProcessor then we see it there)
+ final Object errors = resp.getResponseHeader().get("errors"); // Tolerant URP
+ assertTrue(errors != null && errors.toString().contains(errorMsg));
+ } catch (SolrException e) {
+ assertTrue(e.getMessage().contains(errorMsg));
+ }
+ ++numDocsDeletedOrFailed;
+ }
+
}