lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hoss...@apache.org
Subject [20/50] [abbrv] lucene-solr git commit: SOLR-445: added test asserts of client exception metadata, and hacky kludge to get it working in CloudSolrClient
Date Sat, 12 Mar 2016 00:27:01 GMT
SOLR-445: added test asserts of client exception metadata, and hacky kludge to get it working
in CloudSolrClient

need to refactor KnownErr to solr-common (and rename something more clear out of context)
so client code can use it


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/5b405b61
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/5b405b61
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/5b405b61

Branch: refs/heads/jira/SOLR-445
Commit: 5b405b614417b1bcdbafe933b2e8308bf4e9fbeb
Parents: 92f81fb
Author: Chris Hostetter <hossman@apache.org>
Authored: Wed Mar 9 17:45:28 2016 -0700
Committer: Chris Hostetter <hossman@apache.org>
Committed: Wed Mar 9 17:45:28 2016 -0700

----------------------------------------------------------------------
 .../cloud/TestTolerantUpdateProcessorCloud.java | 67 ++++++++++++++++++--
 .../solr/client/solrj/impl/CloudSolrClient.java | 27 +++++++-
 2 files changed, 85 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5b405b61/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java
b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java
index aef0385..bee23a7 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestTolerantUpdateProcessorCloud.java
@@ -22,7 +22,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -45,9 +45,13 @@ import org.apache.solr.common.cloud.Slice;
 import org.apache.solr.common.cloud.ZkStateReader;
 import org.apache.solr.common.params.ModifiableSolrParams;
 import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.util.RevertDefaultThreadHandlerRule;
 
