You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ds...@apache.org on 2023/09/11 05:06:28 UTC

[solr] branch main updated: SOLR-16654: Improve test (#1886)

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

dsmiley 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 b614c1fa02a SOLR-16654: Improve test (#1886)
b614c1fa02a is described below

commit b614c1fa02ac9f34144a0d0239edfc66a7700c01
Author: David Smiley <ds...@apache.org>
AuthorDate: Mon Sep 11 01:06:22 2023 -0400

    SOLR-16654: Improve test (#1886)
    
    * remove 2 test config files
    * revert "solr.tests.loadSolrXml" option recently added
    * use EmbeddedSolrServerTestRule for initialization
---
 .../conf/solrconfig-nodelevelcaches.xml            | 34 ---------
 .../src/test-files/solr/solr-nodelevelcaches.xml   | 30 --------
 .../src/test/org/apache/solr/core/TestSolrXml.java |  9 ++-
 .../test/org/apache/solr/search/TestThinCache.java | 81 +++++++++++++---------
 .../src/java/org/apache/solr/util/TestHarness.java |  9 +--
 5 files changed, 59 insertions(+), 104 deletions(-)

diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-nodelevelcaches.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-nodelevelcaches.xml
deleted file mode 100644
index d6d33fe7bc6..00000000000
--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-nodelevelcaches.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?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.
--->
-
-<config>
-  <luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>
-  <dataDir>${solr.data.dir:}</dataDir>
-  <xi:include href="solrconfig.snippet.randomindexconfig.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
-  <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/>
-  <schemaFactory class="ClassicIndexSchemaFactory"/>
-  <requestHandler name="/select" class="solr.SearchHandler" />
-  <query>
-    <filterCache
-      class="solr.ThinCache"
-      parentCacheName="myNodeLevelCacheThin"
-      size="5"
-      initialSize="5"/>
-  </query>
-</config>
diff --git a/solr/core/src/test-files/solr/solr-nodelevelcaches.xml b/solr/core/src/test-files/solr/solr-nodelevelcaches.xml
deleted file mode 100644
index cc99abb7a5a..00000000000
--- a/solr/core/src/test-files/solr/solr-nodelevelcaches.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?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.
--->
-<solr>
-  <caches>
-    <cache name="myNodeLevelCache"
-      size="10"
-      initialSize="10"
-      />
-    <cache name="myNodeLevelCacheThin"
-      class="solr.ThinCache$NodeLevelCache"
-      size="10"
-      initialSize="10"
-      />
-  </caches>
-</solr>
diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrXml.java b/solr/core/src/test/org/apache/solr/core/TestSolrXml.java
index 1e547f3ed88..51ac2bb0e65 100644
--- a/solr/core/src/test/org/apache/solr/core/TestSolrXml.java
+++ b/solr/core/src/test/org/apache/solr/core/TestSolrXml.java
@@ -34,6 +34,7 @@ import org.apache.solr.common.SolrException;
 import org.apache.solr.search.CacheConfig;
 import org.apache.solr.search.CaffeineCache;
 import org.apache.solr.search.SolrCache;
+import org.apache.solr.search.TestThinCache;
 import org.apache.solr.search.ThinCache;
 import org.apache.solr.update.UpdateShardHandlerConfig;
 import org.hamcrest.MatcherAssert;
@@ -155,11 +156,9 @@ public class TestSolrXml extends SolrTestCaseJ4 {
     assertFalse("schema cache", cfg.hasSchemaCache());
   }
 
-  public void testNodeLevelCache() throws IOException {
-    Path testSrcRoot = TEST_PATH();
-    Files.copy(testSrcRoot.resolve("solr-nodelevelcaches.xml"), solrHome.resolve("solr.xml"));
-
-    NodeConfig cfg = SolrXmlConfig.fromSolrHome(solrHome, new Properties());
+  public void testNodeLevelCache() {
+    NodeConfig cfg =
+        SolrXmlConfig.fromString(createTempDir(), TestThinCache.SOLR_NODE_LEVEL_CACHE_XML);
     Map<String, CacheConfig> cachesConfig = cfg.getCachesConfig();
     SolrCache<?, ?> nodeLevelCache = cachesConfig.get("myNodeLevelCache").newInstance();
     assertTrue(nodeLevelCache instanceof CaffeineCache);
diff --git a/solr/core/src/test/org/apache/solr/search/TestThinCache.java b/solr/core/src/test/org/apache/solr/search/TestThinCache.java
index 95f795054ad..c485b9fe46a 100644
--- a/solr/core/src/test/org/apache/solr/search/TestThinCache.java
+++ b/solr/core/src/test/org/apache/solr/search/TestThinCache.java
@@ -26,13 +26,63 @@ import org.apache.lucene.tests.util.TestUtil;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.metrics.SolrMetricManager;
 import org.apache.solr.metrics.SolrMetricsContext;
+import org.apache.solr.util.EmbeddedSolrServerTestRule;
+import org.apache.solr.util.TestHarness;
 import org.apache.solr.util.stats.MetricUtils;
 import org.junit.BeforeClass;
+import org.junit.ClassRule;
 import org.junit.Test;
 
 /** Test for {@link ThinCache}. */
 public class TestThinCache extends SolrTestCaseJ4 {
 
+  @ClassRule public static EmbeddedSolrServerTestRule solrRule = new EmbeddedSolrServerTestRule();
+  public static final String SOLR_NODE_LEVEL_CACHE_XML =
+      "<solr>\n"
+          + "  <caches>\n"
+          + "    <cache name='myNodeLevelCache'\n"
+          + "      size='10'\n"
+          + "      initialSize='10'\n"
+          + "      />\n"
+          + "    <cache name='myNodeLevelCacheThin'\n"
+          + "      class='solr.ThinCache$NodeLevelCache'\n"
+          + "      size='10'\n"
+          + "      initialSize='10'\n"
+          + "      />\n"
+          + "  </caches>\n"
+          + "</solr>";
+
+  @BeforeClass
+  public static void setupSolrHome() throws Exception {
+    Path home = createTempDir("home");
+    Files.writeString(home.resolve("solr.xml"), SOLR_NODE_LEVEL_CACHE_XML);
+
+    solrRule.startSolr(home);
+
+    Path configSet = createTempDir("configSet");
+    copyMinConf(configSet.toFile());
+    // insert a special filterCache configuration
+    Path solrConfig = configSet.resolve("conf/solrconfig.xml");
+    Files.writeString(
+        solrConfig,
+        Files.readString(solrConfig)
+            .replace(
+                "</config>",
+                "<query>\n"
+                    + "<filterCache\n"
+                    + "      class=\"solr.ThinCache\"\n"
+                    + "      parentCacheName=\"myNodeLevelCacheThin\"\n"
+                    + "      size=\"5\"\n"
+                    + "      initialSize=\"5\"/>\n"
+                    + "</query></config>"));
+
+    solrRule.newCollection().withConfigSet(configSet.toString()).create();
+
+    // legacy; get rid of this someday!
+    h = new TestHarness(solrRule.getCoreContainer());
+    lrf = h.getRequestFactory("/select", 0, 20);
+  }
+
   SolrMetricManager metricManager = new SolrMetricManager();
   String registry = TestUtil.randomSimpleString(random(), 2, 10);
   String scope = TestUtil.randomSimpleString(random(), 2, 10);
@@ -126,35 +176,4 @@ public class TestThinCache extends SolrTestCaseJ4 {
     // for the other node-level cache, simply check that metrics are accessible
     assertEquals(0, nodeMetricsSnapshot.get("CACHE.nodeLevelCache/myNodeLevelCache.size"));
   }
-
-  @BeforeClass
-  public static void setupSolrHome() throws Exception {
-    // make a solr home underneath the test's TEMP_DIR, else we don't have write access to copy in
-    // `solr.xml`
-    Path tmpFile = createTempDir();
-
-    // make data and conf dirs
-    Files.createDirectories(tmpFile.resolve("data"));
-    Path confDir = tmpFile.resolve("collection1").resolve("conf");
-    Files.createDirectories(confDir);
-
-    // copy over configuration files
-    copyXmlToHome(
-        tmpFile.toFile(),
-        TEST_PATH().resolve("solr-nodelevelcaches.xml").toAbsolutePath().toString());
-    Files.copy(
-        getFile("solr/collection1/conf/solrconfig-nodelevelcaches.xml").toPath(),
-        confDir.resolve("solrconfig.xml"));
-    Files.copy(
-        getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml").toPath(),
-        confDir.resolve("solrconfig.snippet.randomindexconfig.xml"));
-    Files.copy(
-        getFile("solr/collection1/conf/schema-minimal.xml").toPath(),
-        confDir.resolve("schema.xml"));
-
-    // we want the actual `solr.xml` file to be read, instead of the normal operation, which creates
-    // a synthetic "test NodeConfig"
-    System.setProperty("solr.tests.loadSolrXml", "true");
-    initCore("solrconfig.xml", "schema.xml", tmpFile.toAbsolutePath().toString());
-  }
 }
diff --git a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
index 5d049e01ff4..2f8dc0121a7 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
@@ -25,7 +25,6 @@ import java.nio.file.Paths;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.client.solrj.impl.SolrZkClientTimeout;
 import org.apache.solr.common.SolrException;
@@ -94,6 +93,11 @@ public class TestHarness extends BaseTestHarness {
     return createConfig(solrHome, SolrTestCaseJ4.DEFAULT_TEST_CORENAME, confFile);
   }
 
+  public TestHarness(CoreContainer coreContainer) {
+    this.container = coreContainer;
+    this.coreName = SolrTestCaseJ4.DEFAULT_TEST_CORENAME;
+  }
+
   /**
    * @param coreName to initialize
    * @param dataDirectory path for index data, will not be cleaned up
@@ -187,9 +191,6 @@ public class TestHarness extends BaseTestHarness {
   }
 
   public static NodeConfig buildTestNodeConfig(Path solrHome) {
-    if ("true".equals(System.getProperty("solr.tests.loadSolrXml"))) {
-      return SolrXmlConfig.fromSolrHome(solrHome, new Properties());
-    }
     CloudConfig cloudConfig =
         (null == System.getProperty("zkHost"))
             ? null