You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ge...@apache.org on 2023/05/26 15:00:47 UTC

[solr] branch main updated: SOLR-16678: Add test for user properties on v2 coll-creation requests

This is an automated email from the ASF dual-hosted git repository.

gerlowskija pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 9f39d424694 SOLR-16678: Add test for user properties on v2 coll-creation requests
9f39d424694 is described below

commit 9f39d42469495e00b90ee949b906a70aa8354dcb
Author: Alex <st...@apache.org>
AuthorDate: Fri May 26 08:00:40 2023 -0700

    SOLR-16678: Add test for user properties on v2 coll-creation requests
    
    Functionality has was recently fixed but no test existed to prevent regression.
    This commit safeguards us against future breaks by adding a test.
---
 .../cloud-minimal-userproperties/conf/schema.xml   | 29 +++++++++
 .../conf/solrconfig.xml                            | 55 ++++++++++++++++
 .../TestCollectionsAPIViaSolrCloudCluster.java     | 76 +++++++++++++++++++++-
 3 files changed, 159 insertions(+), 1 deletion(-)

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.xml
new file mode 100644
index 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.xml
new file mode 100644
index 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.java
index 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 {
 
   @Override
   public 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 collection
     assertEquals(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;
+    }
+  }
 }