You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mu...@apache.org on 2019/07/29 04:27:18 UTC

[lucene-solr] 02/03: SOLR-13656: fix bad mergePolicyFactory test in SolrIndexConfigTest

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

munendrasn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 501a91763b65d63a0b2a1c49fb1dbf51143d1515
Author: Munendra S N <mu...@apache.org>
AuthorDate: Mon Jul 29 09:30:25 2019 +0530

    SOLR-13656: fix bad mergePolicyFactory test in SolrIndexConfigTest
    
    * use expectThrows to verify the exception and ex message
    * remove unused DummyMergePolicy
---
 .../solr/collection1/conf/bad-mpf-solrconfig.xml   |  2 +-
 .../org/apache/solr/update/DummyMergePolicy.java   | 33 ----------------------
 .../apache/solr/update/SolrIndexConfigTest.java    | 21 +++++++-------
 3 files changed, 11 insertions(+), 45 deletions(-)

diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-mpf-solrconfig.xml b/solr/core/src/test-files/solr/collection1/conf/bad-mpf-solrconfig.xml
index 189d449..19d7860 100644
--- a/solr/core/src/test-files/solr/collection1/conf/bad-mpf-solrconfig.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/bad-mpf-solrconfig.xml
@@ -24,7 +24,7 @@
   <luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>
 
   <indexConfig>
-    <mergePolicyFactory class="org.apache.solr.update.DummyMergePolicyFactory">
+    <mergePolicyFactory class="org.apache.solr.index.DummyMergePolicyFactory">
       <int name="mergeFactor">8</int>
     </mergePolicyFactory>
   </indexConfig>
diff --git a/solr/core/src/test/org/apache/solr/update/DummyMergePolicy.java b/solr/core/src/test/org/apache/solr/update/DummyMergePolicy.java
deleted file mode 100644
index ed1b3ff..0000000
--- a/solr/core/src/test/org/apache/solr/update/DummyMergePolicy.java
+++ /dev/null
@@ -1,33 +0,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.
- */
-package org.apache.solr.update;
-
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.LogByteSizeMergePolicy;
-
-/**
- * Dummy implementation of {@link org.apache.lucene.index.MergePolicy} which doesn't have an empty constructor and
- * is expected to fail if used within Solr
- */
-class DummyMergePolicy extends LogByteSizeMergePolicy {
-
-  private DummyMergePolicy() {}
-
-  public DummyMergePolicy(IndexWriter writer) {
-    super();
-  }
-}
diff --git a/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java b/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java
index de5944e..b314293 100644
--- a/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java
+++ b/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java
@@ -29,6 +29,7 @@ import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.MapSerializable;
+import org.apache.solr.common.SolrException;
 import org.apache.solr.core.DirectoryFactory;
 import org.apache.solr.core.SolrConfig;
 import org.apache.solr.core.TestMergePolicyConfig;
@@ -60,17 +61,15 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
   private final Path instanceDir = TEST_PATH().resolve("collection1");
 
   @Test
-  public void testFailingSolrIndexConfigCreation() {
-    try {
-      SolrConfig solrConfig = new SolrConfig("bad-mpf-solrconfig.xml");
-      SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
-      IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig);
-      h.getCore().setLatestSchema(indexSchema);
-      solrIndexConfig.toIndexWriterConfig(h.getCore());
-      fail("a mergePolicy should have an empty constructor in order to be instantiated in Solr thus this should fail ");
-    } catch (Exception e) {
-      // it failed as expected
-    }
+  public void testFailingSolrIndexConfigCreation() throws Exception {
+    SolrConfig solrConfig = new SolrConfig(instanceDir,"bad-mpf-solrconfig.xml", null);
+    SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
+    IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig);
+    h.getCore().setLatestSchema(indexSchema);
+
+    // this should fail as mergePolicy doesn't have any public constructor
+    SolrException ex = expectThrows(SolrException.class, () -> solrIndexConfig.toIndexWriterConfig(h.getCore()));
+    assertTrue(ex.getMessage().contains("Error instantiating class: 'org.apache.solr.index.DummyMergePolicyFactory'"));
   }
 
   @Test