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
This commit is contained in:
Chris Hostetter 2020-02-12 11:10:26 -07:00
parent 0767a9d4d7
commit 49e20dbee4
1 changed files with 23 additions and 9 deletions

View File

@ -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<String,Object> propMap = new HashMap<String,Object>();
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<Replica> actualTransformed = new ArrayList<>(inputs);
transformer.transform(actualTransformed);
assertEquals(expectedTransformed.size(), actualTransformed.size());
for (int ii=0; ii<expectedTransformed.size(); ++ii) {
assertEquals("mismatch for ii="+ii, expectedTransformed.get(ii), actualTransformed.get(ii));
}
assertEquals(expectedTransformed, actualTransformed);
}
private final List<String> createRandomUrls() throws Exception {