From 501a91763b65d63a0b2a1c49fb1dbf51143d1515 Mon Sep 17 00:00:00 2001 From: Munendra S N Date: Mon, 29 Jul 2019 09:30:25 +0530 Subject: [PATCH] SOLR-13656: fix bad mergePolicyFactory test in SolrIndexConfigTest * use expectThrows to verify the exception and ex message * remove unused DummyMergePolicy --- .../collection1/conf/bad-mpf-solrconfig.xml | 2 +- .../apache/solr/update/DummyMergePolicy.java | 33 ------------------- .../solr/update/SolrIndexConfigTest.java | 21 ++++++------ 3 files changed, 11 insertions(+), 45 deletions(-) delete mode 100644 solr/core/src/test/org/apache/solr/update/DummyMergePolicy.java 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 189d4490fd3..19d786056ad 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 @@ ${tests.luceneMatchVersion:LATEST} - + 8 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 ed1b3ff6b07..00000000000 --- 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 de5944edb45..b314293261f 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