Apache Solr open-source search software
Tests: Add test for using non-default filesystem with EmbeddedSolrServer (#3146)
Andrey Bozhko67bb1c649fd3
diff --git a/solr/core/src/test-files/solr/configsets/zipfs/conf/schema.xml b/solr/core/src/test-files/solr/configsets/zipfs/conf/schema.xmlnew file mode 100644index 00000000000..61c720ee612--- /dev/null+++ b/solr/core/src/test-files/solr/configsets/zipfs/conf/schema.xml@@ -0,0 +1,32 @@+<?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++ https://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="default-config" version="1.7">+ <uniqueKey>id</uniqueKey>++ <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />+ <fieldType name="string" class="solr.StrField" sortMissingLast="true" />++ <field name="_version_" type="plong" indexed="false" stored="false"/>+ <fieldType name="plong" class="solr.LongPointField"/>++ <fieldType name="booleans" class="solr.BoolField" sortMissingLast="true" multiValued="true"/>+ <dynamicField name="*_bs" type="booleans" indexed="true" stored="true"/>++ <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100" multiValued="true" />+</schema>diff --git a/solr/core/src/test-files/solr/configsets/zipfs/conf/solrconfig.xml b/solr/core/src/test-files/solr/configsets/zipfs/conf/solrconfig.xmlnew file mode 100644index 00000000000..1beded14516--- /dev/null+++ b/solr/core/src/test-files/solr/configsets/zipfs/conf/solrconfig.xml@@ -0,0 +1,54 @@+<?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++ https://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.+-->++<config>+ <luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>++ <dataDir>${solr.data.dir:}</dataDir>++ <directoryFactory class="solr.RAMDirectoryFactory"/>+ <indexConfig>+ <lockType>single</lockType>+ </indexConfig>++ <schemaFactory class="ClassicIndexSchemaFactory"/>++ <codecFactory class="solr.SchemaCodecFactory"/>++ <!-- The default high-performance update handler -->+ <updateHandler class="solr.DirectUpdateHandler2">+ <updateLog enable="false"/>+ </updateHandler>++ <!-- Primary search handler, expected by most clients, examples and UI frameworks -->+ <requestHandler name="/select" class="solr.SearchHandler">+ <lst name="defaults">+ <str name="echoParams">explicit</str>+ <int name="rows">10</int>+ </lst>+ </requestHandler>++ <restManager>+ <!--+ IMPORTANT: Due to the Lucene SecurityManager, tests can only write to their runtime directory or below.+ But it's easier to just keep everything in memory for testing so no remnants are left behind.+ -->+ <str name="storageIO">org.apache.solr.rest.ManagedResourceStorage$InMemoryStorageIO</str>+ </restManager>++</config>diff --git a/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServerConstructors.java b/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServerConstructors.javaindex ec6d688fe17..e6a87783a7f 100644--- a/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServerConstructors.java+++ b/solr/core/src/test/org/apache/solr/client/solrj/embedded/TestEmbeddedSolrServerConstructors.java@@ -17,7 +17,12 @@package org.apache.solr.client.solrj.embedded;import java.io.IOException;+import java.nio.file.FileSystems;+import java.nio.file.Files;import java.nio.file.Path;+import java.util.List;+import java.util.Map;+import org.apache.commons.io.file.PathUtils;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.request.CoreAdminRequest;@@ -58,4 +63,57 @@ public class TestEmbeddedSolrServerConstructors extends SolrTestCaseJ4 {assertEquals(1, server.query("newcore", new SolrQuery("*:*")).getResults().getNumFound());}}++ @Test+ public void testPathConstructorZipFS() throws Exception {+ Path archive = createTempFile("configset", ".zip");+ Files.delete(archive);++ // When :+ // Prepare a zip archive which contains+ // the configset files as shown below:+ //+ // configset.zip+ // └── 1+ // └── 2+ // └── 3+ // └── 4+ // ├── data+ // │ └── core1+ // │ ├── conf+ // │ │ ├── schema.xml+ // │ │ └── solrconfig.xml+ // │ └── core.properties+ // └── solr.xml+ //+ // Note :+ // We don't want Solr to attempt to modify+ // the archive when we point solrHome to+ // the archive content. That's why we:+ // - use RAMDirectoryFactory,+ // - disable the update log.++ var zipFs = FileSystems.newFileSystem(archive, Map.of("create", "true"));+ try (zipFs) {+ var destDir = zipFs.getPath("1", "2", "3", "4");+ var confDir = destDir.resolve("data/core1/conf");+ Files.createDirectories(confDir);++ Files.createFile(confDir.resolveSibling("core.properties"));+ Files.copy(TEST_PATH().resolve("solr.xml"), destDir.resolve("solr.xml"));++ PathUtils.copyDirectory(configset("zipfs"), confDir);+ }++ // Then :+ // EmbeddedSolrServer successfully loads the core+ // using the configset directly from the archive+ var configSetFs = FileSystems.newFileSystem(archive);+ try (configSetFs) {+ var server = new EmbeddedSolrServer(configSetFs.getPath("/1/2/3/4"), null);+ try (server) {+ assertEquals(List.of("core1"), server.getCoreContainer().getAllCoreNames());+ }+ }+ }}