Apache Solr open-source search software
SOLR-16678: Add test for user properties on v2 coll-creation requests
Alex9f39d4246949
diff --git a/solr/core/src/test-files/solr/configsets/cloud-minimal-userproperties/conf/schema.xml b/solr/core/src/test-files/solr/configsets/cloud-minimal-userproperties/conf/schema.xmlnew file mode 100644index 00000000000..4124feab0c3--- /dev/null+++ b/solr/core/src/test-files/solr/configsets/cloud-minimal-userproperties/conf/schema.xml@@ -0,0 +1,29 @@+<?xml version="1.0" encoding="UTF-8" ?>+<!--+ Licensed to the Apache Software Foundation (ASF) under one or more+ contributor license agreements. See the NOTICE file distributed with+ this work for additional information regarding copyright ownership.+ The ASF licenses this file to You under the Apache License, Version 2.0+ (the "License"); you may not use this file except in compliance with+ the License. You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.+-->+<schema name="minimal" version="1.1">+ <fieldType name="string" class="solr.StrField"/>+ <fieldType name="int" class="${solr.tests.IntegerFieldType}" docValues="${solr.tests.numeric.dv}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="long" class="${solr.tests.LongFieldType}" docValues="${solr.tests.numeric.dv}" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>+ <dynamicField name="*" type="string" indexed="true" stored="true"/>+ <!-- for versioning -->+ <field name="_version_" type="long" indexed="true" stored="true"/>+ <field name="_root_" type="string" indexed="true" stored="true" multiValued="false" required="false"/>+ <field name="id" type="string" indexed="true" stored="true"/>+ <dynamicField name="*_s" type="string" indexed="true" stored="true" />+ <uniqueKey>id</uniqueKey>+</schema>diff --git a/solr/core/src/test-files/solr/configsets/cloud-minimal-userproperties/conf/solrconfig.xml b/solr/core/src/test-files/solr/configsets/cloud-minimal-userproperties/conf/solrconfig.xmlnew file mode 100644index 00000000000..4e01dc85a64--- /dev/null+++ b/solr/core/src/test-files/solr/configsets/cloud-minimal-userproperties/conf/solrconfig.xml@@ -0,0 +1,55 @@+<?xml version="1.0" ?>++<!--+ Licensed to the Apache Software Foundation (ASF) under one or more+ contributor license agreements. See the NOTICE file distributed with+ this work for additional information regarding copyright ownership.+ The ASF licenses this file to You under the Apache License, Version 2.0+ (the "License"); you may not use this file except in compliance with+ the License. You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.+-->++<!-- Minimal solrconfig.xml with /select, /admin and /update only -->+<config>++ <dataDir>${solr.data.dir:}</dataDir>++ <directoryFactory name="DirectoryFactory"+ class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}"/>+ <schemaFactory class="ClassicIndexSchemaFactory"/>++ <luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>++ <updateHandler class="solr.DirectUpdateHandler2">+ <commitWithin>+ <softCommit>${solr.commitwithin.softcommit:true}</softCommit>+ </commitWithin>++ </updateHandler>+ <requestHandler name="/select" class="solr.SearchHandler">+ <lst name="defaults">+ <str name="echoParams">explicit</str>+ <str name="indent">true</str>+ <str name="df">text</str>+ <str name="dummy1">${solr.core.name}</str>+ <str name="dummy2">${my.custom.prop}</str>+ </lst>++ </requestHandler>++ <initParams path="/select">+ <lst name="defaults">+ <str name="df">text</str>+ </lst>+ </initParams>++</config>+diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionsAPIViaSolrCloudCluster.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionsAPIViaSolrCloudCluster.javaindex a9773b2037f..4eeca04c43a 100644--- a/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionsAPIViaSolrCloudCluster.java+++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/TestCollectionsAPIViaSolrCloudCluster.java@@ -23,12 +23,19 @@ import java.util.Collections;import java.util.HashMap;import java.util.HashSet;import java.util.List;+import java.util.Locale;import java.util.Map;import java.util.Set;+import org.apache.http.HttpResponse;+import org.apache.http.client.methods.HttpGet;+import org.apache.http.client.methods.HttpPost;+import org.apache.http.entity.StringEntity;import org.apache.solr.client.solrj.SolrQuery;+import org.apache.solr.client.solrj.impl.CloudLegacySolrClient;import org.apache.solr.client.solrj.impl.CloudSolrClient;import org.apache.solr.client.solrj.request.CollectionAdminRequest;import org.apache.solr.client.solrj.request.UpdateRequest;+import org.apache.solr.client.solrj.response.CollectionAdminResponse;import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.cloud.AbstractDistribZkTestBase;import org.apache.solr.cloud.SolrCloudTestCase;@@ -54,7 +61,10 @@ public class TestCollectionsAPIViaSolrCloudCluster extends SolrCloudTestCase {@Overridepublic void setUp() throws Exception {- configureCluster(nodeCount).addConfig(configName, configset("cloud-minimal")).configure();+ configureCluster(nodeCount)+ .addConfig(configName, configset("cloud-minimal"))+ .addConfig("cloud-minimal-userproperties", configset("cloud-minimal-userproperties"))+ .configure();super.setUp();}@@ -300,4 +310,68 @@ public class TestCollectionsAPIViaSolrCloudCluster extends SolrCloudTestCase {// re-query collectionassertEquals(numDocs, client.query(collectionName, query).getResults().getNumFound());}++ @Test+ public void testUserDefinedProperties() throws Exception {+ String confName = "cloud-minimal-userproperties";+ String collectionName = "testUserDefinedPropertiesCollection";++ switch (random().nextInt(3)) {+ case 0:+ CollectionAdminRequest.Create createOp =+ CollectionAdminRequest.createCollection(collectionName, confName, 1, 2);+ createOp.withProperty("my.custom.prop", "customProp");+ CollectionAdminResponse rsp = createOp.process(cluster.getSolrClient());+ assertNull(rsp.getErrorMessages());+ assertSame(0, rsp.getStatus());+ break;++ case 1:+ // Sometimes use v1 API+ String url =+ String.format(+ Locale.ROOT,+ "%s/admin/collections?action=CREATE&name=%s&collection.configName=%s&numShards=%s&nrtReplicas=%s&tlogReplicas=%s&pullReplicas=%s&&property.my.custom.prop=%s",+ cluster.getRandomJetty(random()).getBaseUrl(),+ collectionName,+ confName,+ 2,+ 2,+ 2,+ 0,+ "customProp");++ HttpGet createCollectionGet = new HttpGet(url);+ HttpResponse httpResponseV1 =+ ((CloudLegacySolrClient) cluster.getSolrClient())+ .getHttpClient()+ .execute(createCollectionGet);+ assertEquals(200, httpResponseV1.getStatusLine().getStatusCode());+ break;++ case 2:+ // Sometimes use V2 API+ url = cluster.getRandomJetty(random()).getBaseUrl().toString() + "/____v2/collections";+ String requestBody =+ String.format(+ Locale.ROOT,+ "{\"name\":\"%s\", \"config\":\"%s\", \"numShards\":%s, \"nrtReplicas\":%s, \"tlogReplicas\":%s, \"pullReplicas\":%s,"+ + " \"properties\": { \"my.custom.prop\": \"test\" } }",+ collectionName,+ confName,+ 2,+ 2,+ 2,+ 0);+ HttpPost createCollectionPost = new HttpPost(url);+ createCollectionPost.setHeader("Content-type", "application/json");+ createCollectionPost.setEntity(new StringEntity(requestBody));+ HttpResponse httpResponseV2 =+ ((CloudLegacySolrClient) cluster.getSolrClient())+ .getHttpClient()+ .execute(createCollectionPost);+ assertEquals(200, httpResponseV2.getStatusLine().getStatusCode());+ break;+ }+ }}