+import org.apache.solr.update.processor.TolerantUpdateProcessor.KnownErr;
+import org.apache.solr.update.processor.TolerantUpdateProcessor.CmdType;
+
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -523,14 +527,37 @@ public class TestTolerantUpdateProcessorCloud extends SolrCloudTestCase
{
     } catch (SolrException e) {
       // we can't make any reliable assertions about the error message, because
       // it varies based on how the request was routed
-      // nocommit: can we tighten this any more? substring check?
+      // nocommit: verify that we can't do an e.getMessage() substring check
       assertEquals("not the type of error we were expecting ("+e.code()+"): " + e.toString(),
                    // NOTE: we always expect a 400 because we know that's what we would get
from these types of errors
                    // on a single node setup -- a 5xx type error isn't something we should
have triggered
                    400, e.code());
 
-      // nocommit: is there a way to inspect the response body anyway?
-      // nocommit: look for the correct "errors" ?  .... check e's metatata
+      // verify that the Exceptions metadata can tell us what failed.
+      NamedList<String> remoteErrMetadata = e.getMetadata();
+      assertNotNull("no metadata in: " + e.toString(), remoteErrMetadata);
+      Set<KnownErr> actualKnownErrs = new LinkedHashSet<KnownErr>(remoteErrMetadata.size());
+      int actualKnownErrsCount = 0;
+      for (int i = 0; i < remoteErrMetadata.size(); i++) {
+        KnownErr err = KnownErr.parseMetadataIfKnownErr(remoteErrMetadata.getName(i),
+                                                        remoteErrMetadata.getVal(i));
+        if (null == err) {
+          // some metadata unrelated to this update processor
+          continue;
+        }
+        actualKnownErrsCount++;
+        actualKnownErrs.add(err);
+      }
+      assertEquals("wrong number of errors in metadata: " + remoteErrMetadata.toString(),
+                   11, actualKnownErrsCount);
+      assertEquals("at least one dup error in metadata: " + remoteErrMetadata.toString(),
+                   actualKnownErrsCount, actualKnownErrs.size());
+      for (KnownErr err : actualKnownErrs) {
+        assertEquals("only expected type of error is ADD: " + err,
+                     CmdType.ADD, err.type);
+        assertTrue("failed err msg didn't match expected value: " + err,
+                   err.errorValue.contains("bogus_val"));
+      }
     }
     assertEquals(0, client.commit().getStatus()); // need to force since update didn't finish
     assertQueryDocIds(client, false
@@ -573,14 +600,40 @@ public class TestTolerantUpdateProcessorCloud extends SolrCloudTestCase
{
     } catch (SolrException e) {
       // we can't make any reliable assertions about the error message, because
       // it varies based on how the request was routed
-      // nocommit: can we tighten this any more? substring check?
+      // nocommit: verify that we can't do an e.getMessage() substring check
       assertEquals("not the type of error we were expecting ("+e.code()+"): " + e.toString(),
                    // NOTE: we always expect a 400 because we know that's what we would get
from these types of errors
                    // on a single node setup -- a 5xx type error isn't something we should
have triggered
                    400, e.code());
 
-      // nocommit: is there a way to inspect the response body anyway?
-      // nocommit: look for the correct "errors" ?  .... check e's metatata
+      // verify that the Exceptions metadata can tell us what failed.
+      NamedList<String> remoteErrMetadata = e.getMetadata();
+      assertNotNull("no metadata in: " + e.toString(), remoteErrMetadata);
+      Set<KnownErr> actualKnownErrs = new LinkedHashSet<KnownErr>(remoteErrMetadata.size());
+      int actualKnownErrsCount = 0;
+      for (int i = 0; i < remoteErrMetadata.size(); i++) {
+        KnownErr err = KnownErr.parseMetadataIfKnownErr(remoteErrMetadata.getName(i),
+                                                        remoteErrMetadata.getVal(i));
+        if (null == err) {
+          // some metadata unrelated to this update processor
+          continue;
+        }
+        actualKnownErrsCount++;
+        actualKnownErrs.add(err);
+      }
+      assertEquals("wrong number of errors in metadata: " + remoteErrMetadata.toString(),
+                   11, actualKnownErrsCount);
+      assertEquals("at least one dup error in metadata: " + remoteErrMetadata.toString(),
+                   actualKnownErrsCount, actualKnownErrs.size());
+      for (KnownErr err : actualKnownErrs) {
+        assertEquals("only expected type of error is ADD: " + err,
+                     CmdType.ADD, err.type);
+        assertTrue("failed id had unexpected prefix: " + err,
+                   err.id.startsWith(S_TWO_PRE));
+        assertTrue("failed err msg didn't match expected value: " + err,
+                   err.errorValue.contains("bogus_val"));
+      }
+           
     }
     assertEquals(0, client.commit().getStatus()); // need to force since update didn't finish
     assertQueryDocIds(client, true

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5b405b61/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
index 0248a7d..655844f 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
@@ -776,8 +776,15 @@ public class CloudSolrClient extends SolrClient {
     if (null != toleratedErrors) {
       cheader.add("errors", toleratedErrors);
       if (maxToleratedErrors < toleratedErrors.size()) {
-        // nocommit: populate metadata based on the toleratedErrors
-        throw new SolrException(ErrorCode.BAD_REQUEST, "nocommit: need better msg");
+        NamedList metadata = new NamedList<String>();
+        SolrException toThrow = new SolrException(ErrorCode.BAD_REQUEST, "nocommit: need
better msg");
+        toThrow.setMetadata(metadata);
+        for (SimpleOrderedMap<String> err : toleratedErrors) {
+          // nocommit: hack, refactor KnownErr into solr-common and re-use here...
+          metadata.add("org.apache.solr.update.processor.TolerantUpdateProcessor--" +
+                       err.get("type") + ":" + err.get("id"), err.get("message"));
+        }
+        throw toThrow;
       }
     }
     condensed.add("responseHeader", cheader);
@@ -815,6 +822,22 @@ public class CloudSolrClient extends SolrClient {
       super(errorCode, throwables.getVal(0).getMessage(), throwables.getVal(0));
       this.throwables = throwables;
       this.routes = routes;
+
+      // create a merged copy of the metadata from all wrapped exceptions
+      NamedList<String> metadata = new NamedList<String>();
+      for (int i = 0; i < throwables.size(); i++) {
+        Throwable t = throwables.getVal(i);
+        if (t instanceof SolrException) {
+          SolrException e = (SolrException) t;
+          NamedList<String> eMeta = e.getMetadata();
+          if (null != eMeta) {
+            metadata.addAll(eMeta);
+          }
+        }
+      }
+      if (0 < metadata.size()) {
+        this.setMetadata(metadata);
+      }
     }
 
     public NamedList<Throwable> getThrowables() {


Mime
View raw message