Skip to content

Apache Lucene open-source search software

SOLR-7470: Fix sample data to eliminate file order dependency for successful indexing, also fixed SolrCloudExampleTest to help catch this in the future

Chris M. Hostetter3c1130402a68
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 66fa150afec..59459aa8da7 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -210,6 +210,9 @@ Bug Fixes
* SOLR-7449: solr/server/etc/jetty-https-ssl.xml hard codes the key store file and password rather
than pulling them from the sysprops defined in solr/bin/solr.in.{sh,cmd}
+* SOLR-7470: Fix sample data to eliminate file order dependency for successful indexing, also
+ fixed SolrCloudExampleTest to help catch this in the future. (hossman)
+
Optimizations
----------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java b/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java
index 2a92b6045a1..ecca28c8a77 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SolrCloudExampleTest.java
@@ -19,6 +19,11 @@ package org.apache.solr.cloud;
import java.io.File;
import java.io.FilenameFilter;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Random;
import java.util.Set;
import org.apache.commons.cli.CommandLine;
@@ -96,20 +101,29 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
File exampleDocsDir = new File(ExternalPaths.SOURCE_HOME, "example/exampledocs");
assertTrue(exampleDocsDir.getAbsolutePath()+" not found!", exampleDocsDir.isDirectory());
- File[] xmlFiles = exampleDocsDir.listFiles(new FilenameFilter() {
+ List<File> xmlFiles = Arrays.asList(exampleDocsDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".xml");
}
- });
+ }));
+
+ // force a deterministic random ordering of the files so seeds reproduce regardless of platform/filesystem
+ Collections.sort(xmlFiles, new Comparator<File>() {
+ public int compare(File o1, File o2) {
+ // don't rely on File.compareTo, it's behavior varies by OS
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
+ Collections.shuffle(xmlFiles, new Random(random().nextLong()));
// if you add/remove example XML docs, you'll have to fix these expected values
int expectedXmlFileCount = 14;
int expectedXmlDocCount = 32;
- assertTrue("Expected 14 example XML files in "+exampleDocsDir.getAbsolutePath(),
- xmlFiles.length == expectedXmlFileCount);
-
+ assertEquals("Unexpected # of example XML files in "+exampleDocsDir.getAbsolutePath(),
+ expectedXmlFileCount, xmlFiles.size());
+
for (File xml : xmlFiles) {
ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update");
req.addFile(xml, "application/xml");
@@ -121,7 +135,8 @@ public class SolrCloudExampleTest extends AbstractFullDistribZkTestBase {
QueryResponse qr = cloudClient.query(new SolrQuery("*:*"));
int numFound = (int)qr.getResults().getNumFound();
- assertTrue("Expected "+expectedXmlDocCount+" docs but *:* found "+numFound, numFound == expectedXmlDocCount);
+ assertEquals("*:* found unexpected number of documents", expectedXmlDocCount, numFound);
+
log.info("testLoadDocsIntoGettingStartedCollection succeeded ... shutting down now!");
}
diff --git a/solr/example/exampledocs/mem.xml b/solr/example/exampledocs/mem.xml
index 0b89d6785c2..41d31a4f9de 100644
--- a/solr/example/exampledocs/mem.xml
+++ b/solr/example/exampledocs/mem.xml
@@ -25,7 +25,7 @@
<field name="cat">electronics</field>
<field name="cat">memory</field>
<field name="features">CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader</field>
- <field name="price">185</field>
+ <field name="price">185.00</field>
<field name="popularity">5</field>
<field name="inStock">true</field>
<!-- San Francisco store -->