diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 48349f6facf..a4bb3c0f3dc 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -471,6 +471,10 @@ Documentation Upgrading from Solr 3.5 ---------------------- +* SOLR-2983: As a consequence of moving the code which sets a MergePolicy from SolrIndexWriter to SolrIndexConfig, + (custom) MergePolicies should now have an empty constructor; thus an IndexWriter should not be passed as constructor + parameter but instead set using the setIndexWriter() method. + * As doGet() methods in SimplePostTool was changed to static, the client applications of this class need to be recompiled. diff --git a/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java b/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java index 6220bb5cc0d..aa2062ee78e 100644 --- a/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java +++ b/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java @@ -160,14 +160,9 @@ public class SolrIndexConfig { } private MergePolicy buildMergePolicy(IndexSchema schema) { - MergePolicy policy; String mpClassName = mergePolicyInfo == null ? defaultMergePolicyClassName : mergePolicyInfo.className; - try { - policy = (MergePolicy) schema.getResourceLoader().newInstance(mpClassName, null, new Class[]{IndexWriter.class}, new Object[]{this}); - } catch (Exception e) { - policy = (MergePolicy) schema.getResourceLoader().newInstance(mpClassName); - } + MergePolicy policy = (MergePolicy) schema.getResourceLoader().newInstance(mpClassName); if (policy instanceof LogMergePolicy) { LogMergePolicy logMergePolicy = (LogMergePolicy) policy; diff --git a/solr/core/src/test-files/solr/conf/bad-mp-solrconfig.xml b/solr/core/src/test-files/solr/conf/bad-mp-solrconfig.xml new file mode 100644 index 00000000000..af66ff7e4b3 --- /dev/null +++ b/solr/core/src/test-files/solr/conf/bad-mp-solrconfig.xml @@ -0,0 +1,51 @@ + + + + + + + + + ${tests.luceneMatchVersion:LUCENE_CURRENT} + + + + false + 10 + 32 + 2147483647 + 10000 + 1000 + + + + + + false + 8 + 10 + 2147483647 + 10000 + + true + + + + + + diff --git a/solr/core/src/test/org/apache/solr/update/DummyMergePolicy.java b/solr/core/src/test/org/apache/solr/update/DummyMergePolicy.java new file mode 100644 index 00000000000..ef0d07504fe --- /dev/null +++ b/solr/core/src/test/org/apache/solr/update/DummyMergePolicy.java @@ -0,0 +1,35 @@ +package org.apache.solr.update; + +/* + * 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. + */ + +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(); + setIndexWriter(writer); + } +} diff --git a/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java b/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java new file mode 100644 index 00000000000..dd77aedaef9 --- /dev/null +++ b/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java @@ -0,0 +1,53 @@ +package org.apache.solr.update; + +/* + * 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. + */ + +import org.apache.solr.SolrTestCaseJ4; +import org.apache.solr.core.SolrConfig; +import org.apache.solr.schema.IndexSchema; +import org.junit.Test; + +/** + * Testcase for {@link SolrIndexConfig} + */ +public class SolrIndexConfigTest extends SolrTestCaseJ4 { + + @Test + public void testFailingSolrIndexConfigCreation() { + try { + SolrConfig solrConfig = new SolrConfig("bad-mp-solrconfig.xml"); + SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null); + IndexSchema indexSchema = new IndexSchema(solrConfig, "schema.xml", null); + solrIndexConfig.toIndexWriterConfig(indexSchema); + 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 + } + } + + @Test + public void testTieredMPSolrIndexConfigCreation() throws Exception { + SolrConfig solrConfig = new SolrConfig("solrconfig-mergepolicy.xml"); + SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null); + assertNotNull(solrIndexConfig); + assertEquals("org.apache.lucene.index.TieredMergePolicy", solrIndexConfig.defaultMergePolicyClassName); + IndexSchema indexSchema = new IndexSchema(solrConfig, "schema.xml", null); + solrIndexConfig.toIndexWriterConfig(indexSchema); + } + +}