SOLR-13852: Fix TestCloudNestedDocsSort to ensure child docs are never created in a way that violates uniqueKey rules

This commit is contained in:
Chris Hostetter 2019-10-16 15:48:50 -07:00
parent 611c4f960e
commit ebc720c5b0
1 changed files with 10 additions and 6 deletions

View File

@ -49,7 +49,8 @@ public class TestCloudNestedDocsSort extends SolrCloudTestCase {
@BeforeClass
public static void setupCluster() throws Exception {
for (int i=0; i<10+random().nextInt(20); i++) {
final int numVals = atLeast(10);
for (int i=0; i < numVals; i++) {
vals.add(""+Integer.toString(random().nextInt(1000000), Character.MAX_RADIX));
}
@ -75,12 +76,13 @@ public class TestCloudNestedDocsSort extends SolrCloudTestCase {
AbstractDistribZkTestBase.waitForRecoveriesToFinish("collection1", zkStateReader, true, true, 30);
{
List<SolrInputDocument> docs = new ArrayList<>();
int parentsNum = 10 +random().nextInt(20)
int id = 42;
final List<SolrInputDocument> docs = new ArrayList<>();
final int parentsNum = atLeast(20);
;
for (int i=0; i<parentsNum || (matchingParent==null ||matchingChild==null); i++) {
final String parentTieVal = "" + random().nextInt(5);
final String parentId = ""+random().nextInt();
final String parentId = ""+(id++);
final SolrInputDocument parent = new SolrInputDocument("id", parentId,
"type_s", "parent",
"parentTie_s1", parentTieVal,
@ -89,7 +91,7 @@ public class TestCloudNestedDocsSort extends SolrCloudTestCase {
final List<String> parentFilter = addValsField(parent, "parentFilter_s");
final int kids = usually() ? atLeast(20) : 0;
for(int c = 0; c< kids; c++){
SolrInputDocument child = new SolrInputDocument("id", ""+random().nextInt(),
SolrInputDocument child = new SolrInputDocument("id", ""+(id++),
"type_s", "child",
"parentTie_s1", parentTieVal,
"parent_id_s1", parentId);
@ -111,6 +113,8 @@ public class TestCloudNestedDocsSort extends SolrCloudTestCase {
maxDocs += parent.getChildDocumentCount()+1;
docs.add(parent);
}
// don't add parents in increasing uniqueKey order
Collections.shuffle(docs, random());
client.add(docs);
client.commit();
}