From 3dd484ba29db04e4b5d4181e4a042dcc448b34be Mon Sep 17 00:00:00 2001 From: Chris Hostetter Date: Wed, 12 Feb 2020 11:10:26 -0700 Subject: [PATCH] SOLR-14245: Fix ReplicaListTransformerTest Previous changes to this issue 'fixed' the way the test was creating mock Replica instances, to ensure all properties were specified -- but these changes tickled a bug in the existing test scaffolding that caused it's "expecations" to be based on a regex check against only the base "url" even though the test logic itself looked at the entire "core url" The result is that there were reproducible failures if/when the randomly generated regex matched ".*1.*" because the existing test logic did not expect that to match the url or a Replica with a core name of "core1" because it only considered the base url (cherry picked from commit 49e20dbee4b7e74448928a48bfbb50da1018400f) --- .../routing/ReplicaListTransformerTest.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/routing/ReplicaListTransformerTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/routing/ReplicaListTransformerTest.java index 2b784e540be..5e90da29514 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/routing/ReplicaListTransformerTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/routing/ReplicaListTransformerTest.java @@ -16,6 +16,8 @@ */ package org.apache.solr.client.solrj.routing; +import java.lang.invoke.MethodHandles; + import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -32,7 +34,11 @@ import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.SolrQueryRequest; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class ReplicaListTransformerTest extends SolrTestCase { + private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); // A transformer that keeps only matching choices private static class ToyMatchingReplicaListTransformer implements ReplicaListTransformer { @@ -46,6 +52,7 @@ public class ReplicaListTransformerTest extends SolrTestCase { public void transform(List choices) { + log.info("regex transform input: {}", choices); Iterator it = choices.iterator(); while (it.hasNext()) { Object choice = it.next(); @@ -58,7 +65,9 @@ public class ReplicaListTransformerTest extends SolrTestCase { } else { url = null; } + log.info("considering: {} w/url={}", choice, url); if (url == null || !url.matches(regex)) { + log.info("removing {}", choice); it.remove(); } } @@ -76,6 +85,7 @@ public class ReplicaListTransformerTest extends SolrTestCase { public void transform(List choices) { // no-op + log.info("No-Op transform ignoring input: {}", choices); } } @@ -87,11 +97,11 @@ public class ReplicaListTransformerTest extends SolrTestCase { final ReplicaListTransformer transformer; if (random().nextBoolean()) { - + log.info("Using ToyMatching Transfomer"); transformer = new ToyMatchingReplicaListTransformer(regex); } else { - + log.info("Using conditional Transfomer"); transformer = new HttpShardHandlerFactory() { @Override @@ -126,25 +136,29 @@ public class ReplicaListTransformerTest extends SolrTestCase { final String url = urls.get(ii); final Map propMap = new HashMap(); propMap.put("base_url", url); - propMap.put("core", "core1"); - propMap.put("node_name", "node1"); + propMap.put("core", "test_core"); + propMap.put("node_name", "test_node"); propMap.put("type", "NRT"); // a skeleton replica, good enough for this test's purposes final Replica replica = new Replica(name, propMap,"c1","s1"); inputs.add(replica); - if (url.matches(regex)) { + final String coreUrl = replica.getCoreUrl(); + if (coreUrl.matches(regex)) { + log.info("adding replica=[{}] to expected due to core url ({}) regex match on {} ", + replica, coreUrl, regex); expectedTransformed.add(replica); + } else { + log.info("NOT expecting replica=[{}] due to core url ({}) regex mismatch ({})", + replica, coreUrl, regex); } + } final List actualTransformed = new ArrayList<>(inputs); transformer.transform(actualTransformed); - assertEquals(expectedTransformed.size(), actualTransformed.size()); - for (int ii=0; ii