Skip to content

Commit

Permalink
embedded solr server works with zip filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Bozhko committed Jan 29, 2025
1 parent b1c7268 commit 8cf5018
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.lang.invoke.MethodHandles;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map.Entry;
import net.jcip.annotations.NotThreadSafe;
Expand Down Expand Up @@ -148,12 +147,11 @@ public String lookupZKManagedSchemaPath() {
*/
public Path lookupLocalManagedSchemaPath() {
final Path legacyManagedSchemaPath =
Paths.get(
loader.getConfigPath().toString(),
ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME);
loader
.getConfigPath()
.resolve(ManagedIndexSchemaFactory.LEGACY_MANAGED_SCHEMA_RESOURCE_NAME);

Path managedSchemaPath =
Paths.get(loader.getConfigPath().toString(), managedSchemaResourceName);
Path managedSchemaPath = loader.getConfigPath().resolve(managedSchemaResourceName);

// check if we are using the legacy managed-schema file name.
if (Files.exists(legacyManagedSchemaPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,4 +63,63 @@ public void testNodeConfigConstructor() throws Exception {
assertEquals(1, server.query("newcore", new SolrQuery("*:*")).getResults().getNumFound());
}
}

@SuppressWarnings("removal")
@Test
public void testPathConstructorZipFS() throws Exception {
assumeTrue(
"""
Test only works without Security Manager due to SecurityConfHandlerLocal
missing permission to read /1/2/3/4/security.json file""",
System.getSecurityManager() == null);

Path dataDir = createTempDir("data-dir");
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
// │ │ ├── managed-schema.xml
// │ │ └── solrconfig.xml
// │ └── core.properties
// └── solr.xml

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.copy(TEST_PATH().resolve("solr.xml"), destDir.resolve("solr.xml"));
PathUtils.copyDirectory(configset("zipfs"), confDir);

// Need to make sure we circumvent any Solr attempts
// to modify the archive - so to achieve that we:
// - set a custom data dir,
// - disable the update log,
// - configure the rest manager in the solrconfig.xml with InMemoryStorageIO.
Files.writeString(
confDir.resolveSibling("core.properties"),
String.join("\n", "solr.ulog.enable=false", "solr.data.dir=" + dataDir));
}

// Then :
// EmbeddedSolrServer successfully loads 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());
}
}
}
}

0 comments on commit 8cf5018

Please sign in to comment.