From 5865893e649e696a9ceec4d544d6492d2d6ee1ef Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Thu, 5 Dec 2019 18:25:49 +0100 Subject: [PATCH] SOLR-13831: Context property _loop_iter_ should be a string in order to support variable expansion. --- .../org/apache/solr/cloud/autoscaling/sim/SimScenario.java | 2 +- .../apache/solr/cloud/autoscaling/sim/TestSimScenario.java | 7 +++++-- .../src/solrcloud-autoscaling-policy-preferences.adoc | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/cloud/autoscaling/sim/SimScenario.java b/solr/core/src/java/org/apache/solr/cloud/autoscaling/sim/SimScenario.java index 755d2366666..41a2827e05b 100644 --- a/solr/core/src/java/org/apache/solr/cloud/autoscaling/sim/SimScenario.java +++ b/solr/core/src/java/org/apache/solr/cloud/autoscaling/sim/SimScenario.java @@ -300,7 +300,7 @@ public class SimScenario implements AutoCloseable { log.info(" -- abortLoop requested, aborting after " + i + " iterations."); return; } - scenario.context.put(LOOP_ITER_PROP, i); + scenario.context.put(LOOP_ITER_PROP, String.valueOf(i)); log.info(" * iter " + (i + 1) + ":"); for (SimOp op : ops) { op.prepareCurrentParams(scenario); diff --git a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimScenario.java b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimScenario.java index 51c12169ea2..2ee5b021eff 100644 --- a/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimScenario.java +++ b/solr/core/src/test/org/apache/solr/cloud/autoscaling/sim/TestSimScenario.java @@ -76,12 +76,15 @@ public class TestSimScenario extends SimSolrCloudTestCase { "loop_end\n" + "loop_start iterations=${justCalc}\n" + " calculate_suggestions\n" + + " save_snapshot path=${snapshotPath}/${_loop_iter_}\n" + "loop_end\n" + "dump redact=true"; @Test public void testSuggestions() throws Exception { + String snapshotPath = createTempDir() + "/snapshot"; try (SimScenario scenario = SimScenario.load(testSuggestionsScenario)) { + scenario.context.put("snapshotPath", snapshotPath); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos, true, "UTF-8"); scenario.console = ps; @@ -100,14 +103,14 @@ public class TestSimScenario extends SimSolrCloudTestCase { List> snapSuggestions = (List>)autoscalingState.get("suggestions"); assertEquals(snapSuggestions.toString(), 1, snapSuggestions.size()); // _loop_iter_ should be present and 0 (first iteration) - assertEquals(0, scenario.context.get(SimScenario.LOOP_ITER_PROP)); + assertEquals("0", scenario.context.get(SimScenario.LOOP_ITER_PROP)); } // try looping more times try (SimScenario scenario = SimScenario.load(testSuggestionsScenario)) { scenario.context.put("iterative", "10"); scenario.context.put("justCalc", "0"); scenario.run(); - assertEquals(9, scenario.context.get(SimScenario.LOOP_ITER_PROP)); + assertEquals("9", scenario.context.get(SimScenario.LOOP_ITER_PROP)); } } diff --git a/solr/solr-ref-guide/src/solrcloud-autoscaling-policy-preferences.adoc b/solr/solr-ref-guide/src/solrcloud-autoscaling-policy-preferences.adoc index cc3373c586d..d7760928c71 100644 --- a/solr/solr-ref-guide/src/solrcloud-autoscaling-policy-preferences.adoc +++ b/solr/solr-ref-guide/src/solrcloud-autoscaling-policy-preferences.adoc @@ -530,7 +530,7 @@ updated to contain the current values for the following properties: * `_collections_` - a list of existing collections, or absent if there are no collections (or no live nodes) * `_suggestions_` - a list of autoscaling suggestions generated using CREATE_SUGGESTIONS command. * `_responses_` - a list of SolrResponse-s resulting from SOLR_REQUEST commands. -* `_loop_iter_` - current loop iteration, or absent outside of loop. +* `_loop_iter_` - current loop iteration (as a string), or absent outside of loop. * `_trigger_event_` - last trigger event captured by WAIT_EVENT Command parameters support variable expansion using string values from the current context (non-string values, including numeric, are ignored)