From 54d8574f9662f89598a06fbb47de9a376ef5d2bc Mon Sep 17 00:00:00 2001 From: Mikhail Khludnev Date: Sun, 25 Dec 2016 10:00:50 +0300 Subject: [PATCH] SOLR-9448: providing a test for workaround of a differently named uniqueKey field --- solr/CHANGES.txt | 2 + .../schema-minimal-with-another-uniqkey.xml | 23 ++++++++ .../TestSubQueryTransformerDistrib.java | 55 +++++++++++-------- 3 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 solr/core/src/test-files/solr/collection1/conf/schema-minimal-with-another-uniqkey.xml diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index b2ec5efb500..a6ea07b6e22 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -332,6 +332,8 @@ Other Changes * SOLR-9758: refactor preferLocalShards implementation (Christine Poerschke) +* SOLR-9448: providing a test to workaround a differently named uniqueKey field (Mikhail Khludnev) + ================== 6.3.0 ================== Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-minimal-with-another-uniqkey.xml b/solr/core/src/test-files/solr/collection1/conf/schema-minimal-with-another-uniqkey.xml new file mode 100644 index 00000000000..2087a1daae0 --- /dev/null +++ b/solr/core/src/test-files/solr/collection1/conf/schema-minimal-with-another-uniqkey.xml @@ -0,0 +1,23 @@ + + + + + notid + + + diff --git a/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerDistrib.java b/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerDistrib.java index c417272bb23..620cac0a942 100644 --- a/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerDistrib.java +++ b/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerDistrib.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; import java.util.Random; -import org.apache.solr.SolrTestCaseJ4.SuppressSSL; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.request.CollectionAdminRequest; @@ -42,15 +41,19 @@ import org.apache.solr.common.util.ContentStreamBase; import org.junit.BeforeClass; import org.junit.Test; -@SuppressSSL public class TestSubQueryTransformerDistrib extends SolrCloudTestCase { + private static final String support = "These guys help customers"; + private static final String engineering = "These guys develop stuff"; final static String people = "people"; final static String depts = "departments"; + private static boolean differentUniqueId; @BeforeClass public static void setupCluster() throws Exception { + differentUniqueId = random().nextBoolean(); + final Path configDir = Paths.get(TEST_HOME(), "collection1", "conf"); String configName = "solrCloudCollectionConfig"; @@ -72,7 +75,9 @@ public class TestSubQueryTransformerDistrib extends SolrCloudTestCase { CollectionAdminRequest.createCollection(depts, configName, shards, replicas) .withProperty("config", "solrconfig-doctransformers.xml") - .withProperty("schema", "schema-docValuesJoin.xml") + .withProperty("schema", + differentUniqueId ? "schema-minimal-with-another-uniqkey.xml": + "schema-docValuesJoin.xml") .process(cluster.getSolrClient()); CloudSolrClient client = cluster.getSolrClient(); @@ -102,28 +107,22 @@ public class TestSubQueryTransformerDistrib extends SolrCloudTestCase { "fl","*,depts:[subquery "+((random1.nextBoolean() ? "" : "separator=,"))+"]", "rows","" + peopleMultiplier, "depts.q","{!terms f=dept_id_s v=$row.dept_ss_dv "+((random1.nextBoolean() ? "" : "separator=,"))+"}", - "depts.fl","text_t", + "depts.fl","text_t"+(differentUniqueId?",id:notid":""), "depts.indent","true", "depts.collection","departments", + differentUniqueId ? "depts.distrib.singlePass":"notnecessary","true", "depts.rows",""+(deptMultiplier*2), - "depts.logParamsList","q,fl,rows,row.dept_ss_dv"})); + "depts.logParamsList","q,fl,rows,row.dept_ss_dv", + random().nextBoolean()?"depts.wt":"whatever",anyWt(), + random().nextBoolean()?"wt":"whatever",anyWt()})); final QueryResponse rsp = new QueryResponse(); rsp.setResponse(cluster.getSolrClient().request(qr, people)); final SolrDocumentList hits = rsp.getResults(); assertEquals(peopleMultiplier, hits.getNumFound()); - Map engText = new HashMap() { - { put("text_t", "These guys develop stuff"); - } - }; - Map suppText = new HashMap() { - { put("text_t", "These guys help customers"); - } - }; - - int engineer = 0; - int support = 0; + int engineerCount = 0; + int supportCount = 0; for (int res : new int [] {0, (peopleMultiplier-1) /2, peopleMultiplier-1}) { SolrDocument doc = hits.get(res); @@ -133,16 +132,23 @@ public class TestSubQueryTransformerDistrib extends SolrCloudTestCase { deptMultiplier * 2, relDepts.getNumFound()); for (int deptN = 0 ; deptN < relDepts.getNumFound(); deptN++ ) { SolrDocument deptDoc = relDepts.get(deptN); - assertTrue(deptDoc + "should be either "+engText +" or "+suppText, - (engText.equals(deptDoc) && ++engineer>0) || - (suppText.equals(deptDoc) && ++support>0)); + String actual = (String) deptDoc.get("text_t"); + assertTrue(deptDoc + "should be either "+engineering +" or "+support, + (engineering.equals(actual) && ++engineerCount>0) || + (support.equals(actual) && ++supportCount>0)); } } - assertEquals(hits.toString(), engineer, support); + assertEquals(hits.toString(), engineerCount, supportCount); } } + private String anyWt() { + String[] wts = new String[]{"javabin","xml","json"}; + return wts[random().nextInt(wts.length)]; + } + + private void createIndex(String people, int peopleMultiplier, String depts, int deptMultiplier) throws SolrServerException, IOException { @@ -175,14 +181,15 @@ public class TestSubQueryTransformerDistrib extends SolrCloudTestCase { addDocs(people, peopleDocs); List deptsDocs = new ArrayList<>(); + String deptIdField = differentUniqueId? "notid":"id"; for (int d=0; d < deptMultiplier; d++) { - deptsDocs.add(add(doc("id",""+id++, "dept_id_s", "Engineering", "text_t","These guys develop stuff", "salary_i_dv", "1000", + deptsDocs.add(add(doc(deptIdField,""+id++, "dept_id_s", "Engineering", "text_t",engineering, "salary_i_dv", "1000", "dept_id_i", "0"))); - deptsDocs.add(add(doc("id",""+id++, "dept_id_s", "Marketing", "text_t","These guys make you look good","salary_i_dv", "1500", + deptsDocs.add(add(doc(deptIdField,""+id++, "dept_id_s", "Marketing", "text_t","These guys make you look good","salary_i_dv", "1500", "dept_id_i", "1"))); - deptsDocs.add(add(doc("id",""+id++, "dept_id_s", "Sales", "text_t","These guys sell stuff","salary_i_dv", "1600", + deptsDocs.add(add(doc(deptIdField,""+id++, "dept_id_s", "Sales", "text_t","These guys sell stuff","salary_i_dv", "1600", "dept_id_i", "2"))); - deptsDocs.add(add(doc("id",""+id++, "dept_id_s", "Support", "text_t","These guys help customers","salary_i_dv", "800", + deptsDocs.add(add(doc(deptIdField,""+id++, "dept_id_s", "Support", "text_t",support,"salary_i_dv", "800", "dept_id_i", "3"))); }