epugh commented on code in PR #2247:
URL: https://github.com/apache/solr/pull/2247#discussion_r1480147205


##########
solr/core/src/java/org/apache/solr/search/CacheConfig.java:
##########
@@ -81,7 +80,7 @@ public void setRegenerator(CacheRegenerator regenerator) {
 
   public static Map<String, CacheConfig> getMultipleConfigs(
       SolrResourceLoader loader, SolrConfig solrConfig, String configPath, 
List<ConfigNode> nodes) {
-    if (nodes == null || nodes.size() == 0) return new LinkedHashMap<>();
+    if (nodes == null || nodes.isEmpty()) return new LinkedHashMap<>();

Review Comment:
   i prefer to nest these in `{ }` instead of single line return..   



##########
solr/core/src/test/org/apache/solr/core/CacheConfigTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.
+ */
+package org.apache.solr.core;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.ConfigNode;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.search.CacheConfig;
+import org.apache.solr.util.DOMConfigNode;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.mockito.Mockito;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class CacheConfigTest extends SolrTestCaseJ4 {
+  private static final String XPATH_DOCUMENT_CACHE = "query/documentCache";
+  private static final String XPATH_QUERY_RESULT_CACHE = 
"query/queryResultCache";
+  private SolrResourceLoader mockSolrResourceLoader;
+  private ConfigOverlay mockConfigOverlay;
+  private ConfigNode overlayConfigNode;
+  private ConfigNode domConfigNode;
+  private ConfigNode domConfigNodeDisable;
+  private SolrConfig mockSolrConfig;
+  private static final DocumentBuilder docBuilder;
+
+  static {
+    try {
+      docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+    } catch (ParserConfigurationException e) {
+      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
+    }
+  }
+
+  @BeforeClass
+  public static void ensureWorkingMockito() {
+    SolrTestCaseJ4.assumeWorkingMockito();
+  }
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    resetMocks();
+    final String initialSize = "99";
+    final String size = "999";
+
+    final Document doc = docBuilder.newDocument();
+    final Element documentCacheNode = doc.createElement("documentCache");
+    documentCacheNode.setAttribute("initialSize", initialSize);
+    documentCacheNode.setAttribute("size", size);
+    documentCacheNode.setAttribute("enabled", "true");
+    domConfigNode = new DOMConfigNode(documentCacheNode);
+    Mockito.when(mockSolrConfig.getOverlay()).thenReturn(mockConfigOverlay);
+    
Mockito.when(mockConfigOverlay.getEditableSubProperties(XPATH_DOCUMENT_CACHE)).thenReturn(null);
+
+    final String sizeForQueryResCache = "199";
+    final Document queryResultCacheDoc = docBuilder.newDocument();
+    final Element queryResultNode = 
queryResultCacheDoc.createElement("queryResultCache");
+    queryResultNode.setAttribute("initialSize", "99");
+    queryResultNode.setAttribute("size", sizeForQueryResCache);
+    queryResultNode.setAttribute("enabled", "false");
+    domConfigNodeDisable = new DOMConfigNode(queryResultNode);
+  }
+
+  public void test_SolrConfigProps_ForCache() {

Review Comment:
   `testSolrConfigPropsForCache`.....   That is the more common pattern for 
tests........



##########
solr/core/src/java/org/apache/solr/search/CacheConfig.java:
##########
@@ -94,12 +93,7 @@ public static Map<String, CacheConfig> getMultipleConfigs(
   }
 
   public static CacheConfig getConfig(SolrConfig solrConfig, ConfigNode node, 
String xpath) {
-    if (!node.exists() || !"true".equals(node.attributes().get("enabled", 
"true"))) {
-      Map<String, Object> m = 
solrConfig.getOverlay().getEditableSubProperties(xpath);
-      if (m == null) return null;
-      List<String> parts = StrUtils.splitSmart(xpath, '/');
-      return getConfig(solrConfig, parts.get(parts.size() - 1), 
Collections.emptyMap(), xpath);
-    }
+    if (!node.boolAttr("enabled", true) || !node.exists()) return null;

Review Comment:
   liewise here nest the return...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to