From a2eb7f388009b9fd0bda356fdf51e52d525124d2 Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Mon, 26 Feb 2018 13:56:55 +0100 Subject: [PATCH] SOLR-11407: Use all details of the query response in the handler response. More consistency in debug info from the test. --- .../admin/AutoscalingHistoryHandler.java | 6 ++- .../admin/AutoscalingHistoryHandlerTest.java | 46 +++++++------------ 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/handler/admin/AutoscalingHistoryHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/AutoscalingHistoryHandler.java index a70afcf5ae2..15af8642ff9 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/AutoscalingHistoryHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/AutoscalingHistoryHandler.java @@ -128,11 +128,13 @@ public class AutoscalingHistoryHandler extends RequestHandlerBase implements Per .withHttpClient(coreContainer.getUpdateShardHandler().getHttpClient()) .build()) { QueryResponse qr = cloudSolrClient.query(collection, params); - rsp.getValues().add("response", qr.getResults()); + rsp.setAllValues(qr.getResponse()); } catch (Exception e) { if ((e instanceof SolrException) && e.getMessage().contains("Collection not found")) { // relatively benign - LOG.info("Collection " + collection + " does not exist."); + String msg = "Collection " + collection + " does not exist."; + LOG.info(msg); + rsp.getValues().add("error", msg); } else { throw e; } diff --git a/solr/core/src/test/org/apache/solr/handler/admin/AutoscalingHistoryHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/AutoscalingHistoryHandlerTest.java index 8bb336df4ad..028f8d844f0 100644 --- a/solr/core/src/test/org/apache/solr/handler/admin/AutoscalingHistoryHandlerTest.java +++ b/solr/core/src/test/org/apache/solr/handler/admin/AutoscalingHistoryHandlerTest.java @@ -23,6 +23,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrRequest; import org.apache.solr.client.solrj.cloud.autoscaling.TriggerEventProcessorStage; import org.apache.solr.client.solrj.embedded.JettySolrRunner; @@ -262,15 +263,7 @@ public class AutoscalingHistoryHandlerTest extends SolrCloudTestCase { query = params(CommonParams.QT, CommonParams.AUTOSCALING_HISTORY_PATH, AutoscalingHistoryHandler.TRIGGER_PARAM, PREFIX + "_node_added_trigger"); - QueryResponse rsp = solrClient.query(query); - docs = rsp.getResults(); - if (docs.size() != 8) { - log.info("Cluster state: " + solrClient.getZkStateReader().getClusterState()); - query = params(CommonParams.QT, CommonParams.AUTOSCALING_HISTORY_PATH); - log.info("Wrong response: ", rsp); - log.info("Full response: " + solrClient.query(query)); - } - assertEquals(8, docs.size()); + docs = queryAndAssertDocs(query, solrClient, 8); query = params(CommonParams.QT, CommonParams.AUTOSCALING_HISTORY_PATH, AutoscalingHistoryHandler.STAGE_PARAM, "STARTED"); @@ -280,8 +273,7 @@ public class AutoscalingHistoryHandlerTest extends SolrCloudTestCase { query = params(CommonParams.QT, CommonParams.AUTOSCALING_HISTORY_PATH, AutoscalingHistoryHandler.NODE_PARAM, nodeAddedName); - docs = solrClient.query(query).getResults(); - assertEquals(8, docs.size()); + docs = queryAndAssertDocs(query, solrClient, 8); for (SolrDocument doc : docs) { assertTrue(doc.getFieldValues("event.property.nodeNames_ss").contains(nodeAddedName)); } @@ -302,15 +294,7 @@ public class AutoscalingHistoryHandlerTest extends SolrCloudTestCase { query = params(CommonParams.QT, CommonParams.AUTOSCALING_HISTORY_PATH, AutoscalingHistoryHandler.COLLECTION_PARAM, COLL_NAME); - rsp = solrClient.query(query); - docs = rsp.getResults(); - if (docs.size() != 5) { - log.info("Cluster state: " + solrClient.getZkStateReader().getClusterState()); - query = params(CommonParams.QT, CommonParams.AUTOSCALING_HISTORY_PATH); - log.info("Wrong response: ", rsp); - log.info("Full response: " + solrClient.query(query)); - } - assertEquals(5, docs.size()); + docs = queryAndAssertDocs(query, solrClient, 5); assertEquals("AFTER_ACTION", docs.get(0).getFieldValue("stage_s")); assertEquals("compute_plan", docs.get(0).getFieldValue("action_s")); @@ -359,16 +343,20 @@ public class AutoscalingHistoryHandlerTest extends SolrCloudTestCase { query = params(CommonParams.QT, CommonParams.AUTOSCALING_HISTORY_PATH, AutoscalingHistoryHandler.TRIGGER_PARAM, PREFIX + "_node_lost_trigger", AutoscalingHistoryHandler.COLLECTION_PARAM, COLL_NAME); - rsp = solrClient.query(query); - docs = rsp.getResults(); - if (docs.size() != 5) { - log.info("Cluster state: " + solrClient.getZkStateReader().getClusterState()); - query = params(CommonParams.QT, CommonParams.AUTOSCALING_HISTORY_PATH); - log.info("Wrong response: ", rsp); - log.info("Full response: " + solrClient.query(query)); - } + docs = queryAndAssertDocs(query, solrClient, 5); + } - assertEquals(5, docs.size()); + private SolrDocumentList queryAndAssertDocs(ModifiableSolrParams query, SolrClient client, int expected) throws Exception { + QueryResponse rsp = client.query(query); + SolrDocumentList docs = rsp.getResults(); + if (docs.size() != expected) { + log.info("History query: " + query); + log.info("Wrong response: " + rsp); + query = params(CommonParams.QT, CommonParams.AUTOSCALING_HISTORY_PATH); + log.info("Full response: " + client.query(query)); + } + assertEquals("Wrong number of documents", expected, docs.size()); + return docs; } private void waitForRecovery(String collection) throws Exception {